Commit bf3721ae authored by Mao Huang's avatar Mao Huang Committed by Commit Bot

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: default avatarWill Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579581}
parent bf593d54
......@@ -228,6 +228,9 @@ extern "C" {
// 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 @@ bool GetUniquePathFromEnv(const char* env_name, char* path) {
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;
}
......
......@@ -461,7 +461,10 @@ bool HeapProfileTable::WriteProfile(const char* file_name,
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);
......
......@@ -231,8 +231,8 @@ static void DumpProfileLocked(const char* reason) {
// 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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment