STATS_COMPCHECK = 26,
STATS_CANTUSEPCH = 27,
STATS_PREPROCESSING = 28,
+ STATS_NUMCLEANUPS = 29,
STATS_END
};
void stats_get_obsolete_limits(const char *dir, unsigned *maxfiles,
uint64_t *maxsize);
void stats_set_sizes(const char *dir, unsigned num_files, uint64_t total_size);
+void stats_add_cleanup(const char *dir, unsigned count);
void stats_read(const char *path, struct counters *counters);
void stats_write(const char *path, struct counters *counters);
/* sort the files we've found and delete the oldest ones until we are
below the thresholds */
-static void
+static bool
sort_and_clean(void)
{
unsigned i;
char *last_base = x_strdup("");
+ bool clean = false;
if (num_files > 1) {
/* Sort in ascending mtime order. */
/* .manifest or unknown file. */
delete_file(files[i]->fname, files[i]->size);
}
+ clean = true;
}
free(last_base);
+ return clean;
}
/* cleanup in one cache subdir */
cleanup_dir(struct conf *conf, const char *dir)
{
unsigned i;
+ bool clean;
cc_log("Cleaning up cache directory %s", dir);
traverse(dir, traverse_fn);
/* clean the cache */
- sort_and_clean();
+ clean = sort_and_clean();
+
+ if (clean) {
+ cc_log("Cleaned up cache directory %s", dir);
+ stats_add_cleanup(dir, 1);
+ }
stats_set_sizes(dir, files_in_cache, cache_size);
}
free(p);
+ files_in_cache++;
+
x_unlink(fname);
}
+/* wipe in one cache subdir */
+void
+wipe_dir(struct conf *conf, const char *dir)
+{
+ cc_log("Clearing out cache directory %s", dir);
+
+ files_in_cache_threshold = conf->max_files * LIMIT_MULTIPLE / 16;
+
+ files_in_cache = 0;
+
+ traverse(dir, wipe_fn);
+
+ if (files_in_cache > 0) {
+ cc_log("Cleared out cache directory %s", dir);
+ stats_add_cleanup(dir, 1);
+ }
+
+ files_in_cache = 0;
+}
+
/* wipe all cached files in all subdirs */
void wipe_all(struct conf *conf)
{
for (i = 0; i <= 0xF; i++) {
char *dname = format("%s/%1x", conf->cache_dir, i);
- traverse(dname, wipe_fn);
+ wipe_dir(conf, dname);
free(dname);
}
{ 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 ",
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);
+}
checkfilecount 0 '*.d' $CCACHE_DIR
checkfilecount 0 '*.stderr' $CCACHE_DIR
checkstat 'files in cache' 0
+ checkstat 'cleanups performed' 1
testname="forced cleanup, no limits"
$CCACHE -C >/dev/null
checkfilecount 10 '*.d' $CCACHE_DIR
checkfilecount 10 '*.stderr' $CCACHE_DIR
checkstat 'files in cache' 30
+ checkstat 'cleanups performed' 0
testname="forced cleanup, file limit"
$CCACHE -C >/dev/null
checkfilecount 7 '*.d' $CCACHE_DIR
checkfilecount 7 '*.stderr' $CCACHE_DIR
checkstat 'files in cache' 21
+ checkstat 'cleanups performed' 1
for i in 0 1 2 3 4 5 9; do
file=$CCACHE_DIR/a/result$i-4017.o
if [ ! -f $file ]; then
checkfilecount 3 '*.d' $CCACHE_DIR
checkfilecount 3 '*.stderr' $CCACHE_DIR
checkstat 'files in cache' 9
+ checkstat 'cleanups performed' 1
for i in 3 4 5; do
file=$CCACHE_DIR/a/result$i-4017.o
if [ ! -f $file ]; then
checkfilecount 156 '*.d' $CCACHE_DIR
checkfilecount 156 '*.stderr' $CCACHE_DIR
checkstat 'files in cache' 469
+ checkstat 'cleanups performed' 1
testname="sibling cleanup"
$CCACHE -C >/dev/null