summaryrefslogtreecommitdiff
path: root/source/tools/mudraw.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2017-08-05 23:34:21 +0800
committerSebastian Rasmussen <sebras@gmail.com>2017-08-07 21:47:30 +0800
commit660242888b38de6207de0874c4ef42562a67c3f4 (patch)
treeda8d88644c242efa9fb1bf17bf49bf88cf4a42f6 /source/tools/mudraw.c
parent24fd32243ed51c1f79b5f9fce304c782fdd16a7d (diff)
downloadmupdf-660242888b38de6207de0874c4ef42562a67c3f4.tar.xz
tools: Move trace alloc info into callback argument.
Diffstat (limited to 'source/tools/mudraw.c')
-rw-r--r--source/tools/mudraw.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 24d2f2fe..17338307 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -227,9 +227,6 @@ static float min_line_width = 0.0f;
static int showfeatures = 0;
static int showtime = 0;
-static size_t memtrace_current = 0;
-static size_t memtrace_peak = 0;
-static size_t memtrace_total = 0;
static int showmemory = 0;
static int showmd5 = 0;
@@ -1177,9 +1174,17 @@ typedef struct
#endif
} trace_header;
+typedef struct
+{
+ size_t current;
+ size_t peak;
+ size_t total;
+} trace_info;
+
static void *
trace_malloc(void *arg, size_t size)
{
+ trace_info *info = (trace_info *) arg;
trace_header *p;
if (size == 0)
return NULL;
@@ -1187,27 +1192,29 @@ trace_malloc(void *arg, size_t size)
if (p == NULL)
return NULL;
p[0].size = size;
- memtrace_current += size;
- memtrace_total += size;
- if (memtrace_current > memtrace_peak)
- memtrace_peak = memtrace_current;
+ info->current += size;
+ info->total += size;
+ if (info->current > info->peak)
+ info->peak = info->current;
return (void *)&p[1];
}
static void
trace_free(void *arg, void *p_)
{
+ trace_info *info = (trace_info *) arg;
trace_header *p = (trace_header *)p_;
if (p == NULL)
return;
- memtrace_current -= p[-1].size;
+ info->current -= p[-1].size;
free(&p[-1]);
}
static void *
trace_realloc(void *arg, void *p_, size_t size)
{
+ trace_info *info = (trace_info *) arg;
trace_header *p = (trace_header *)p_;
size_t oldsize;
@@ -1222,11 +1229,11 @@ trace_realloc(void *arg, void *p_, size_t size)
p = realloc(&p[-1], size + sizeof(trace_header));
if (p == NULL)
return NULL;
- memtrace_current += size - oldsize;
+ info->current += size - oldsize;
if (size > oldsize)
- memtrace_total += size - oldsize;
- if (memtrace_current > memtrace_peak)
- memtrace_peak = memtrace_current;
+ info->total += size - oldsize;
+ if (info->current > info->peak)
+ info->peak = info->current;
p[0].size = size;
return &p[1];
}
@@ -1392,7 +1399,8 @@ int mudraw_main(int argc, char **argv)
fz_document *doc = NULL;
int c;
fz_context *ctx;
- fz_alloc_context alloc_ctx = { NULL, trace_malloc, trace_realloc, trace_free };
+ trace_info info = { 0, 0, 0 };
+ fz_alloc_context alloc_ctx = { &info, trace_malloc, trace_realloc, trace_free };
fz_locks_context *locks = NULL;
fz_colorspace *oi = NULL;
@@ -1870,9 +1878,9 @@ int mudraw_main(int argc, char **argv)
if (showmemory)
{
- fprintf(stderr, "Total memory use = " FZ_FMT_zu " bytes\n", memtrace_total);
- fprintf(stderr, "Peak memory use = " FZ_FMT_zu " bytes\n", memtrace_peak);
- fprintf(stderr, "Current memory use = " FZ_FMT_zu " bytes\n", memtrace_current);
+ fprintf(stderr, "Total memory use = " FZ_FMT_zu " bytes\n", info.total);
+ fprintf(stderr, "Peak memory use = " FZ_FMT_zu " bytes\n", info.peak);
+ fprintf(stderr, "Current memory use = " FZ_FMT_zu " bytes\n", info.current);
}
return (errored != 0);