]> The Tcpdump Group git mirrors - tcpdump/commitdiff
instrument functions: Minimize stat() calls
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 17 Feb 2023 14:28:22 +0000 (15:28 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 17 Feb 2023 14:29:35 +0000 (15:29 +0100)
This change decreases the execution time when the file indicating that
instrumentation is "off" exists.

[skip ci]

instrument-functions.c

index a8e07d9dffbbecc0348d78b1029625526d00221d..fb2314dd3f02c25561e9bca7b342b76192d10f37 100644 (file)
@@ -86,12 +86,19 @@ static void print_debug(void *this_fn, void *call_site, action_type action)
        static long symcount;
        static asection *text;
        static bfd_vma vma;
+       static int instrument_off;
        static int print_only_global;
        symbol_info syminfo;
        struct stat statbuf;
        int i;
 
-       if (!stat(ND_FILE_FLAG_OFF, &statbuf))
+       if (!instrument_off) {
+               /* one-time test */
+               if (!stat(ND_FILE_FLAG_OFF, &statbuf)) {
+                       instrument_off = 1;
+                       return;
+               }
+       } else
                return;
 
        /* If no errors, this block should be executed one time */