]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Let stats_update() update counters in memory and stats_flush() write to disk
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 14 Jul 2010 13:57:57 +0000 (15:57 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 14 Jul 2010 13:57:57 +0000 (15:57 +0200)
ccache.c
ccache.h
stats.c
util.c

index b97fa6b3c9989b1a646f5bdeae6a2dfa67843284..1017ad237b9c6587687a957f763cfcadede32b98 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -253,6 +253,8 @@ static void failed(void)
 {
        char *e;
 
+       stats_flush();
+
        /* delete intermediate pre-processor file if needed */
        if (i_tmpfile) {
                if (!direct_i_file) {
@@ -703,6 +705,7 @@ static void to_cache(ARGS *args)
                                if (i_tmpfile && !direct_i_file) {
                                        unlink(i_tmpfile);
                                }
+                               stats_flush();
                                exit(status);
                        }
                }
@@ -1284,6 +1287,7 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest
        }
 
        /* and exit with the right status code */
+       stats_flush();
        exit(0);
 }
 
index 92691cb7d0b74b07465139760bf954c5c8f5868a..68be2ae1cd791aec7a34a86d4c73d27176f4b5ab 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -110,6 +110,7 @@ char *get_relative_path(const char *from, const char *to);
 void update_mtime(const char *path);
 
 void stats_update(enum stats stat);
+void stats_flush(void);
 void stats_zero(void);
 void stats_summary(void);
 void stats_update_size(enum stats stat, size_t size, unsigned files);
diff --git a/stats.c b/stats.c
index d25a4c5a778341cb9dfff9db2d011c802e5e7c0f..b77794c37648aa9e4edff53606ef820011e41050 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -35,6 +35,8 @@
 extern char *stats_file;
 extern char *cache_dir;
 
+static unsigned counter_updates[STATS_END];
+
 /* default maximum cache size */
 #ifndef DEFAULT_MAXSIZE
 #define DEFAULT_MAXSIZE (1024*1024)
@@ -145,13 +147,34 @@ static void stats_read_fd(int fd, unsigned counters[STATS_END])
  * number of bytes and files have been added to the cache. Size is in KiB.
  */
 void stats_update_size(enum stats stat, size_t size, unsigned files)
+{
+       if (stat != STATS_NONE) {
+               counter_updates[stat]++;
+       }
+       counter_updates[STATS_NUMFILES] += files;
+       counter_updates[STATS_TOTALSIZE] += size;
+}
+
+/*
+ * Write counter updates in pending_counters to disk.
+ */
+void stats_flush(void)
 {
        int fd;
        unsigned counters[STATS_END];
        int need_cleanup = 0;
+       int should_flush = 0;
+       int i;
 
        if (getenv("CCACHE_NOSTATS")) return;
 
+       for (i = 0; i < STATS_END; ++i) {
+               if (counter_updates[i] > 0) {
+                       should_flush = 1;
+               }
+       }
+       if (!should_flush) return;
+
        if (!stats_file) {
                /*
                 * A NULL stats_file means that we didn't get past calculate_object_hash(),
@@ -169,11 +192,9 @@ void stats_update_size(enum stats stat, size_t size, unsigned files)
        memset(counters, 0, sizeof(counters));
        stats_read_fd(fd, counters);
 
-       if (stat != STATS_NONE) {
-               counters[stat]++;
+       for (i = 0; i < STATS_END; ++i) {
+               counters[i] += counter_updates[i];
        }
-       counters[STATS_NUMFILES] += files;
-       counters[STATS_TOTALSIZE] += size;
 
        write_stats(fd, counters);
        close(fd);
diff --git a/util.c b/util.c
index 6f7c781d378d13d77e03ef13209554b2435238e3..254fbd8a9bff0bc3e5c4c163c85ab5db4857f539 100644 (file)
--- a/util.c
+++ b/util.c
@@ -135,6 +135,7 @@ void fatal(const char *format, ...)
 
        fprintf(stderr, "ccache: FATAL: %s\n", msg);
 
+       stats_flush();
        exit(1);
 }