Skip to content

Commit 02e09fb

Browse files
committed
Merge pull request #1910 from benpeart/fscache_statistics-gfw
fscache: add fscache hit statistics
2 parents 60db471 + d278356 commit 02e09fb

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
/*
@@ -257,6 +261,8 @@ static void fscache_clear(void)
257261
{
258262
hashmap_free_entries(&map, struct fsentry, ent);
259263
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
264+
lstat_requests = opendir_requests = 0;
265+
fscache_misses = fscache_requests = 0;
260266
}
261267

262268
/*
@@ -303,6 +309,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
303309
int dir_not_found;
304310

305311
EnterCriticalSection(&mutex);
312+
fscache_requests++;
306313
/* check if entry is in cache */
307314
fse = fscache_get_wait(key);
308315
if (fse) {
@@ -366,6 +373,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
366373
}
367374

368375
/* add directory listing to the cache */
376+
fscache_misses++;
369377
fscache_add(fse);
370378

371379
/* lookup file entry if requested (fse already points to directory) */
@@ -403,6 +411,8 @@ int fscache_enable(int enable)
403411
return 0;
404412

405413
InitializeCriticalSection(&mutex);
414+
lstat_requests = opendir_requests = 0;
415+
fscache_misses = fscache_requests = 0;
406416
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
407417
initialized = 1;
408418
}
@@ -419,6 +429,10 @@ int fscache_enable(int enable)
419429
opendir = dirent_opendir;
420430
lstat = mingw_lstat;
421431
EnterCriticalSection(&mutex);
432+
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
433+
"total requests/misses %u/%u\n",
434+
lstat_requests, opendir_requests,
435+
fscache_requests, fscache_misses);
422436
fscache_clear();
423437
LeaveCriticalSection(&mutex);
424438
}
@@ -451,6 +465,7 @@ int fscache_lstat(const char *filename, struct stat *st)
451465
if (!fscache_enabled(filename))
452466
return mingw_lstat(filename, st);
453467

468+
lstat_requests++;
454469
/* split filename into path + name */
455470
len = strlen(filename);
456471
if (len && is_dir_sep(filename[len - 1]))
@@ -530,6 +545,7 @@ DIR *fscache_opendir(const char *dirname)
530545
if (!fscache_enabled(dirname))
531546
return dirent_opendir(dirname);
532547

548+
opendir_requests++;
533549
/* prepare name (strip trailing '/', replace '.') */
534550
len = strlen(dirname);
535551
if ((len == 1 && dirname[0] == '.') ||

0 commit comments

Comments
 (0)