From 0924e802017d5a669041a86beb0f1348d5fda8da Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 26 Aug 2013 15:08:28 +0000 Subject: Dump glyph cache size as part of mudraw -M --- source/fitz/draw-glyph.c | 25 ++++++++++++++++++++++--- source/tools/mudraw.c | 14 +++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/fitz/draw-glyph.c b/source/fitz/draw-glyph.c index f38f9140..859c8762 100644 --- a/source/fitz/draw-glyph.c +++ b/source/fitz/draw-glyph.c @@ -34,6 +34,10 @@ struct fz_glyph_cache_s { int refs; int total; +#ifndef NDEBUG + int num_evictions; + int evicted; +#endif fz_glyph_cache_entry *entry[GLYPH_HASH_LEN]; fz_glyph_cache_entry *lru_head; fz_glyph_cache_entry *lru_tail; @@ -78,7 +82,7 @@ drop_glyph_cache_entry(fz_context *ctx, fz_glyph_cache_entry *entry) /* The glyph cache lock is always held when this function is called. */ static void -fz_evict_glyph_cache(fz_context *ctx) +do_purge(fz_context *ctx) { fz_glyph_cache *cache = ctx->glyph_cache; int i; @@ -96,7 +100,7 @@ void fz_purge_glyph_cache(fz_context *ctx) { fz_lock(ctx, FZ_LOCK_GLYPHCACHE); - fz_evict_glyph_cache(ctx); + do_purge(ctx); fz_unlock(ctx, FZ_LOCK_GLYPHCACHE); } @@ -110,7 +114,7 @@ fz_drop_glyph_cache_context(fz_context *ctx) ctx->glyph_cache->refs--; if (ctx->glyph_cache->refs == 0) { - fz_evict_glyph_cache(ctx); + do_purge(ctx); fz_free(ctx, ctx->glyph_cache); ctx->glyph_cache = NULL; } @@ -318,6 +322,10 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *ctm, f cache->total += val->w * val->h; while (cache->total > MAX_CACHE_SIZE) { +#ifndef NDEBUG + cache->num_evictions++; + cache->evicted += cache->lru_tail->val->w * cache->lru_tail->val->h; +#endif drop_glyph_cache_entry(ctx, cache->lru_tail); } @@ -339,3 +347,14 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *ctm, f return val; } + +void +fz_dump_glyph_cache_stats(fz_context *ctx) +{ + fz_glyph_cache *cache = ctx->glyph_cache; + + printf("Glyph Cache Size: %d\n", cache->total); +#ifndef NDEBUG + printf("Glyph Cache Evictions: %d (%d bytes)\n", cache->num_evictions, cache->evicted); +#endif +} diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 78b3cfba..7a6ad478 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -157,7 +157,7 @@ static int out_cs = CS_UNSET; static int memtrace_current = 0; static int memtrace_peak = 0; static int memtrace_total = 0; - +static int showmemory = 0; static fz_text_sheet *sheet = NULL; static fz_colorspace *colorspace; static char *filename; @@ -771,6 +771,11 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) if (showmd5 || showtime) printf("\n"); + if (showmemory) + { + fz_dump_glyph_cache_stats(ctx); + } + fz_flush_warnings(ctx); if (mujstest_file && needshot) @@ -921,7 +926,6 @@ int main(int argc, char **argv) int c; fz_context *ctx; fz_alloc_context alloc_ctx = { NULL, trace_malloc, trace_realloc, trace_free }; - int tracememory = 0; fz_var(doc); @@ -937,7 +941,7 @@ int main(int argc, char **argv) case 'b': alphabits = atoi(fz_optarg); break; case 'l': showoutline++; break; case 'm': showtime++; break; - case 'M': tracememory++; break; + case 'M': showmemory++; break; case 't': showtext++; break; case 'x': showxml++; break; case '5': showmd5++; break; @@ -972,7 +976,7 @@ int main(int argc, char **argv) mujstest_file = fopen(mujstest_filename, "wb"); } - ctx = fz_new_context((tracememory == 0 ? NULL : &alloc_ctx), NULL, FZ_STORE_DEFAULT); + ctx = fz_new_context((showmemory == 0 ? NULL : &alloc_ctx), NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); @@ -1213,7 +1217,7 @@ int main(int argc, char **argv) fz_free_context(ctx); - if (tracememory) + if (showmemory) { printf("Total memory use = %d bytes\n", memtrace_total); printf("Peak memory use = %d bytes\n", memtrace_peak); -- cgit v1.2.3