Skip to content

Commit 408027a

Browse files
benpeartdscho
authored andcommitted
fscache: add fscache hit statistics
Track fscache hits and misses for lstat and opendir requests. Reporting of statistics is done when the cache is disabled for the last time and freed and is only reported if GIT_TRACE_FSCACHE is set. Sample output is: 11:33:11.836428 compat/win32/fscache.c:433 fscache: lstat 3775, opendir 263, total requests/misses 4052/269 Signed-off-by: Ben Peart <[email protected]>
1 parent d126289 commit 408027a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compat/win32/fscache.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ static int initialized;
88
static volatile long enabled;
99
static struct hashmap map;
1010
static CRITICAL_SECTION mutex;
11+
static unsigned int lstat_requests;
12+
static unsigned int opendir_requests;
13+
static unsigned int fscache_requests;
14+
static unsigned int fscache_misses;
1115
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1216

1317
/*
@@ -260,6 +264,8 @@ static void fscache_clear(void)
260264
{
261265
hashmap_clear_and_free(&map, struct fsentry, ent);
262266
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
267+
lstat_requests = opendir_requests = 0;
268+
fscache_misses = fscache_requests = 0;
263269
}
264270

265271
/*
@@ -306,6 +312,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
306312
int dir_not_found;
307313

308314
EnterCriticalSection(&mutex);
315+
fscache_requests++;
309316
/* check if entry is in cache */
310317
fse = fscache_get_wait(key);
311318
if (fse) {
@@ -369,6 +376,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
369376
}
370377

371378
/* add directory listing to the cache */
379+
fscache_misses++;
372380
fscache_add(fse);
373381

374382
/* lookup file entry if requested (fse already points to directory) */
@@ -406,6 +414,8 @@ int fscache_enable(int enable)
406414
return 0;
407415

408416
InitializeCriticalSection(&mutex);
417+
lstat_requests = opendir_requests = 0;
418+
fscache_misses = fscache_requests = 0;
409419
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
410420
initialized = 1;
411421
}
@@ -422,6 +432,10 @@ int fscache_enable(int enable)
422432
opendir = dirent_opendir;
423433
lstat = mingw_lstat;
424434
EnterCriticalSection(&mutex);
435+
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
436+
"total requests/misses %u/%u\n",
437+
lstat_requests, opendir_requests,
438+
fscache_requests, fscache_misses);
425439
fscache_clear();
426440
LeaveCriticalSection(&mutex);
427441
}
@@ -454,6 +468,7 @@ int fscache_lstat(const char *filename, struct stat *st)
454468
if (!fscache_enabled(filename))
455469
return mingw_lstat(filename, st);
456470

471+
lstat_requests++;
457472
/* split filename into path + name */
458473
len = strlen(filename);
459474
if (len && is_dir_sep(filename[len - 1]))
@@ -533,6 +548,7 @@ DIR *fscache_opendir(const char *dirname)
533548
if (!fscache_enabled(dirname))
534549
return dirent_opendir(dirname);
535550

551+
opendir_requests++;
536552
/* prepare name (strip trailing '/', replace '.') */
537553
len = strlen(dirname);
538554
if ((len == 1 && dirname[0] == '.') ||

0 commit comments

Comments
 (0)