Skip to content

Commit decd4ce

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 d6ad26b commit decd4ce

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
/*
@@ -248,6 +252,8 @@ static void fscache_clear(void)
248252
{
249253
hashmap_free(&map, 1);
250254
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
255+
lstat_requests = opendir_requests = 0;
256+
fscache_misses = fscache_requests = 0;
251257
}
252258

253259
/*
@@ -294,6 +300,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
294300
int dir_not_found;
295301

296302
EnterCriticalSection(&mutex);
303+
fscache_requests++;
297304
/* check if entry is in cache */
298305
fse = fscache_get_wait(key);
299306
if (fse) {
@@ -356,6 +363,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
356363
}
357364

358365
/* add directory listing to the cache */
366+
fscache_misses++;
359367
fscache_add(fse);
360368

361369
/* lookup file entry if requested (fse already points to directory) */
@@ -393,6 +401,8 @@ int fscache_enable(int enable)
393401
return 0;
394402

395403
InitializeCriticalSection(&mutex);
404+
lstat_requests = opendir_requests = 0;
405+
fscache_misses = fscache_requests = 0;
396406
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
397407
initialized = 1;
398408
}
@@ -409,6 +419,10 @@ int fscache_enable(int enable)
409419
opendir = dirent_opendir;
410420
lstat = mingw_lstat;
411421
EnterCriticalSection(&mutex);
422+
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
423+
"total requests/misses %u/%u\n",
424+
lstat_requests, opendir_requests,
425+
fscache_requests, fscache_misses);
412426
fscache_clear();
413427
LeaveCriticalSection(&mutex);
414428
}
@@ -428,6 +442,7 @@ int fscache_lstat(const char *filename, struct stat *st)
428442
if (!fscache_enabled(filename))
429443
return mingw_lstat(filename, st);
430444

445+
lstat_requests++;
431446
/* split filename into path + name */
432447
len = strlen(filename);
433448
if (len && is_dir_sep(filename[len - 1]))
@@ -507,6 +522,7 @@ DIR *fscache_opendir(const char *dirname)
507522
if (!fscache_enabled(dirname))
508523
return dirent_opendir(dirname);
509524

525+
opendir_requests++;
510526
/* prepare name (strip trailing '/', replace '.') */
511527
len = strlen(dirname);
512528
if ((len == 1 && dirname[0] == '.') ||

0 commit comments

Comments
 (0)