summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2023-01-26 14:20:12 -0700
committerBehdad Esfahbod <behdad@behdad.org>2023-01-26 14:20:12 -0700
commit25b6775cc6eef8deea8c06b83a131c362efd8979 (patch)
treeef7bc2bf16b1d4ebf142dec0305ee3ad17e3676b /util
parent055ca7fb09842caa2595cf7864fa3afd417ebd37 (diff)
downloadcairo-25b6775cc6eef8deea8c06b83a131c362efd8979.tar.gz
[malloc-stats] Measure calloc
Diffstat (limited to 'util')
-rw-r--r--util/malloc-stats.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/util/malloc-stats.c b/util/malloc-stats.c
index eba0b2ac0..a086b0543 100644
--- a/util/malloc-stats.c
+++ b/util/malloc-stats.c
@@ -173,6 +173,7 @@ func_stats_add (const void *caller, int is_realloc, size_t size)
#include <dlfcn.h>
static void *(*old_malloc)(size_t);
+static void *(*old_calloc)(size_t, size_t);
static void *(*old_realloc)(void *, size_t);
static int enable_hook = 0;
@@ -195,6 +196,22 @@ malloc(size_t size)
}
void *
+calloc(size_t nmemb, size_t size)
+{
+ if (!old_calloc)
+ init ();
+
+ if (enable_hook) {
+ enable_hook = 0;
+ void *caller = __builtin_return_address(0);
+ func_stats_add (caller, 0, nmemb * size);
+ enable_hook = 1;
+ }
+
+ return old_calloc (nmemb, size);
+}
+
+void *
realloc(void *ptr, size_t size)
{
if (!old_malloc)
@@ -218,6 +235,11 @@ init(void)
fprintf(stderr, "%s\n", dlerror());
exit(1);
}
+ old_calloc = dlsym(RTLD_NEXT, "calloc");
+ if (!old_calloc) {
+ fprintf(stderr, "%s\n", dlerror());
+ exit(1);
+ }
old_realloc = dlsym(RTLD_NEXT, "realloc");
if (!old_realloc) {
fprintf(stderr, "%s\n", dlerror());