dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 2/4] realloc
Date: Fri,  5 Apr 2024 21:05:02 +0000	[thread overview]
Message-ID: <20240405210504.3110367-2-e@80x24.org> (raw)
In-Reply-To: <20240405210504.3110367-1-e@80x24.org>

---
 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 <urcu/rculist.h>
 #include <urcu/wfcqueue.h>
 #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;
 }

  reply	other threads:[~2024-04-05 21:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 21:05 [PATCH 1/4] support malloc tracing Eric Wong
2024-04-05 21:05 ` Eric Wong [this message]
2024-04-05 21:05 ` [PATCH 3/4] gzip Eric Wong
2024-04-05 21:05 ` [PATCH 4/4] tracecompress Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240405210504.3110367-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).