From c7177181154a5bdce61edbfe008741a7583c7203 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Thu, 11 Feb 2010 09:25:56 -0800 Subject: [PATCH] Dump /proc//maps in heap profiles. --- jemalloc/src/prof.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c index 85b70203..f471c6a1 100644 --- a/jemalloc/src/prof.c +++ b/jemalloc/src/prof.c @@ -100,6 +100,7 @@ static void prof_write(const char *s); static void prof_ctx_merge(prof_ctx_t *ctx, prof_cnt_t *cnt_all, size_t *leak_nctx); static void prof_dump_ctx(prof_ctx_t *ctx, prof_bt_t *bt); +static void prof_dump_maps(void); static void prof_dump(const char *filename, bool leakcheck); static void prof_dump_filename(char *filename, char v, int64_t vseq); static void prof_fdump(void); @@ -739,6 +740,54 @@ prof_dump_ctx(prof_ctx_t *ctx, prof_bt_t *bt) prof_write("\n"); } +static void +prof_dump_maps(void) +{ + int mfd; + char buf[UMAX2S_BUFSIZE]; + char *s; + unsigned i, slen; + /* /proc//maps\0 */ + char mpath[6 + UMAX2S_BUFSIZE + + 5 + 1]; + + i = 0; + + s = "/proc/"; + slen = strlen(s); + memcpy(&mpath[i], s, slen); + i += slen; + + s = umax2s(getpid(), 10, buf); + slen = strlen(s); + memcpy(&mpath[i], s, slen); + i += slen; + + s = "/maps"; + slen = strlen(s); + memcpy(&mpath[i], s, slen); + i += slen; + + mpath[i] = '\0'; + + mfd = open(mpath, O_RDONLY); + if (mfd != -1) { + ssize_t nread; + + prof_write("\nMAPPED_LIBRARIES:\n"); + nread = 0; + do { + prof_dump_buf_end += nread; + if (prof_dump_buf_end == PROF_DUMP_BUF_SIZE) { + /* Make space in prof_dump_buf before read(). */ + prof_flush(); + } + nread = read(mfd, &prof_dump_buf[prof_dump_buf_end], + PROF_DUMP_BUF_SIZE - prof_dump_buf_end); + } while (nread > 0); + } +} + static void prof_dump(const char *filename, bool leakcheck) { @@ -785,6 +834,9 @@ prof_dump(const char *filename, bool leakcheck) prof_dump_ctx(ctx, bt); } + /* Dump /proc//maps if possible. */ + prof_dump_maps(); + prof_flush(); close(prof_dump_fd); prof_leave();