summaryrefslogtreecommitdiffstats
path: root/jemalloc
diff options
context:
space:
mode:
authorJason Evans <je@facebook.com>2010-02-11 17:25:56 (GMT)
committerJason Evans <je@facebook.com>2010-02-11 17:25:56 (GMT)
commitc7177181154a5bdce61edbfe008741a7583c7203 (patch)
tree5caf9ffe9a9a9d3ad2016da2b7bd10425c75f474 /jemalloc
parent3383af6c2dcc23a423b395a1a17eba9b24ecb200 (diff)
downloadjemalloc-c7177181154a5bdce61edbfe008741a7583c7203.zip
jemalloc-c7177181154a5bdce61edbfe008741a7583c7203.tar.gz
jemalloc-c7177181154a5bdce61edbfe008741a7583c7203.tar.bz2
Dump /proc/<pid>/maps in heap profiles.
Diffstat (limited to 'jemalloc')
-rw-r--r--jemalloc/src/prof.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c
index 85b7020..f471c6a 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);
@@ -740,6 +741,54 @@ prof_dump_ctx(prof_ctx_t *ctx, prof_bt_t *bt)
}
static void
+prof_dump_maps(void)
+{
+ int mfd;
+ char buf[UMAX2S_BUFSIZE];
+ char *s;
+ unsigned i, slen;
+ /* /proc/<pid>/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)
{
prof_cnt_t cnt_all;
@@ -785,6 +834,9 @@ prof_dump(const char *filename, bool leakcheck)
prof_dump_ctx(ctx, bt);
}
+ /* Dump /proc/<pid>/maps if possible. */
+ prof_dump_maps();
+
prof_flush();
close(prof_dump_fd);
prof_leave();