summaryrefslogtreecommitdiff
path: root/source/fitz/track-usage.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-05-26 15:57:21 +0100
committerRobin Watts <robin.watts@artifex.com>2016-05-27 17:08:18 +0100
commitdba5c0206072986ae07111e4e62234bbc1156caa (patch)
tree4cb9f6841739a30cfa0c3124b1dd4ef09bfa7e9a /source/fitz/track-usage.c
parent0a4ebf51a9de8f2f1feddd9bb9ea78a5ed061a52 (diff)
downloadmupdf-dba5c0206072986ae07111e4e62234bbc1156caa.tar.xz
Add facility to track usage of functions.
Use this for plotters so we can see which ones are being used in any given build. Build with -DTRACK_USAGE to enable.
Diffstat (limited to 'source/fitz/track-usage.c')
-rw-r--r--source/fitz/track-usage.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/fitz/track-usage.c b/source/fitz/track-usage.c
new file mode 100644
index 00000000..f2d8af49
--- /dev/null
+++ b/source/fitz/track-usage.c
@@ -0,0 +1,34 @@
+#include "mupdf/fitz.h"
+
+#ifdef TRACK_USAGE
+
+static track_usage_data_t *usage_head = NULL;
+
+static void dump_usage(void)
+{
+ track_usage_data_t *u = usage_head;
+
+ while (u)
+ {
+ fprintf(stderr, "USAGE: %s (%s:%d) %d calls\n",
+ u->desc, u->function, u->line, u->count);
+ u = u->next;
+ }
+}
+
+void track_usage(track_usage_data_t *data, const char *function, int line, const char *desc)
+{
+ int c = data->count++;
+ if (c == 0)
+ {
+ data->function = function;
+ data->line = line;
+ data->desc = desc;
+ if (usage_head == NULL)
+ atexit(dump_usage);
+ data->next = usage_head;
+ usage_head = data;
+ }
+}
+
+#endif