From: Joel Rosdahl Date: Wed, 14 Jul 2010 13:57:57 +0000 (+0200) Subject: Let stats_update() update counters in memory and stats_flush() write to disk X-Git-Tag: v3.1~200 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fdad44c641ed4804688c3644ba338f9db095e63a;p=thirdparty%2Fccache.git Let stats_update() update counters in memory and stats_flush() write to disk --- diff --git a/ccache.c b/ccache.c index b97fa6b3c..1017ad237 100644 --- 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); } diff --git a/ccache.h b/ccache.h index 92691cb7d..68be2ae1c 100644 --- 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 d25a4c5a7..b77794c37 100644 --- 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 6f7c781d3..254fbd8a9 100644 --- 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); }