From 768e4ff6892503dfbff4d06e7098e751dd28e85b Mon Sep 17 00:00:00 2001 From: "stevenjb@google.com" Date: Thu, 11 Aug 2011 20:29:35 +0000 Subject: Enable tcmalloc profiling and heap dump. BUG=chromium-os:18876 TEST=See issue. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=96054 Review URL: http://codereview.chromium.org/7528016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96444 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/chrome_render_process_observer.cc | 39 +++++++++++++++++++++-- chrome/renderer/chrome_render_process_observer.h | 3 ++ 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'chrome/renderer') diff --git a/chrome/renderer/chrome_render_process_observer.cc b/chrome/renderer/chrome_render_process_observer.cc index 7805e7b..e36dc8d 100644 --- a/chrome/renderer/chrome_render_process_observer.cc +++ b/chrome/renderer/chrome_render_process_observer.cc @@ -33,6 +33,7 @@ #include "net/base/net_module.h" #include "third_party/sqlite/sqlite3.h" #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" +#include "third_party/tcmalloc/chromium/src/google/heap-profiler.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h" @@ -407,6 +408,10 @@ bool ChromeRenderProcessObserver::OnControlMessageReceived( IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) #if defined(USE_TCMALLOC) IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) + IPC_MESSAGE_HANDLER(ViewMsg_SetTcmallocHeapProfiling, + OnSetTcmallocHeapProfiling) + IPC_MESSAGE_HANDLER(ViewMsg_WriteTcmallocHeapProfile, + OnWriteTcmallocHeapProfile) #endif IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) @@ -458,11 +463,41 @@ void ChromeRenderProcessObserver::OnGetCacheResourceStats() { void ChromeRenderProcessObserver::OnGetRendererTcmalloc() { std::string result; char buffer[1024 * 32]; - base::ProcessId pid = base::GetCurrentProcId(); MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); result.append(buffer); - Send(new ViewHostMsg_RendererTcmalloc(pid, result)); + Send(new ViewHostMsg_RendererTcmalloc(result)); } + +void ChromeRenderProcessObserver::OnSetTcmallocHeapProfiling( + bool profiling, const std::string& filename_prefix) { +#if !defined(OS_WIN) + // TODO(stevenjb): Create MallocExtension wrappers for HeapProfile functions. + if (profiling) + HeapProfilerStart(filename_prefix.c_str()); + else + HeapProfilerStop(); +#endif +} + +void ChromeRenderProcessObserver::OnWriteTcmallocHeapProfile( + const FilePath::StringType& filename) { +#if !defined(OS_WIN) + // TODO(stevenjb): Create MallocExtension wrappers for HeapProfile functions. + if (!IsHeapProfilerRunning()) + return; + char* profile = GetHeapProfile(); + if (!profile) { + LOG(WARNING) << "Unable to get heap profile."; + return; + } + // The render process can not write to a file, so copy the result into + // a string and pass it to the handler (which runs on the browser host). + std::string result(profile); + delete profile; + Send(new ViewHostMsg_WriteTcmallocHeapProfile_ACK(filename, result)); +#endif +} + #endif void ChromeRenderProcessObserver::OnSetFieldTrialGroup( diff --git a/chrome/renderer/chrome_render_process_observer.h b/chrome/renderer/chrome_render_process_observer.h index 9361290..80bf18ef 100644 --- a/chrome/renderer/chrome_render_process_observer.h +++ b/chrome/renderer/chrome_render_process_observer.h @@ -9,6 +9,7 @@ #include #include "base/compiler_specific.h" +#include "base/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/renderer/render_process_observer.h" @@ -49,6 +50,8 @@ class ChromeRenderProcessObserver : public RenderProcessObserver { void OnSetFieldTrialGroup(const std::string& fiel_trial_name, const std::string& group_name); void OnGetRendererTcmalloc(); + void OnSetTcmallocHeapProfiling(bool profiling, const std::string& prefix); + void OnWriteTcmallocHeapProfile(const FilePath::StringType& filename); void OnGetV8HeapStats(); void OnPurgeMemory(); -- cgit v1.1