diff options
-rw-r--r-- | third_party/tcmalloc/chromium/src/deep-heap-profile.cc | 80 | ||||
-rw-r--r-- | third_party/tcmalloc/chromium/src/deep-heap-profile.h | 18 | ||||
-rw-r--r-- | third_party/tcmalloc/chromium/src/heap-profiler.cc | 8 | ||||
-rw-r--r-- | tools/deep_memory_profiler/dmprof.py | 2 |
4 files changed, 68 insertions, 40 deletions
diff --git a/third_party/tcmalloc/chromium/src/deep-heap-profile.cc b/third_party/tcmalloc/chromium/src/deep-heap-profile.cc index f89d8ce..b5d4821 100644 --- a/third_party/tcmalloc/chromium/src/deep-heap-profile.cc +++ b/third_party/tcmalloc/chromium/src/deep-heap-profile.cc @@ -229,7 +229,9 @@ DeepHeapProfile::~DeepHeapProfile() { // Global malloc() should not be used in this function. // Use LowLevelAlloc if required. -int DeepHeapProfile::FillOrderedProfile(char raw_buffer[], int buffer_size) { +int DeepHeapProfile::FillOrderedProfile(const char* reason, + char raw_buffer[], + int buffer_size) { TextBuffer buffer(raw_buffer, buffer_size); TextBuffer global_buffer(profiler_buffer_, kProfilerBufferSize); @@ -275,6 +277,12 @@ int DeepHeapProfile::FillOrderedProfile(char raw_buffer[], int buffer_size) { buffer.AppendUnsignedLong(time_value, 0); buffer.AppendChar('\n'); + if (reason != NULL) { + buffer.AppendString("Reason: ", 0); + buffer.AppendString(reason, 0); + buffer.AppendChar('\n'); + } + // Fill buffer with the global stats. buffer.AppendString(kMMapListHeader, 0); @@ -325,63 +333,79 @@ void DeepHeapProfile::TextBuffer::Write(RawFD fd) { } // TODO(dmikurube): These Append* functions should not use snprintf. -bool DeepHeapProfile::TextBuffer::AppendChar(char v) { - return ForwardCursor(snprintf(buffer_ + cursor_, size_ - cursor_, "%c", v)); +bool DeepHeapProfile::TextBuffer::AppendChar(char value) { + return ForwardCursor(snprintf(buffer_ + cursor_, size_ - cursor_, + "%c", value)); } -bool DeepHeapProfile::TextBuffer::AppendString(const char* s, int d) { +bool DeepHeapProfile::TextBuffer::AppendString(const char* value, int width) { + char* position = buffer_ + cursor_; + int available = size_ - cursor_; int appended; - if (d == 0) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%s", s); + if (width == 0) + appended = snprintf(position, available, "%s", value); else - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%*s", d, s); + appended = snprintf(position, available, "%*s", + width, value); return ForwardCursor(appended); } -bool DeepHeapProfile::TextBuffer::AppendInt(int v, int d, bool leading_zero) { +bool DeepHeapProfile::TextBuffer::AppendInt(int value, int width, + bool leading_zero) { + char* position = buffer_ + cursor_; + int available = size_ - cursor_; int appended; - if (d == 0) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%d", v); + if (width == 0) + appended = snprintf(position, available, "%d", value); else if (leading_zero) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%0*d", d, v); + appended = snprintf(position, available, "%0*d", width, value); else - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%*d", d, v); + appended = snprintf(position, available, "%*d", width, value); return ForwardCursor(appended); } -bool DeepHeapProfile::TextBuffer::AppendLong(long v, int d) { +bool DeepHeapProfile::TextBuffer::AppendLong(long value, int width) { + char* position = buffer_ + cursor_; + int available = size_ - cursor_; int appended; - if (d == 0) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%ld", v); + if (width == 0) + appended = snprintf(position, available, "%ld", value); else - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%*ld", d, v); + appended = snprintf(position, available, "%*ld", width, value); return ForwardCursor(appended); } -bool DeepHeapProfile::TextBuffer::AppendUnsignedLong(unsigned long v, int d) { +bool DeepHeapProfile::TextBuffer::AppendUnsignedLong(unsigned long value, + int width) { + char* position = buffer_ + cursor_; + int available = size_ - cursor_; int appended; - if (d == 0) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%lu", v); + if (width == 0) + appended = snprintf(position, available, "%lu", value); else - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%*lu", d, v); + appended = snprintf(position, available, "%*lu", width, value); return ForwardCursor(appended); } -bool DeepHeapProfile::TextBuffer::AppendInt64(int64 v, int d) { +bool DeepHeapProfile::TextBuffer::AppendInt64(int64 value, int width) { + char* position = buffer_ + cursor_; + int available = size_ - cursor_; int appended; - if (d == 0) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%"PRId64, v); + if (width == 0) + appended = snprintf(position, available, "%"PRId64, value); else - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%*"PRId64, d, v); + appended = snprintf(position, available, "%*"PRId64, width, value); return ForwardCursor(appended); } -bool DeepHeapProfile::TextBuffer::AppendPtr(uint64 v, int d) { +bool DeepHeapProfile::TextBuffer::AppendPtr(uint64 value, int width) { + char* position = buffer_ + cursor_; + int available = size_ - cursor_; int appended; - if (d == 0) - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%"PRIx64, v); + if (width == 0) + appended = snprintf(position, available, "%"PRIx64, value); else - appended = snprintf(buffer_ + cursor_, size_ - cursor_, "%0*"PRIx64, d, v); + appended = snprintf(position, available, "%0*"PRIx64, width, value); return ForwardCursor(appended); } diff --git a/third_party/tcmalloc/chromium/src/deep-heap-profile.h b/third_party/tcmalloc/chromium/src/deep-heap-profile.h index 7cf95fd..4a943a1 100644 --- a/third_party/tcmalloc/chromium/src/deep-heap-profile.h +++ b/third_party/tcmalloc/chromium/src/deep-heap-profile.h @@ -83,7 +83,9 @@ class DeepHeapProfile { // // In addition, a list of buckets is dumped into a ".buckets" file in // descending order of allocated bytes. - int FillOrderedProfile(char raw_buffer[], int buffer_size); + int FillOrderedProfile(const char* reason, + char raw_buffer[], + int buffer_size); private: #ifdef USE_DEEP_HEAP_PROFILE @@ -134,13 +136,13 @@ class DeepHeapProfile { void Clear(); void Write(RawFD fd); - bool AppendChar(char v); - bool AppendString(const char* v, int d); - bool AppendInt(int v, int d, bool leading_zero); - bool AppendLong(long v, int d); - bool AppendUnsignedLong(unsigned long v, int d); - bool AppendInt64(int64 v, int d); - bool AppendPtr(uint64 v, int d); + bool AppendChar(char value); + bool AppendString(const char* value, int width); + bool AppendInt(int value, int width, bool leading_zero); + bool AppendLong(long value, int width); + bool AppendUnsignedLong(unsigned long value, int width); + bool AppendInt64(int64 value, int width); + bool AppendPtr(uint64 value, int width); private: bool ForwardCursor(int appended); diff --git a/third_party/tcmalloc/chromium/src/heap-profiler.cc b/third_party/tcmalloc/chromium/src/heap-profiler.cc index 67cb31e..e08b0fc 100644 --- a/third_party/tcmalloc/chromium/src/heap-profiler.cc +++ b/third_party/tcmalloc/chromium/src/heap-profiler.cc @@ -225,7 +225,7 @@ static DeepHeapProfile* deep_profile = NULL; // deep memory profiler //---------------------------------------------------------------------- // Input must be a buffer of size at least 1MB. -static char* DoGetHeapProfileLocked(char* buf, int buflen) { +static char* DoGetHeapProfileLocked(const char* reason, char* buf, int buflen) { // We used to be smarter about estimating the required memory and // then capping it to 1MB and generating the profile into that. if (buf == NULL || buflen < 1) @@ -237,7 +237,7 @@ static char* DoGetHeapProfileLocked(char* buf, int buflen) { HeapProfileTable::Stats const stats = heap_profile->total(); (void)stats; // avoid an unused-variable warning in non-debug mode. if (deep_profile) { - bytes_written = deep_profile->FillOrderedProfile(buf, buflen - 1); + bytes_written = deep_profile->FillOrderedProfile(reason, buf, buflen - 1); } else { bytes_written = heap_profile->FillOrderedProfile(buf, buflen - 1); } @@ -257,7 +257,7 @@ extern "C" char* GetHeapProfile() { // Use normal malloc: we return the profile to the user to free it: char* buffer = reinterpret_cast<char*>(malloc(kProfileBufferSize)); SpinLockHolder l(&heap_lock); - return DoGetHeapProfileLocked(buffer, kProfileBufferSize); + return DoGetHeapProfileLocked(/* reason */ NULL, buffer, kProfileBufferSize); } // defined below @@ -298,7 +298,7 @@ static void DumpProfileLocked(const char* reason) { reinterpret_cast<char*>(ProfilerMalloc(kProfileBufferSize)); } - char* profile = DoGetHeapProfileLocked(global_profiler_buffer, + char* profile = DoGetHeapProfileLocked(reason, global_profiler_buffer, kProfileBufferSize); RawWrite(fd, profile, strlen(profile)); RawClose(fd); diff --git a/tools/deep_memory_profiler/dmprof.py b/tools/deep_memory_profiler/dmprof.py index 8327f96..af32bfa 100644 --- a/tools/deep_memory_profiler/dmprof.py +++ b/tools/deep_memory_profiler/dmprof.py @@ -944,6 +944,8 @@ class Dump(object): self._time += float(matched_format.group(2)[1:]) / 1000.0 elif matched_seconds: self._time = float(matched_seconds.group(1)) + elif self._lines[ln].startswith('Reason:'): + pass # Nothing to do for 'Reason:' else: break ln += 1 |