summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-04-26 14:34:31 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-04-27 15:12:03 +0200
commit2ccb4fe72b9af0241d16a0d206fc8dcf3c2497df (patch)
treea983427b532e9f082bc58ce26b91ff782f858f55 /source
parentcabf4489896a2a978361eb6e1df4b4aef81193f4 (diff)
downloadmupdf-2ccb4fe72b9af0241d16a0d206fc8dcf3c2497df.tar.xz
Clean up store debug printing.
Replace fz_print_hash with fz_hash_for_each iterator. Use string formatting callback.
Diffstat (limited to 'source')
-rw-r--r--source/fitz/draw-device.c24
-rw-r--r--source/fitz/hash.c31
-rw-r--r--source/fitz/image.c6
-rw-r--r--source/fitz/store.c52
-rw-r--r--source/pdf/pdf-font.c7
-rw-r--r--source/pdf/pdf-store.c9
6 files changed, 64 insertions, 65 deletions
diff --git a/source/fitz/draw-device.c b/source/fitz/draw-device.c
index f4425558..4e10829f 100644
--- a/source/fitz/draw-device.c
+++ b/source/fitz/draw-device.c
@@ -1899,7 +1899,7 @@ typedef struct
static int
fz_make_hash_tile_key(fz_context *ctx, fz_store_hash *hash, void *key_)
{
- tile_key *key = (tile_key *)key_;
+ tile_key *key = key_;
hash->u.im.id = key->id;
hash->u.im.m[0] = key->ctm[0];
@@ -1912,14 +1912,14 @@ fz_make_hash_tile_key(fz_context *ctx, fz_store_hash *hash, void *key_)
static void *
fz_keep_tile_key(fz_context *ctx, void *key_)
{
- tile_key *key = (tile_key *)key_;
+ tile_key *key = key_;
return fz_keep_imp(ctx, key, &key->refs);
}
static void
fz_drop_tile_key(fz_context *ctx, void *key_)
{
- tile_key *key = (tile_key *)key_;
+ tile_key *key = key_;
if (fz_drop_imp(ctx, key, &key->refs))
fz_free(ctx, key);
}
@@ -1927,16 +1927,21 @@ fz_drop_tile_key(fz_context *ctx, void *key_)
static int
fz_cmp_tile_key(fz_context *ctx, void *k0_, void *k1_)
{
- tile_key *k0 = (tile_key *)k0_;
- tile_key *k1 = (tile_key *)k1_;
- return k0->id == k1->id && k0->ctm[0] == k1->ctm[0] && k0->ctm[1] == k1->ctm[1] && k0->ctm[2] == k1->ctm[2] && k0->ctm[3] == k1->ctm[3];
+ tile_key *k0 = k0_;
+ tile_key *k1 = k1_;
+ return k0->id == k1->id &&
+ k0->ctm[0] == k1->ctm[0] &&
+ k0->ctm[1] == k1->ctm[1] &&
+ k0->ctm[2] == k1->ctm[2] &&
+ k0->ctm[3] == k1->ctm[3];
}
static void
-fz_print_tile(fz_context *ctx, fz_output *out, void *key_)
+fz_format_tile_key(fz_context *ctx, char *s, int n, void *key_)
{
tile_key *key = (tile_key *)key_;
- fz_write_printf(ctx, out, "(tile id=%x, ctm=%g %g %g %g) ", key->id, key->ctm[0], key->ctm[1], key->ctm[2], key->ctm[3]);
+ fz_snprintf(s, n, "(tile id=%x, ctm=%g %g %g %g)",
+ key->id, key->ctm[0], key->ctm[1], key->ctm[2], key->ctm[3]);
}
static const fz_store_type fz_tile_store_type =
@@ -1945,7 +1950,8 @@ static const fz_store_type fz_tile_store_type =
fz_keep_tile_key,
fz_drop_tile_key,
fz_cmp_tile_key,
- fz_print_tile
+ fz_format_tile_key,
+ NULL
};
static void
diff --git a/source/fitz/hash.c b/source/fitz/hash.c
index 38393caf..245ebbd8 100644
--- a/source/fitz/hash.c
+++ b/source/fitz/hash.c
@@ -283,31 +283,10 @@ fz_hash_remove(fz_context *ctx, fz_hash_table *table, const void *key)
}
void
-fz_print_hash(fz_context *ctx, fz_output *out, fz_hash_table *table)
+fz_hash_for_each(fz_context *ctx, fz_hash_table *table, void *state, fz_hash_table_for_each_fn callback)
{
- fz_print_hash_details(ctx, out, table, NULL, 0);
-}
-
-void
-fz_print_hash_details(fz_context *ctx, fz_output *out, fz_hash_table *table, void (*details)(fz_context*,fz_output*,void*), int compact)
-{
- int i, k;
-
- fz_write_printf(ctx, out, "cache load %d / %d\n", table->load, table->size);
-
- for (i = 0; i < table->size; i++)
- {
- if (!table->ents[i].val && !compact)
- fz_write_printf(ctx, out, "table %04d: empty\n", i);
- else if (table->ents[i].val)
- {
- fz_write_printf(ctx, out, "table %04d: key=", i);
- for (k = 0; k < MAX_KEY_LEN; k++)
- fz_write_printf(ctx, out, "%02x", ((unsigned char*)table->ents[i].key)[k]);
- if (details)
- details(ctx, out, table->ents[i].val);
- else
- fz_write_printf(ctx, out, " val=$%p\n", table->ents[i].val);
- }
- }
+ int i;
+ for (i = 0; i < table->size; ++i)
+ if (table->ents[i].val)
+ callback(ctx, state, table->ents[i].key, table->keylen, table->ents[i].val);
}
diff --git a/source/fitz/image.c b/source/fitz/image.c
index 057d6480..cedb0180 100644
--- a/source/fitz/image.c
+++ b/source/fitz/image.c
@@ -87,10 +87,10 @@ fz_cmp_image_key(fz_context *ctx, void *k0_, void *k1_)
}
static void
-fz_print_image_key(fz_context *ctx, fz_output *out, void *key_)
+fz_format_image_key(fz_context *ctx, char *s, int n, void *key_)
{
fz_image_key *key = (fz_image_key *)key_;
- fz_write_printf(ctx, out, "(image %d x %d sf=%d) ", key->image->w, key->image->h, key->l2factor);
+ fz_snprintf(s, n, "(image %d x %d sf=%d)", key->image->w, key->image->h, key->l2factor);
}
static int
@@ -107,7 +107,7 @@ static const fz_store_type fz_image_store_type =
fz_keep_image_key,
fz_drop_image_key,
fz_cmp_image_key,
- fz_print_image_key,
+ fz_format_image_key,
fz_needs_reap_image_key
};
diff --git a/source/fitz/store.c b/source/fitz/store.c
index dbff08fc..e2ce8d01 100644
--- a/source/fitz/store.c
+++ b/source/fitz/store.c
@@ -1,5 +1,8 @@
#include "mupdf/fitz.h"
+#include <assert.h>
+#include <stdio.h>
+
typedef struct fz_item_s fz_item;
struct fz_item_s
@@ -669,43 +672,54 @@ fz_drop_store_context(fz_context *ctx)
}
static void
-print_item(fz_context *ctx, fz_output *out, void *item_)
+fz_debug_store_item(fz_context *ctx, void *state, void *key_, int keylen, void *item_)
{
- fz_item *item = (fz_item *)item_;
- fz_write_printf(ctx, out, " val=%p item=%p\n", item->val, item);
+ unsigned char *key = key_;
+ fz_item *item = item_;
+ int i;
+ char buf[256];
+ fz_unlock(ctx, FZ_LOCK_ALLOC);
+ item->type->format_key(ctx, buf, sizeof buf, item->key);
+ fz_lock(ctx, FZ_LOCK_ALLOC);
+ printf("hash[");
+ for (i=0; i < keylen; ++i)
+ printf("%02x", key[i]);
+ printf("][refs=%d][size=%d] key=%s val=%p\n", item->val->refs, (int)item->size, buf, item->val);
}
-void
-fz_print_store_locked(fz_context *ctx, fz_output *out)
+static void
+fz_debug_store_locked(fz_context *ctx)
{
fz_item *item, *next;
+ char buf[256];
fz_store *store = ctx->store;
- fz_write_printf(ctx, out, "-- resource store contents --\n");
+ printf("-- resource store contents --\n");
for (item = store->head; item; item = next)
{
next = item->next;
if (next)
next->val->refs++;
- fz_write_printf(ctx, out, "store[*][refs=%d][size=%d] ", item->val->refs, item->size);
fz_unlock(ctx, FZ_LOCK_ALLOC);
- item->type->print(ctx, out, item->key);
- fz_write_printf(ctx, out, " = %p\n", item->val);
+ item->type->format_key(ctx, buf, sizeof buf, item->key);
fz_lock(ctx, FZ_LOCK_ALLOC);
+ printf("store[*][refs=%d][size=%d] key=%s val=%p\n",
+ item->val->refs, (int)item->size, buf, item->val);
if (next)
next->val->refs--;
}
- fz_write_printf(ctx, out, "-- resource store hash contents --\n");
- fz_print_hash_details(ctx, out, store->hash, print_item, 1);
- fz_write_printf(ctx, out, "-- end --\n");
+
+ printf("-- resource store hash contents --\n");
+ fz_hash_for_each(ctx, store->hash, NULL, fz_debug_store_item);
+ printf("-- end --\n");
}
void
-fz_print_store(fz_context *ctx, fz_output *out)
+fz_debug_store(fz_context *ctx)
{
fz_lock(ctx, FZ_LOCK_ALLOC);
- fz_print_store_locked(ctx, out);
+ fz_debug_store_locked(ctx);
fz_unlock(ctx, FZ_LOCK_ALLOC);
}
@@ -751,7 +765,7 @@ int fz_store_scavenge(fz_context *ctx, size_t size, int *phase)
#ifdef DEBUG_SCAVENGING
printf("Scavenging: store=" FZ_FMT_zu " size=" FZ_FMT_zu " phase=%d\n", store->size, size, *phase);
- fz_print_store_locked(ctx, stderr);
+ fz_debug_store_locked(ctx);
Memento_stats();
#endif
do
@@ -779,7 +793,7 @@ int fz_store_scavenge(fz_context *ctx, size_t size, int *phase)
{
#ifdef DEBUG_SCAVENGING
printf("scavenged: store=" FZ_FMT_zu "\n", store->size);
- fz_print_store(ctx, stderr);
+ fz_debug_store(ctx);
Memento_stats();
#endif
return 1;
@@ -789,7 +803,7 @@ int fz_store_scavenge(fz_context *ctx, size_t size, int *phase)
#ifdef DEBUG_SCAVENGING
printf("scavenging failed\n");
- fz_print_store(ctx, stderr);
+ fz_debug_store(ctx);
Memento_listBlocks();
#endif
return 0;
@@ -810,7 +824,7 @@ fz_shrink_store(fz_context *ctx, unsigned int percent)
return 0;
#ifdef DEBUG_SCAVENGING
- fprintf(stderr, "fz_shrink_store: " FZ_FMT_zu "\n", store->size/(1024*1024));
+ printf("fz_shrink_store: " FZ_FMT_zu "\n", store->size/(1024*1024));
#endif
fz_lock(ctx, FZ_LOCK_ALLOC);
@@ -821,7 +835,7 @@ fz_shrink_store(fz_context *ctx, unsigned int percent)
success = (store->size <= new_size) ? 1 : 0;
fz_unlock(ctx, FZ_LOCK_ALLOC);
#ifdef DEBUG_SCAVENGING
- fprintf(stderr, "fz_shrink_store after: " FZ_FMT_zu "\n", store->size/(1024*1024));
+ printf("fz_shrink_store after: " FZ_FMT_zu "\n", store->size/(1024*1024));
#endif
return success;
diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c
index cee094b9..43390247 100644
--- a/source/pdf/pdf-font.c
+++ b/source/pdf/pdf-font.c
@@ -961,9 +961,9 @@ hail_mary_cmp_key(fz_context *ctx, void *k0, void *k1)
}
static void
-hail_mary_print_key(fz_context *ctx, fz_output *out, void *key_)
+hail_mary_format_key(fz_context *ctx, char *s, int n, void *key_)
{
- fz_write_printf(ctx, out, "hail mary ");
+ fz_strlcpy(s, "(hail mary font)", n);
}
static int hail_mary_store_key; /* Dummy */
@@ -974,7 +974,8 @@ static const fz_store_type hail_mary_store_type =
hail_mary_keep_key,
hail_mary_drop_key,
hail_mary_cmp_key,
- hail_mary_print_key
+ hail_mary_format_key,
+ NULL
};
pdf_font_desc *
diff --git a/source/pdf/pdf-store.c b/source/pdf/pdf-store.c
index 15828d79..7b562d1a 100644
--- a/source/pdf/pdf-store.c
+++ b/source/pdf/pdf-store.c
@@ -34,14 +34,13 @@ pdf_cmp_key(fz_context *ctx, void *k0, void *k1)
}
static void
-pdf_print_key(fz_context *ctx, fz_output *out, void *key_)
+pdf_format_key(fz_context *ctx, char *s, int n, void *key_)
{
pdf_obj *key = (pdf_obj *)key_;
-
if (pdf_is_indirect(ctx, key))
- fz_write_printf(ctx, out, "(%d 0 R) ", pdf_to_num(ctx, key));
+ fz_snprintf(s, n, "(%d 0 R)", pdf_to_num(ctx, key));
else
- pdf_print_obj(ctx, out, key, 0);
+ pdf_sprint_obj(ctx, s, n, key, 1);
}
static const fz_store_type pdf_obj_store_type =
@@ -50,7 +49,7 @@ static const fz_store_type pdf_obj_store_type =
pdf_keep_key,
pdf_drop_key,
pdf_cmp_key,
- pdf_print_key,
+ pdf_format_key,
NULL
};