Extract utility function for opening maps file

This commit is contained in:
Yinan Zhang 2020-03-17 19:46:18 -07:00
parent f307b25804
commit 4bb4037dbe

View File

@ -919,7 +919,7 @@ label_return:
#ifndef _WIN32 #ifndef _WIN32
JEMALLOC_FORMAT_PRINTF(1, 2) JEMALLOC_FORMAT_PRINTF(1, 2)
static int static int
prof_open_maps(const char *format, ...) { prof_open_maps_internal(const char *format, ...) {
int mfd; int mfd;
va_list ap; va_list ap;
char filename[PATH_MAX + 1]; char filename[PATH_MAX + 1];
@ -941,26 +941,31 @@ prof_open_maps(const char *format, ...) {
} }
#endif #endif
static bool static int
prof_dump_maps(bool propagate_err) { prof_dump_open_maps() {
bool ret;
int mfd; int mfd;
cassert(config_prof); cassert(config_prof);
#ifdef __FreeBSD__ #ifdef __FreeBSD__
mfd = prof_open_maps("/proc/curproc/map"); mfd = prof_open_maps_internal("/proc/curproc/map");
#elif defined(_WIN32) #elif defined(_WIN32)
mfd = -1; // Not implemented mfd = -1; // Not implemented
#else #else
{
int pid = prof_getpid(); int pid = prof_getpid();
mfd = prof_open_maps("/proc/%d/task/%d/maps", pid, pid); mfd = prof_open_maps_internal("/proc/%d/task/%d/maps", pid, pid);
if (mfd == -1) { if (mfd == -1) {
mfd = prof_open_maps("/proc/%d/maps", pid); mfd = prof_open_maps_internal("/proc/%d/maps", pid);
}
} }
#endif #endif
return mfd;
}
static bool
prof_dump_maps(bool propagate_err) {
bool ret;
int mfd = prof_dump_open_maps();
if (mfd != -1) { if (mfd != -1) {
ssize_t nread; ssize_t nread;