Skip to content

Commit ece9d26

Browse files
benpeartGit for Windows Build Agent
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 <benpeart@microsoft.com>
1 parent f4ade51 commit ece9d26

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

compat/win32/fscache.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ static int initialized;
1111
static volatile long enabled;
1212
static struct hashmap map;
1313
static CRITICAL_SECTION mutex;
14+
static unsigned int lstat_requests;
15+
static unsigned int opendir_requests;
16+
static unsigned int fscache_requests;
17+
static unsigned int fscache_misses;
1418
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);
1519

1620
/*
@@ -272,6 +276,8 @@ static void fscache_clear(void)
272276
{
273277
hashmap_clear_and_free(&map, struct fsentry, ent);
274278
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
279+
lstat_requests = opendir_requests = 0;
280+
fscache_misses = fscache_requests = 0;
275281
}
276282

277283
/*
@@ -318,6 +324,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
318324
int dir_not_found;
319325

320326
EnterCriticalSection(&mutex);
327+
fscache_requests++;
321328
/* check if entry is in cache */
322329
fse = fscache_get_wait(key);
323330
if (fse) {
@@ -381,6 +388,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
381388
}
382389

383390
/* add directory listing to the cache */
391+
fscache_misses++;
384392
fscache_add(fse);
385393

386394
/* lookup file entry if requested (fse already points to directory) */
@@ -418,6 +426,8 @@ int fscache_enable(int enable)
418426
return 0;
419427

420428
InitializeCriticalSection(&mutex);
429+
lstat_requests = opendir_requests = 0;
430+
fscache_misses = fscache_requests = 0;
421431
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
422432
initialized = 1;
423433
}
@@ -434,6 +444,10 @@ int fscache_enable(int enable)
434444
opendir = dirent_opendir;
435445
lstat = mingw_lstat;
436446
EnterCriticalSection(&mutex);
447+
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
448+
"total requests/misses %u/%u\n",
449+
lstat_requests, opendir_requests,
450+
fscache_requests, fscache_misses);
437451
fscache_clear();
438452
LeaveCriticalSection(&mutex);
439453
}
@@ -471,6 +485,7 @@ int fscache_lstat(const char *filename, struct stat *st)
471485
if (!fscache_enabled(filename))
472486
return mingw_lstat(filename, st);
473487

488+
lstat_requests++;
474489
/* split filename into path + name */
475490
len = strlen(filename);
476491
if (len && is_dir_sep(filename[len - 1]))
@@ -564,6 +579,7 @@ DIR *fscache_opendir(const char *dirname)
564579
if (!fscache_enabled(dirname))
565580
return dirent_opendir(dirname);
566581

582+
opendir_requests++;
567583
/* prepare name (strip trailing '/', replace '.') */
568584
len = strlen(dirname);
569585
if ((len == 1 && dirname[0] == '.') ||

0 commit comments

Comments
 (0)