mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-01 08:20:36 +00:00
gpu: Improve cache stats printing
We no longer hardcode the few different classes we have, but generically walk over all classes. As a side effect we now get new classes added to stats automatically. The content itself did not change.
This commit is contained in:
parent
c47a3c54fd
commit
c1e008fa86
@ -60,6 +60,7 @@ G_DEFINE_TYPE (GskGpuCache, gsk_gpu_cache, G_TYPE_OBJECT)
|
|||||||
struct _GskGpuCachedClass
|
struct _GskGpuCachedClass
|
||||||
{
|
{
|
||||||
gsize size;
|
gsize size;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
void (* free) (GskGpuCache *cache,
|
void (* free) (GskGpuCache *cache,
|
||||||
GskGpuCached *cached);
|
GskGpuCached *cached);
|
||||||
@ -229,6 +230,7 @@ gsk_gpu_cached_atlas_should_collect (GskGpuCache *cache,
|
|||||||
static const GskGpuCachedClass GSK_GPU_CACHED_ATLAS_CLASS =
|
static const GskGpuCachedClass GSK_GPU_CACHED_ATLAS_CLASS =
|
||||||
{
|
{
|
||||||
sizeof (GskGpuCachedAtlas),
|
sizeof (GskGpuCachedAtlas),
|
||||||
|
"Atlas",
|
||||||
gsk_gpu_cached_atlas_free,
|
gsk_gpu_cached_atlas_free,
|
||||||
gsk_gpu_cached_atlas_should_collect
|
gsk_gpu_cached_atlas_should_collect
|
||||||
};
|
};
|
||||||
@ -341,6 +343,7 @@ gsk_gpu_cached_texture_should_collect (GskGpuCache *cache,
|
|||||||
static const GskGpuCachedClass GSK_GPU_CACHED_TEXTURE_CLASS =
|
static const GskGpuCachedClass GSK_GPU_CACHED_TEXTURE_CLASS =
|
||||||
{
|
{
|
||||||
sizeof (GskGpuCachedTexture),
|
sizeof (GskGpuCachedTexture),
|
||||||
|
"Texture",
|
||||||
gsk_gpu_cached_texture_free,
|
gsk_gpu_cached_texture_free,
|
||||||
gsk_gpu_cached_texture_should_collect
|
gsk_gpu_cached_texture_should_collect
|
||||||
};
|
};
|
||||||
@ -479,6 +482,7 @@ gsk_gpu_cached_tile_should_collect (GskGpuCache *cache,
|
|||||||
static const GskGpuCachedClass GSK_GPU_CACHED_TILE_CLASS =
|
static const GskGpuCachedClass GSK_GPU_CACHED_TILE_CLASS =
|
||||||
{
|
{
|
||||||
sizeof (GskGpuCachedTile),
|
sizeof (GskGpuCachedTile),
|
||||||
|
"Tile",
|
||||||
gsk_gpu_cached_tile_free,
|
gsk_gpu_cached_tile_free,
|
||||||
gsk_gpu_cached_tile_should_collect
|
gsk_gpu_cached_tile_should_collect
|
||||||
};
|
};
|
||||||
@ -662,6 +666,7 @@ gsk_gpu_cached_glyph_equal (gconstpointer v1,
|
|||||||
static const GskGpuCachedClass GSK_GPU_CACHED_GLYPH_CLASS =
|
static const GskGpuCachedClass GSK_GPU_CACHED_GLYPH_CLASS =
|
||||||
{
|
{
|
||||||
sizeof (GskGpuCachedGlyph),
|
sizeof (GskGpuCachedGlyph),
|
||||||
|
"Glyph",
|
||||||
gsk_gpu_cached_glyph_free,
|
gsk_gpu_cached_glyph_free,
|
||||||
gsk_gpu_cached_glyph_should_collect
|
gsk_gpu_cached_glyph_should_collect
|
||||||
};
|
};
|
||||||
@ -669,34 +674,38 @@ static const GskGpuCachedClass GSK_GPU_CACHED_GLYPH_CLASS =
|
|||||||
/* }}} */
|
/* }}} */
|
||||||
/* {{{ GskGpuCache */
|
/* {{{ GskGpuCache */
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
guint n_items;
|
||||||
|
guint n_stale;
|
||||||
|
} CacheData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_cache_stats (GskGpuCache *self)
|
print_cache_stats (GskGpuCache *self)
|
||||||
{
|
{
|
||||||
GskGpuCached *cached;
|
GskGpuCached *cached;
|
||||||
guint glyphs = 0;
|
GString *message;
|
||||||
guint stale_glyphs = 0;
|
|
||||||
guint textures = 0;
|
|
||||||
guint atlases = 0;
|
|
||||||
GString *ratios = g_string_new ("");
|
GString *ratios = g_string_new ("");
|
||||||
|
GHashTable *classes = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer key, value;
|
||||||
|
|
||||||
for (cached = self->first_cached; cached != NULL; cached = cached->next)
|
for (cached = self->first_cached; cached != NULL; cached = cached->next)
|
||||||
{
|
{
|
||||||
if (cached->class == &GSK_GPU_CACHED_GLYPH_CLASS)
|
CacheData *cache_data = g_hash_table_lookup (classes, cached->class);
|
||||||
|
if (cache_data == NULL)
|
||||||
{
|
{
|
||||||
glyphs++;
|
cache_data = g_new0 (CacheData, 1);
|
||||||
|
g_hash_table_insert (classes, (gpointer) cached->class, cache_data);
|
||||||
|
}
|
||||||
|
cache_data->n_items++;
|
||||||
if (cached->stale)
|
if (cached->stale)
|
||||||
stale_glyphs++;
|
cache_data->n_stale++;
|
||||||
}
|
|
||||||
else if (cached->class == &GSK_GPU_CACHED_TEXTURE_CLASS)
|
if (cached->class == &GSK_GPU_CACHED_ATLAS_CLASS)
|
||||||
{
|
|
||||||
textures++;
|
|
||||||
}
|
|
||||||
else if (cached->class == &GSK_GPU_CACHED_ATLAS_CLASS)
|
|
||||||
{
|
{
|
||||||
double ratio;
|
double ratio;
|
||||||
|
|
||||||
atlases++;
|
|
||||||
|
|
||||||
ratio = (double) cached->pixels / (double) (ATLAS_SIZE * ATLAS_SIZE);
|
ratio = (double) cached->pixels / (double) (ATLAS_SIZE * ATLAS_SIZE);
|
||||||
|
|
||||||
if (ratios->len == 0)
|
if (ratios->len == 0)
|
||||||
@ -710,14 +719,24 @@ print_cache_stats (GskGpuCache *self)
|
|||||||
if (ratios->len > 0)
|
if (ratios->len > 0)
|
||||||
g_string_append (ratios, ")");
|
g_string_append (ratios, ")");
|
||||||
|
|
||||||
gdk_debug_message ("Cached items\n"
|
message = g_string_new ("Cached items");
|
||||||
" glyphs: %5u (%u stale)\n"
|
g_hash_table_iter_init (&iter, classes);
|
||||||
" textures: %5u (%u in hash)\n"
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||||
" atlases: %5u%s",
|
{
|
||||||
glyphs, stale_glyphs,
|
const GskGpuCachedClass *class = key;
|
||||||
textures, g_hash_table_size (self->texture_cache),
|
const CacheData *cache_data = value;
|
||||||
atlases, ratios->str);
|
|
||||||
|
|
||||||
|
g_string_append_printf (message, "\n %s:%*s%5u (%u stale)", class->name, 12 - MIN (12, (int) strlen (class->name)), "", cache_data->n_items, cache_data->n_stale);
|
||||||
|
|
||||||
|
if (class == &GSK_GPU_CACHED_ATLAS_CLASS)
|
||||||
|
g_string_append_printf (message, "%s", ratios->str);
|
||||||
|
else if (class == &GSK_GPU_CACHED_TEXTURE_CLASS)
|
||||||
|
g_string_append_printf (message, " (%u in hash)", g_hash_table_size (self->texture_cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_debug_message ("%s", message->str);
|
||||||
|
g_string_free (message, TRUE);
|
||||||
|
g_hash_table_unref (classes);
|
||||||
g_string_free (ratios, TRUE);
|
g_string_free (ratios, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user