Commit: cf566d9520dd9278f38630d5a83474592abb5d0d
Parent: de9cb651aa6eabfd3e2dd83c07ddd10be667df2f
Author: Randy Palamar
Date: Sun, 29 Sep 2024 13:25:17 -0600
add glyph cache stats to debug overlay
Diffstat:
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/debug.c b/debug.c
@@ -259,6 +259,7 @@ draw_debug_overlay(Term *t, RenderPushBuffer *rpb)
v2 ws = t->gl.window_size;
s8 buf = s8alloc(&t->arena_for_frame, 128);
+ static GlyphCacheStats glyph_stats;
static Rect r;
static f32 max_text_width;
r.pos.x = ws.w - 1.1 * max_text_width;
@@ -309,6 +310,30 @@ draw_debug_overlay(Term *t, RenderPushBuffer *rpb)
if (ts.w > max_text_width) max_text_width = ts.w;
}
+ GlyphCacheStats new_glyph_stats = get_and_clear_glyph_cache_stats(&t->fa.glyph_cache);
+ if (new_glyph_stats.hit_count != 0)
+ glyph_stats = new_glyph_stats;
+ {
+ v2 ts = debug_measure_text(t, &t->debug_font, s8("Glyph Cache Stats:"), 1);
+ txt_pos.y = (u32)(txt_pos.y - ts.y - line_pad);
+ txt_pos.y = (u32)(txt_pos.y - ts.y - line_pad);
+ debug_draw_text(t, rpb, s8("Glyph Cache Stats:"), txt_pos, (Colour){.rgba = 0x1e9e33ff}, 1);
+
+ static char *fmts[ARRAY_COUNT(glyph_stats.E)] = {
+ " Hits: %u",
+ " Misses: %u",
+ " Recycles: %u",
+ };
+ for (u32 i = 0; i < ARRAY_COUNT(glyph_stats.E); i++) {
+ s8 txt = buf;
+ txt.len = snprintf((char *)txt.data, buf.len, fmts[i], glyph_stats.E[i]);
+ ts = debug_measure_text(t, &t->debug_font, txt, 1);
+ txt_pos.y = (u32)(txt_pos.y - ts.y - line_pad);
+ debug_draw_text(t, rpb, txt, txt_pos, (Colour){.rgba = 0x1e9e33ff}, 1);
+ if (ts.w > max_text_width) max_text_width = ts.w;
+ }
+ }
+
r.pos.y = txt_pos.y - 2 * line_pad;
r.size.h = ws.h - r.pos.y;
}
diff --git a/util.h b/util.h
@@ -327,10 +327,13 @@ typedef struct {
b32 uploaded_to_gpu;
} CachedGlyph;
-typedef struct {
- u32 hit_count;
- u32 miss_count;
- u32 recycle_count;
+typedef union {
+ struct {
+ u32 hit_count;
+ u32 miss_count;
+ u32 recycle_count;
+ };
+ u32 E[3];
} GlyphCacheStats;
typedef struct {