Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fscache: add fscache hit statistics #1910

Merged
merged 1 commit into from
Nov 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions compat/win32/fscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ static int initialized;
static volatile long enabled;
static struct hashmap map;
static CRITICAL_SECTION mutex;
static unsigned int lstat_requests;
static unsigned int opendir_requests;
static unsigned int fscache_requests;
static unsigned int fscache_misses;
static struct trace_key trace_fscache = TRACE_KEY_INIT(FSCACHE);

/*
Expand Down Expand Up @@ -260,6 +264,8 @@ static void fscache_clear(void)
{
hashmap_free(&map, 1);
hashmap_init(&map, (hashmap_cmp_fn)fsentry_cmp, NULL, 0);
lstat_requests = opendir_requests = 0;
fscache_misses = fscache_requests = 0;
}

/*
Expand Down Expand Up @@ -306,6 +312,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
int dir_not_found;

EnterCriticalSection(&mutex);
fscache_requests++;
/* check if entry is in cache */
fse = fscache_get_wait(key);
if (fse) {
Expand Down Expand Up @@ -368,6 +375,7 @@ static struct fsentry *fscache_get(struct fsentry *key)
}

/* add directory listing to the cache */
fscache_misses++;
fscache_add(fse);

/* lookup file entry if requested (fse already points to directory) */
Expand Down Expand Up @@ -401,6 +409,8 @@ int fscache_enable(int enable)
return 0;

InitializeCriticalSection(&mutex);
lstat_requests = opendir_requests = 0;
fscache_misses = fscache_requests = 0;
hashmap_init(&map, (hashmap_cmp_fn) fsentry_cmp, NULL, 0);
initialized = 1;
}
Expand All @@ -417,6 +427,10 @@ int fscache_enable(int enable)
opendir = dirent_opendir;
lstat = mingw_lstat;
EnterCriticalSection(&mutex);
trace_printf_key(&trace_fscache, "fscache: lstat %u, opendir %u, "
"total requests/misses %u/%u\n",
lstat_requests, opendir_requests,
fscache_requests, fscache_misses);
fscache_clear();
LeaveCriticalSection(&mutex);
}
Expand Down Expand Up @@ -448,6 +462,7 @@ int fscache_lstat(const char *filename, struct stat *st)
if (!fscache_enabled(filename))
return mingw_lstat(filename, st);

lstat_requests++;
/* split filename into path + name */
len = strlen(filename);
if (len && is_dir_sep(filename[len - 1]))
Expand Down Expand Up @@ -528,6 +543,7 @@ DIR *fscache_opendir(const char *dirname)
if (!fscache_enabled(dirname))
return dirent_opendir(dirname);

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