]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
- added CCACHE_NOSTATS env variable
authorAndrew Tridgell <tridge@samba.org>
Mon, 1 Apr 2002 02:59:06 +0000 (04:59 +0200)
committerAndrew Tridgell <tridge@samba.org>
Mon, 1 Apr 2002 02:59:06 +0000 (04:59 +0200)
- added some more stats

ccache.1
ccache.c
ccache.h
ccache.yo
stats.c
web/ccache-man.html

index 4a404870ccc4806f1b77448a2125427a6072b28d..b9675b66383374cada74653ebac895f20b2711ec 100644 (file)
--- a/ccache.1
+++ b/ccache.1
@@ -134,6 +134,11 @@ If you set the environment variable
 CCACHE_DISABLE then ccache will just call the real compiler,
 bypassing the cache completely\&.
 .IP 
+.IP "\fBCCACHE_NOSTATS\fP" 
+If you set the environment variable
+CCACHE_NOSTATS then ccache will not update the statistics files on
+each compile\&.
+.IP 
 .IP "\fBCCACHE_NOUNIFY\fP" 
 If you set the environment variable
 CCACHE_NOUNIFY then ccache will not use the C/C++ unifier when hashing
index cdc5e8d264ebb72088e3eb6e46d5960fe55f1b7d..13cd54f3d9029a3515c5b2b111dc9eb7b923e61b 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -475,12 +475,13 @@ static void process_args(int argc, char **argv)
 
        if (!input_file) {
                cc_log("No input file found\n");
-               stats_update(STATS_ARGS);
+               stats_update(STATS_NOINPUT);
                failed();
        }
 
        if (check_extension(input_file) != 0) {
                cc_log("Not a C/C++ file - %s\n", input_file);
+               stats_update(STATS_NOTC);
                failed();
        }
 
@@ -513,7 +514,7 @@ static void process_args(int argc, char **argv)
        /* cope with -o /dev/null */
        if (stat(output_file, &st) == 0 && !S_ISREG(st.st_mode)) {
                cc_log("Not a regular file %s\n", output_file);
-               stats_update(STATS_ARGS);
+               stats_update(STATS_DEVICE);
                failed();
        }
 }
index 4f08574182d430a4bb685809e310e03effcd08bd..0a440baab80b4dae950650fca3e916849a609cc4 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -40,11 +40,13 @@ enum stats {
        STATS_CACHED,
        STATS_ARGS,
        STATS_LINK,
-
        STATS_NUMFILES,
        STATS_TOTALSIZE,
        STATS_MAXFILES,
        STATS_MAXSIZE,
+       STATS_NOTC,
+       STATS_DEVICE,
+       STATS_NOINPUT,
 
        STATS_END
 };
index 38a80db6ce51b589473fa6024e9cb105cc999679..972eb1db297d041f3b79f56fdd9b49393134ec7d 100644 (file)
--- a/ccache.yo
+++ b/ccache.yo
@@ -114,6 +114,10 @@ dit(bf(CCACHE_DISABLE)) If you set the environment variable
 CCACHE_DISABLE then ccache will just call the real compiler,
 bypassing the cache completely.
 
+dit(bf(CCACHE_NOSTATS)) If you set the environment variable
+CCACHE_NOSTATS then ccache will not update the statistics files on
+each compile.
+
 dit(bf(CCACHE_NOUNIFY)) If you set the environment variable
 CCACHE_NOUNIFY then ccache will not use the C/C++ unifier when hashing
 the pre-processor output. The unifier is slower than a normal hash, so
diff --git a/stats.c b/stats.c
index 341ecad87aff5dcdf08867c726474920cddfdde0..2334174e0cc83528efaefcb59dffa43d2f49d5f0 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -29,34 +29,40 @@ extern char *cache_dir;
 
 #define STATS_VERSION 1
 
