tcmalloc: fix heap profiler to always append the process id to the heap
dump.
Original CLs:
- http://codereview.chromium.org/6532051
Fix heap profiler to always append the process id to the heap dump.
To run Chrome:
HEAP_PROFILE_ALLOCATION_INTERVAL=1000000 HEAPPROFILE=heapprof
out/Debug/chrome
To analyze:
pprof --text out/Debug/chrome heapprof.21026.0039.heap
pprof --gv out/Debug/chrome heapprof.21026.0039.heap
(pprof is slooow)
Committed:
http://src.chromium.org/viewvc/chrome?view=rev&revision=86273
- https://codereview.chromium.org/8957007
Change the heap file names to be Cleanup'ed in
third_party/tcmalloc/chromium.
In spite of Chromium's changing heap file names dumped in
heap-profiler.cc:DumpProfileLocked(), the file names cleaned-up in
heap-profile-table.cc:HeapProfileTable::CleanupOldProfiles are not
modified.
(See the difference between
third_party/tcmalloc/chromium/src/heap-profiler.cc and
.../vendor/src/heap-profiler.cc)
This patch is originally from http://codereview.chromium.org/7865021/.
BUG=none
TEST=none
Committed:
http://src.chromium.org/viewvc/chrome?view=rev&revision=114777
BUG=724399,b:70905156
Change-Id: Iab590a6a34f3e3922b0958460169e517accef7df
Reviewed-on: https://chromium-review.googlesource.com/1130782
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#579581}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: bf3721aec76107e6b45c766a025fbd0da99946dd
diff --git a/src/base/sysinfo.cc b/src/base/sysinfo.cc
index 36f7067..ceb8e43 100644
--- a/src/base/sysinfo.cc
+++ b/src/base/sysinfo.cc
@@ -228,6 +228,9 @@
// in their first character! If that assumption is violated, we'll
// still get a profile, but one with an unexpected name.
// TODO(csilvers): set an envvar instead when we can do it reliably.
+//
+// In Chromium this hack is intentionally disabled, because the path is not
+// re-initialized upon fork.
bool GetUniquePathFromEnv(const char* env_name, char* path) {
char* envval = getenv(env_name);
if (envval == NULL || *envval == '\0')
@@ -237,7 +240,9 @@
envval[0] & 127, envval+1, (unsigned int)(getpid()));
} else {
snprintf(path, PATH_MAX, "%s", envval);
+#if 0
envval[0] |= 128; // set high bit for kids to see
+#endif
}
return true;
}
diff --git a/src/heap-profile-table.cc b/src/heap-profile-table.cc
index 7486468..238d041 100644
--- a/src/heap-profile-table.cc
+++ b/src/heap-profile-table.cc
@@ -461,7 +461,10 @@
void HeapProfileTable::CleanupOldProfiles(const char* prefix) {
if (!FLAGS_cleanup_old_heap_profiles)
return;
- string pattern = string(prefix) + ".*" + kFileExt;
+ char buf[1000];
+ snprintf(buf, 1000,"%s.%05d.", prefix, getpid());
+ string pattern = string(buf) + ".*" + kFileExt;
+
#if defined(HAVE_GLOB_H)
glob_t g;
const int r = glob(pattern.c_str(), GLOB_ERR, NULL, &g);
diff --git a/src/heap-profiler.cc b/src/heap-profiler.cc
index 33a25ac..b037f62 100755
--- a/src/heap-profiler.cc
+++ b/src/heap-profiler.cc
@@ -231,8 +231,8 @@
// Make file name
char file_name[1000];
dump_count++;
- snprintf(file_name, sizeof(file_name), "%s.%04d%s",
- filename_prefix, dump_count, HeapProfileTable::kFileExt);
+ snprintf(file_name, sizeof(file_name), "%s.%05d.%04d%s",
+ filename_prefix, getpid(), dump_count, HeapProfileTable::kFileExt);
// Dump the profile
RAW_VLOG(0, "Dumping heap profile to %s (%s)", file_name, reason);