summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2015-05-01 16:03:20 (GMT)
committerJason Evans <jasone@canonware.com>2015-05-01 16:03:20 (GMT)
commit8e33c21d2d03ee7f540e32c3d75b10c128eaea57 (patch)
treee3b6394f9e6c753fd6e84ca29909d2f8be7d3e4d /src
parentf1f2b4542902c5bc14788f6c2d4190b422e5901f (diff)
downloadjemalloc-8e33c21d2d03ee7f540e32c3d75b10c128eaea57.zip
jemalloc-8e33c21d2d03ee7f540e32c3d75b10c128eaea57.tar.gz
jemalloc-8e33c21d2d03ee7f540e32c3d75b10c128eaea57.tar.bz2
Prefer /proc/<pid>/task/<pid>/maps over /proc/<pid>/maps on Linux.
This resolves #227.
Diffstat (limited to 'src')
-rw-r--r--src/prof.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/prof.c b/src/prof.c
index f2a3725..8453ea8 100644
--- a/src/prof.c
+++ b/src/prof.c
@@ -1338,21 +1338,40 @@ label_return:
return (ret);
}
+JEMALLOC_ATTR(format(printf, 1, 2))
+static int
+prof_open_maps(const char *format, ...)
+{
+ int mfd;
+ va_list ap;
+ char filename[PATH_MAX + 1];
+
+ va_start(ap, format);
+ malloc_vsnprintf(filename, sizeof(filename), format, ap);
+ va_end(ap);
+ mfd = open(filename, O_RDONLY);
+
+ return (mfd);
+}
+
static bool
prof_dump_maps(bool propagate_err)
{
bool ret;
int mfd;
- char filename[PATH_MAX + 1];
cassert(config_prof);
#ifdef __FreeBSD__
- malloc_snprintf(filename, sizeof(filename), "/proc/curproc/map");
+ mfd = prof_open_maps("/proc/curproc/map");
#else
- malloc_snprintf(filename, sizeof(filename), "/proc/%d/maps",
- (int)getpid());
+ {
+ int pid = getpid();
+
+ mfd = prof_open_maps("/proc/%d/task/%d/maps", pid, pid);
+ if (mfd == -1)
+ mfd = prof_open_maps("/proc/%d/maps", pid);
+ }
#endif
- mfd = open(filename, O_RDONLY);
if (mfd != -1) {
ssize_t nread;