Skip to content

Commit 5e1ad8e

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 52e05f8 commit 5e1ad8e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compat/win32/fscache.c

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ static int initialized;
99
static volatile long enabled;
1010
static struct hashmap map;
1111
static CRITICAL_SECTION mutex;
12+
static unsigned int lstat_requests;
13+
static unsigned int opendir_requests;
14+
static unsigned int fscache_requests;
15+
static unsigned int fscache_misses;
1216
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1317

1418
/*
@@ -263,6 +267,8 @@ static void fscache_clear(void)
263267
{
264268
hashmap_clear_and_free(&map, struct fsentry, ent);
265269
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
270+
lstat_requests = opendir_requests = 0;
271+
fscache_misses = fscache_requests = 0;
266272
}
267273

268274
/*
@@ -309,6 +315,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
309315
int dir_not_found;
310316

311317
EnterCriticalSection(&mutex);
318+
fscache_requests++;
312319
/* check if entry is in cache */
313320
fse = fscache_get_wait(key);
314321
if (fse) {
@@ -372,6 +379,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
372379
}
373380

374381
/* add directory listing to the cache */
382+
fscache_misses++;
375383
fscache_add(fse);
376384

377385
/* lookup file entry if requested (fse already points to directory) */
@@ -409,6 +417,8 @@ int fscache_enable(int enable)
409417
return 0;
410418

411419
InitializeCriticalSection(&mutex);
420+
lstat_requests = opendir_requests = 0;
421+
fscache_misses = fscache_requests = 0;
412422
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
413423
initialized = 1;
414424
}
@@ -425,6 +435,10 @@ int fscache_enable(int enable)
425435
opendir = dirent_opendir;
426436
lstat = mingw_lstat;
427437
EnterCriticalSection(&mutex);
438+
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
439+
"total requests/misses %u/%u\n",
440+
lstat_requests, opendir_requests,
441+
fscache_requests, fscache_misses);
428442
fscache_clear();
429443
LeaveCriticalSection(&mutex);
430444
}
@@ -457,6 +471,7 @@ int fscache_lstat(const char *filename, struct stat *st)
457471
if (!fscache_enabled(filename))
458472
return mingw_lstat(filename, st);
459473

474+
lstat_requests++;
460475
/* split filename into path + name */
461476
len = strlen(filename);
462477
if (len && is_dir_sep(filename[len - 1]))
@@ -538,6 +553,7 @@ DIR *fscache_opendir(const char *dirname)
538553
if (!fscache_enabled(dirname))
539554
return dirent_opendir(dirname);
540555

556+
opendir_requests++;
541557
/* prepare name (strip trailing '/', replace '.') */
542558
len = strlen(dirname);
543559
if ((len == 1 && dirname[0] == '.') ||

0 commit comments

Comments
 (0)