summaryrefslogtreecommitdiff
path: root/stats.c
diff options
context:
space:
mode:
authorAnders Björklund <anders@itension.se>2015-09-25 19:22:44 +0200
committerJoel Rosdahl <joel@rosdahl.net>2016-07-21 21:40:07 +0200
commit0769ea3630efd6315303f7325fc16d73a0ef1a4d (patch)
tree5eb3a6200269b8958c9f1a4216440c2155c03da0 /stats.c
parent5fdb77458a0d34a4d24e2ca82138197bcd083685 (diff)
downloadccache-0769ea3630efd6315303f7325fc16d73a0ef1a4d.tar.gz
Count the number of cleanups performed, in stats
When running a busy ccache, it is useful to keep track of the number of cleanups performed to know when you need to increase the cache size. The number shown is actually the number of subdirectories, so when you do a full cleanup the counter usually increases by 16 (not just 1).
Diffstat (limited to 'stats.c')
-rw-r--r--stats.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/stats.c b/stats.c
index 5f217657..e9a8f09e 100644
--- a/stats.c
+++ b/stats.c
@@ -78,6 +78,7 @@ static struct {
{ STATS_DEVICE, "output to a non-regular file ", NULL, 0 },
{ STATS_NOINPUT, "no input file ", NULL, 0 },
{ STATS_BADEXTRAFILE, "error hashing extra file ", NULL, 0 },
+ { STATS_NUMCLEANUPS, "cleanups performed ", NULL, FLAG_ALWAYS },
{ STATS_NUMFILES, "files in cache ", NULL,
FLAG_NOZERO|FLAG_ALWAYS },
{ STATS_TOTALSIZE, "cache size ",
@@ -407,3 +408,22 @@ stats_set_sizes(const char *dir, unsigned num_files, uint64_t total_size)
free(statsfile);
counters_free(counters);
}
+
+/* count directory cleanup run */
+void
+stats_add_cleanup(const char *dir, unsigned count)
+{
+ struct counters *counters = counters_init(STATS_END);
+ char *statsfile;
+
+ statsfile = format("%s/stats", dir);
+
+ if (lockfile_acquire(statsfile, lock_staleness_limit)) {
+ stats_read(statsfile, counters);
+ counters->data[STATS_NUMCLEANUPS] += count;
+ stats_write(statsfile, counters);
+ lockfile_release(statsfile);
+ }
+ free(statsfile);
+ counters_free(counters);
+}