From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C714E1F461 for ; Fri, 5 Apr 2024 21:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1712351104; bh=BKe7Ec2N1gDh+kCDulxD48FwjX3Srkb3G5X4L0HtdiM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jGZNZ7nHcWniMz9YOQ2t4/zjDrj4G9QD1QJXq1s92/4B/ObexjNVmDgmFKGtCazQp XAYXLhCS1t6UygJ6QX0+c+a576j1NAizYodHvByApAPGgLHuCxwPzPTTzP6z1fXhm1 /VtjGoPLncHZ/X4QwGI3QHv3kLcTDILZ2sVcHYwg= From: Eric Wong To: spew@80x24.org Subject: [PATCH 2/4] realloc Date: Fri, 5 Apr 2024 21:05:02 +0000 Message-ID: <20240405210504.3110367-2-e@80x24.org> In-Reply-To: <20240405210504.3110367-1-e@80x24.org> References: <20240405210504.3110367-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- lib/Devel/Mwrap/trace-replay.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/Devel/Mwrap/trace-replay.h b/lib/Devel/Mwrap/trace-replay.h index dfd443e..a2b0e50 100644 --- a/lib/Devel/Mwrap/trace-replay.h +++ b/lib/Devel/Mwrap/trace-replay.h @@ -25,13 +25,17 @@ #ifdef __GLIBC__ extern void __attribute__((weak)) malloc_stats(void); extern void __attribute__((weak)) malloc_info(int, FILE *); -# define MALLOC_STATS() do { \ - if (malloc_stats) malloc_stats(); \ +# define GLIBC_MALLOC_STATS() do { \ if (malloc_info) malloc_info(0, stderr); \ + if (malloc_stats) malloc_stats(); \ } while (0) -#else // TODO: jemalloc -# define MALLOC_STATS() do {} while (0) +#else +# define GLIBC_MALLOC_STATS() do {} while (0) #endif + +extern void __attribute__((weak)) malloc_stats_print( + void (*wcb)(void *, const char *), void *, const char *opts); + #include #include #include "dlmalloc_c.h" @@ -80,7 +84,6 @@ int main(int argc, char *argv[]) tr_ms->seg.sflags = EXTERN_BIT | USE_MMAP_BIT; disable_contiguous(tr_ms); size_t realloc_miss = 0, free_miss = 0, bad_entry = 0; - size_t realloc_hit = 0; union { struct tr_memalign do_memalign; struct tr_free do_free; @@ -160,9 +163,7 @@ int main(int argc, char *argv[]) if (k >= kh_end(old2cur)) { realloc_miss++; } else { - realloc_hit++; - cur = (void *) - kh_val(old2cur, k); + cur = (void *)kh_val(old2cur, k); ptrmap_del(old2cur, k); } } @@ -199,8 +200,11 @@ int main(int argc, char *argv[]) if (free_miss || realloc_miss || bad_entry) fprintf(stderr, "miss free=%zu realloc=%zu bad=%zu\n", free_miss, realloc_miss, bad_entry); - fprintf(stderr, "realloc_hit=%zu\n", realloc_hit); - MALLOC_STATS(); + + if (malloc_stats_print) // jemalloc loaded + malloc_stats_print(NULL, NULL, NULL); + else + GLIBC_MALLOC_STATS(); int c; char *end; @@ -226,7 +230,6 @@ int main(int argc, char *argv[]) (int)getpid(), s); sleep(s); } - fprintf(stderr, "truncated=%d\n", truncated); return truncated; }