disk_cache: add env var to show stats

Signed-off-by: Eric Engestrom <eric@igalia.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Tested-by: Chris Healy <healych@amazon.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19644>
This commit is contained in:
Eric Engestrom 2022-11-10 11:36:46 +00:00 committed by Marge Bot
parent f7d7e558c9
commit 4a14ba6fce
3 changed files with 37 additions and 9 deletions

View file

@ -160,6 +160,9 @@ Core Mesa environment variables
will be stored in ``$XDG_CACHE_HOME/mesa_shader_cache`` (if that
variable is set), or else within ``.cache/mesa_shader_cache`` within
the user's home directory.
:envvar:`MESA_SHADER_CACHE_SHOW_STATS`
if set to ``true``, keeps hit/miss statistics for the shader cache.
These statistics are printed when the app terminates.
:envvar:`MESA_GLSL`
:ref:`shading language compiler options <envvars>`
:envvar:`MESA_NO_MINMAX_CACHE`

View file

@ -130,6 +130,9 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
cache->use_cache_db = true;
}
cache->stats.enabled = debug_get_bool_option("MESA_SHADER_CACHE_SHOW_STATS",
false);
if (!disk_cache_mmap_cache_index(local, cache, path))
goto path_fail;
@ -255,6 +258,12 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
void
disk_cache_destroy(struct disk_cache *cache)
{
if (unlikely(cache && cache->stats.enabled)) {
printf("disk shader cache: hits = %u, misses = %u\n",
cache->stats.hits,
cache->stats.misses);
}
if (cache && !cache->path_init_failed) {
util_queue_finish(&cache->cache_queue);
util_queue_destroy(&cache->cache_queue);
@ -523,23 +532,33 @@ disk_cache_put_nocopy(struct disk_cache *cache, const cache_key key,
void *
disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
{
void *buf;
if (size)
*size = 0;
if (cache->blob_get_cb)
return blob_get_compressed(cache, key, size);
if (debug_get_bool_option("MESA_DISK_CACHE_SINGLE_FILE", false)) {
return disk_cache_load_item_foz(cache, key, size);
if (cache->blob_get_cb) {
buf = blob_get_compressed(cache, key, size);
} else if (debug_get_bool_option("MESA_DISK_CACHE_SINGLE_FILE", false)) {
buf = disk_cache_load_item_foz(cache, key, size);
} else if (cache->use_cache_db) {
return disk_cache_db_load_item(cache, key, size);
buf = disk_cache_db_load_item(cache, key, size);
} else {
char *filename = disk_cache_get_cache_filename(cache, key);
if (filename == NULL)
return NULL;
return disk_cache_load_item(cache, filename, size);
buf = NULL;
else
buf = disk_cache_load_item(cache, filename, size);
}
if (unlikely(cache->stats.enabled)) {
if (buf)
p_atomic_inc(&cache->stats.hits);
else
p_atomic_inc(&cache->stats.misses);
}
return buf;
}
void

View file

@ -87,6 +87,12 @@ struct disk_cache {
/* Don't compress cached data. This is for testing purposes only. */
bool compression_disabled;
struct {
bool enabled;
unsigned hits;
unsigned misses;
} stats;
};
struct cache_entry_file_data {