Skip to content

Commit aec157c

Browse files
committed
Merge pull request #1910 from benpeart/fscache_statistics-gfw
fscache: add fscache hit statistics
2 parents e7fb1f7 + 60ce08b commit aec157c

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
/*
@@ -262,6 +266,8 @@ static void fscache_clear(void)
262266
{
263267
hashmap_clear_and_free(&map, struct fsentry, ent);
264268
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
269+
lstat_requests = opendir_requests = 0;
270+
fscache_misses = fscache_requests = 0;
265271
}
266272

267273
/*
@@ -308,6 +314,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
308314
int dir_not_found;
309315

310316
EnterCriticalSection(&mutex);
317+
fscache_requests++;
311318
/* check if entry is in cache */
312319
fse = fscache_get_wait(key);
313320
if (fse) {
@@ -371,6 +378,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
371378
}
372379

373380
/* add directory listing to the cache */
381+
fscache_misses++;
374382
fscache_add(fse);
375383

376384
/* lookup file entry if requested (fse already points to directory) */
@@ -408,6 +416,8 @@ int fscache_enable(int enable)
408416
return 0;
409417

410418
InitializeCriticalSection(&mutex);
419+
lstat_requests = opendir_requests = 0;
420+
fscache_misses = fscache_requests = 0;
411421
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
412422
initialized = 1;
413423
}
@@ -424,6 +434,10 @@ int fscache_enable(int enable)
424434
opendir = dirent_opendir;
425435
lstat = mingw_lstat;
426436
EnterCriticalSection(&mutex);
437+
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
438+
"total requests/misses %u/%u\n",
439+
lstat_requests, opendir_requests,
440+
fscache_requests, fscache_misses);
427441
fscache_clear();
428442
LeaveCriticalSection(&mutex);
429443
}
@@ -456,6 +470,7 @@ int fscache_lstat(const char *filename, struct stat *st)
456470
if (!fscache_enabled(filename))
457471
return mingw_lstat(filename, st);
458472

473+
lstat_requests++;
459474
/* split filename into path + name */
460475
len = strlen(filename);
461476
if (len && is_dir_sep(filename[len - 1]))
@@ -537,6 +552,7 @@ DIR *fscache_opendir(const char *dirname)
537552
if (!fscache_enabled(dirname))
538553
return dirent_opendir(dirname);
539554

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

0 commit comments

Comments
 (0)