+#define FLAG_NOZERO 1
+
 static struct {
        enum stats stat;
        char *message;
        void (*fn)(unsigned );
-} stats_messages[] = {
-       { STATS_TOCACHE,      "cache miss                     ", NULL },
-       { STATS_CACHED,       "cache hit                      ", NULL },
-       { STATS_LINK,         "called for link                ", NULL },
-       { STATS_STDOUT,       "compiler produced stdout       ", NULL },
-       { STATS_STATUS,       "compile failed                 ", NULL },
-       { STATS_ERROR,        "ccache internal error          ", NULL },
-       { STATS_PREPROCESSOR, "preprocessor error             ", NULL },
-       { STATS_COMPILER,     "couldn't find the compiler     ", NULL },
-       { STATS_MISSING,      "cache file missing             ", NULL },
-       { STATS_ARGS,         "bad compiler arguments         ", NULL },
-       { STATS_NUMFILES,     "files in cache                 ", NULL },
-       { STATS_TOTALSIZE,    "cache size                     ", display_size },
-       { STATS_MAXFILES,     "max files                      ", NULL },
-       { STATS_MAXSIZE,      "max cache size                 ", display_size },
-       { STATS_NONE, NULL, NULL }
+       unsigned flags;
+} stats_info[] = {
+       { STATS_CACHED,       "cache hit                      ", NULL, 0 },
+       { STATS_TOCACHE,      "cache miss                     ", NULL, 0 },
+       { STATS_LINK,         "called for link                ", NULL, 0 },
+       { STATS_STDOUT,       "compiler produced stdout       ", NULL, 0 },
+       { STATS_STATUS,       "compile failed                 ", NULL, 0 },
+       { STATS_ERROR,        "ccache internal error          ", NULL, 0 },
+       { STATS_PREPROCESSOR, "preprocessor error             ", NULL, 0 },
+       { STATS_COMPILER,     "couldn't find the compiler     ", NULL, 0 },
+       { STATS_MISSING,      "cache file missing             ", NULL, 0 },
+       { STATS_ARGS,         "bad compiler arguments         ", NULL, 0 },
+       { STATS_NOTC,         "not a C/C++ file               ", NULL, 0 },
+       { STATS_DEVICE,       "output to a non-regular file   ", NULL, 0 },
+       { STATS_NOINPUT,      "no input file                  ", NULL, 0 },
+       { STATS_NUMFILES,     "files in cache                 ", NULL, FLAG_NOZERO },
+       { STATS_TOTALSIZE,    "cache size                     ", display_size , FLAG_NOZERO },
+       { STATS_MAXFILES,     "max files                      ", NULL, FLAG_NOZERO },
+       { STATS_MAXSIZE,      "max cache size                 ", display_size, FLAG_NOZERO },
+       { STATS_NONE, NULL, NULL, 0 }
 };
 
 /* return a string description of a statistic */
-static int stats_message(enum stats stat)
+static int stats_find(enum stats stat)
 {
        int i;
-       for (i=0;stats_messages[i].stat != STATS_NONE; i++) {
-               if (stats_messages[i].stat == stat) {
+       for (i=0;stats_info[i].stat != STATS_NONE; i++) {
+               if (stats_info[i].stat == stat) {
                        return i;
                }
        }
@@ -115,6 +121,8 @@ static void stats_update_size(enum stats stat, size_t size)
        unsigned counters[STATS_END];
        int need_cleanup = 0;
 
+       if (getenv("CCACHE_NOSTATS")) return;
+
        if (!stats_file) {
                if (!cache_dir) return;
                x_asprintf(&stats_file, "%s/stats", cache_dir);
@@ -211,17 +219,17 @@ void stats_summary(void)
        }
 
        /* and display them */
-       for (i=0;i<STATS_END;i++) {
-               if (counters[i] != 0) {
-                       int n = stats_message(i);
-                       if (n == -1) continue;
-                       printf("%s ", stats_messages[n].message);
-                       if (stats_messages[n].fn) {
-                               stats_messages[n].fn(counters[i]);
-                               printf("\n");
-                       } else {
-                               printf("%8u\n", counters[i]);
-                       }
+       for (i=0;stats_info[i].message;i++) {
+               enum stats stat = stats_info[i].stat;
+
+               if (counters[stat] == 0) continue;
+
+               printf("%s ", stats_info[i].message);
+               if (stats_info[i].fn) {
+                       stats_info[i].fn(counters[stat]);
+                       printf("\n");
+               } else {
+                       printf("%8u\n", counters[stat]);
                }
        }
 }
@@ -248,8 +256,11 @@ void stats_zero(void)
                lock_fd(fd);
                memset(counters, 0, sizeof(counters));
                stats_read_fd(fd, counters);
-               for (i=0;i<=STATS_LINK;i++) {
-                       counters[i] = 0;
+               for (i=0;i<=STATS_END;i++) {
+                       int n = stats_find(i);
+                       if (n != -1 && (!stats_info[n].flags & FLAG_NOZERO)) {
+                               counters[i] = 0;
+                       }
                }
                write_stats(fd, counters);
                close(fd);
index 5905a718f31d031baddfef372cc63200d2388c5f..91a5adb7eebb14b6d6ad7ccb1ae392e52056665c 100644 (file)
@@ -113,6 +113,9 @@ ccache itself.
 <p><p></p><dt><strong><strong>CCACHE_DISABLE</strong></strong><dd> If you set the environment variable
 CCACHE_DISABLE then ccache will just call the real compiler,
 bypassing the cache completely.
+<p><p></p><dt><strong><strong>CCACHE_NOSTATS</strong></strong><dd> If you set the environment variable
+CCACHE_NOSTATS then ccache will not update the statistics files on
+each compile.
 <p><p></p><dt><strong><strong>CCACHE_NOUNIFY</strong></strong><dd> If you set the environment variable
 CCACHE_NOUNIFY then ccache will not use the C/C++ unifier when hashing
 the pre-processor output. The unifier is slower than a normal hash, so