Commit f2c2b3c3 authored by fischman@chromium.org's avatar fischman@chromium.org

Revert 96054 - Enable tcmalloc profiling and heap dump.

BUG=chromium-os:18876
TEST=See issue.

Review URL: http://codereview.chromium.org/7528016

TBR=stevenjb@google.com
Review URL: http://codereview.chromium.org/7607009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96065 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b121768
...@@ -4,25 +4,14 @@ ...@@ -4,25 +4,14 @@
#include "chrome/browser/chromeos/status/memory_menu_button.h" #include "chrome/browser/chromeos/status/memory_menu_button.h"
#include "base/file_util.h"
#include "base/process_util.h" // GetSystemMemoryInfo #include "base/process_util.h" // GetSystemMemoryInfo
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "chrome/browser/chromeos/status/status_area_host.h" #include "chrome/browser/chromeos/status/status_area_host.h"
#include "chrome/browser/memory_purger.h" #include "chrome/browser/memory_purger.h"
#include "chrome/common/render_messages.h"
#include "content/browser/renderer_host/render_process_host.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "views/widget/widget.h" #include "views/widget/widget.h"
#if defined(USE_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/google/heap-profiler.h"
#endif
#if defined(USE_TCMALLOC)
const char kProfileDumpFilePrefix[] = "/tmp/chrome_tcmalloc";
#endif
namespace { namespace {
// views::MenuItemView item ids // views::MenuItemView item ids
...@@ -33,10 +22,6 @@ enum { ...@@ -33,10 +22,6 @@ enum {
MEM_CACHE_ITEM, MEM_CACHE_ITEM,
SHMEM_ITEM, SHMEM_ITEM,
PURGE_MEMORY_ITEM, PURGE_MEMORY_ITEM,
#if defined(USE_TCMALLOC)
TOGGLE_PROFILING_ITEM,
DUMP_PROFILING_ITEM,
#endif
}; };
} // namespace } // namespace
...@@ -97,15 +82,6 @@ std::wstring MemoryMenuButton::GetLabel(int id) const { ...@@ -97,15 +82,6 @@ std::wstring MemoryMenuButton::GetLabel(int id) const {
return StringPrintf(L"%d MB shmem", shmem_ / 1024); return StringPrintf(L"%d MB shmem", shmem_ / 1024);
case PURGE_MEMORY_ITEM: case PURGE_MEMORY_ITEM:
return L"Purge memory"; return L"Purge memory";
#if defined(USE_TCMALLOC)
case TOGGLE_PROFILING_ITEM:
if (!IsHeapProfilerRunning())
return L"Start profiling";
else
return L"Stop profiling";
case DUMP_PROFILING_ITEM:
return L"Dump profile";
#endif
default: default:
return std::wstring(); return std::wstring();
} }
...@@ -115,76 +91,16 @@ bool MemoryMenuButton::IsCommandEnabled(int id) const { ...@@ -115,76 +91,16 @@ bool MemoryMenuButton::IsCommandEnabled(int id) const {
switch (id) { switch (id) {
case PURGE_MEMORY_ITEM: case PURGE_MEMORY_ITEM:
return true; return true;
#if defined(USE_TCMALLOC)
case TOGGLE_PROFILING_ITEM:
case DUMP_PROFILING_ITEM:
return true;
#endif
default: default:
return false; return false;
} }
} }
namespace {
FilePath::StringType GetFilePath(base::ProcessId pid) {
int int_pid = static_cast<int>(pid);
FilePath::StringType filepath = StringPrintf(
FILE_PATH_LITERAL("%s.%d.heap"),
FILE_PATH_LITERAL(kProfileDumpFilePrefix), int_pid);
return filepath;
}
}
void MemoryMenuButton::SendCommandToRenderers(int id) {
#if defined(USE_TCMALLOC)
// Use the "is running" value for this process to determine whether to
// start or stop profiling on the renderer processes.
bool started = IsHeapProfilerRunning();
for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
!it.IsAtEnd(); it.Advance()) {
switch (id) {
case TOGGLE_PROFILING_ITEM:
it.GetCurrentValue()->Send(new ViewMsg_SetTcmallocHeapProfiling(
started, std::string(kProfileDumpFilePrefix)));
break;
case DUMP_PROFILING_ITEM:
it.GetCurrentValue()->Send(new ViewMsg_WriteTcmallocHeapProfile(
GetFilePath(base::GetProcId(it.GetCurrentValue()->GetHandle()))));
break;
default:
NOTREACHED();
}
}
#endif
}
void MemoryMenuButton::ExecuteCommand(int id) { void MemoryMenuButton::ExecuteCommand(int id) {
switch (id) { switch (id) {
case PURGE_MEMORY_ITEM: case PURGE_MEMORY_ITEM:
MemoryPurger::PurgeAll(); MemoryPurger::PurgeAll();
break; break;
#if defined(USE_TCMALLOC)
case TOGGLE_PROFILING_ITEM: {
if (!IsHeapProfilerRunning())
HeapProfilerStart(kProfileDumpFilePrefix);
else
HeapProfilerStop();
SendCommandToRenderers(id);
break;
}
case DUMP_PROFILING_ITEM: {
char* profile = GetHeapProfile();
if (profile) {
FilePath::StringType filepath =
GetFilePath(base::GetProcId(base::GetCurrentProcId()));
VLOG(0) << "Writing browser heap profile dump to: " << filepath;
file_util::WriteFile(FilePath(filepath), profile, strlen(profile));
delete profile;
}
SendCommandToRenderers(id);
break;
}
#endif
default: default:
NOTREACHED(); NOTREACHED();
break; break;
...@@ -225,14 +141,9 @@ void MemoryMenuButton::EnsureMenu() { ...@@ -225,14 +141,9 @@ void MemoryMenuButton::EnsureMenu() {
menu_->AppendDelegateMenuItem(MEM_BUFFERS_ITEM); menu_->AppendDelegateMenuItem(MEM_BUFFERS_ITEM);
menu_->AppendDelegateMenuItem(MEM_CACHE_ITEM); menu_->AppendDelegateMenuItem(MEM_CACHE_ITEM);
menu_->AppendDelegateMenuItem(SHMEM_ITEM); menu_->AppendDelegateMenuItem(SHMEM_ITEM);
// TODO(jamescook): Dump heap profiles?
menu_->AppendSeparator(); menu_->AppendSeparator();
menu_->AppendDelegateMenuItem(PURGE_MEMORY_ITEM); menu_->AppendDelegateMenuItem(PURGE_MEMORY_ITEM);
#if defined(USE_TCMALLOC)
menu_->AppendSeparator();
menu_->AppendDelegateMenuItem(TOGGLE_PROFILING_ITEM);
if (IsHeapProfilerRunning())
menu_->AppendDelegateMenuItem(DUMP_PROFILING_ITEM);
#endif
} }
} // namespace chromeos } // namespace chromeos
...@@ -43,9 +43,6 @@ class MemoryMenuButton : public StatusAreaButton, ...@@ -43,9 +43,6 @@ class MemoryMenuButton : public StatusAreaButton,
// views::ViewMenuDelegate implementation. // views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt); virtual void RunMenu(views::View* source, const gfx::Point& pt);
// Execute command id for each renderer. Used for heap profiling.
void SendCommandToRenderers(int id);
// Create and initialize menu if not already present. // Create and initialize menu if not already present.
void EnsureMenu(); void EnsureMenu();
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "chrome/browser/renderer_host/chrome_render_message_filter.h" #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
#include "base/file_util.h" #include "base/file_path.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "chrome/browser/automation/automation_resource_message_filter.h" #include "chrome/browser/automation/automation_resource_message_filter.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
...@@ -121,8 +121,6 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message, ...@@ -121,8 +121,6 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message,
OnExtensionRequestForIOThread) OnExtensionRequestForIOThread)
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
IPC_MESSAGE_HANDLER(ViewHostMsg_RendererTcmalloc, OnRendererTcmalloc) IPC_MESSAGE_HANDLER(ViewHostMsg_RendererTcmalloc, OnRendererTcmalloc)
IPC_MESSAGE_HANDLER(ViewHostMsg_WriteTcmallocHeapProfile_ACK,
OnWriteTcmallocHeapProfile)
#endif #endif
IPC_MESSAGE_HANDLER(ViewHostMsg_GetPluginPolicies, OnGetPluginPolicies) IPC_MESSAGE_HANDLER(ViewHostMsg_GetPluginPolicies, OnGetPluginPolicies)
IPC_MESSAGE_HANDLER(ViewHostMsg_AllowDatabase, OnAllowDatabase) IPC_MESSAGE_HANDLER(ViewHostMsg_AllowDatabase, OnAllowDatabase)
...@@ -386,17 +384,10 @@ void ChromeRenderMessageFilter::OnExtensionRequestForIOThread( ...@@ -386,17 +384,10 @@ void ChromeRenderMessageFilter::OnExtensionRequestForIOThread(
} }
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
void ChromeRenderMessageFilter::OnRendererTcmalloc(const std::string& output) { void ChromeRenderMessageFilter::OnRendererTcmalloc(base::ProcessId pid,
base::ProcessId pid = base::GetProcId(peer_handle()); const std::string& output) {
AboutTcmallocRendererCallback(pid, output); AboutTcmallocRendererCallback(pid, output);
} }
void ChromeRenderMessageFilter::OnWriteTcmallocHeapProfile(
const FilePath::StringType& filepath,
const std::string& output) {
VLOG(0) << "Writing renderer heap profile dump to: " << filepath;
file_util::WriteFile(FilePath(filepath), output.c_str(), output.size());
}
#endif #endif
void ChromeRenderMessageFilter::OnGetPluginPolicies( void ChromeRenderMessageFilter::OnGetPluginPolicies(
......
...@@ -88,9 +88,7 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter { ...@@ -88,9 +88,7 @@ class ChromeRenderMessageFilter : public BrowserMessageFilter {
int routing_id, int routing_id,
const ExtensionHostMsg_Request_Params& params); const ExtensionHostMsg_Request_Params& params);
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
void OnRendererTcmalloc(const std::string& output); void OnRendererTcmalloc(base::ProcessId pid, const std::string& output);
void OnWriteTcmallocHeapProfile(const FilePath::StringType& filename,
const std::string& output);
#endif #endif
void OnGetPluginPolicies(ContentSetting* outdated_policy, void OnGetPluginPolicies(ContentSetting* outdated_policy,
ContentSetting* authorize_policy); ContentSetting* authorize_policy);
......
...@@ -211,16 +211,6 @@ IPC_MESSAGE_CONTROL2(ViewMsg_SetFieldTrialGroup, ...@@ -211,16 +211,6 @@ IPC_MESSAGE_CONTROL2(ViewMsg_SetFieldTrialGroup,
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
// Asks the renderer to send back tcmalloc stats. // Asks the renderer to send back tcmalloc stats.
IPC_MESSAGE_CONTROL0(ViewMsg_GetRendererTcmalloc) IPC_MESSAGE_CONTROL0(ViewMsg_GetRendererTcmalloc)
// Asks the renderer to enable/disable Tcmalloc heap profiling.
// Note: filename_prefix arg is effectively ignored since the render process
// will be unable to write files to disk. Instead use WriteTcmallocHeapProfile
// to write a profile file.
IPC_MESSAGE_CONTROL2(ViewMsg_SetTcmallocHeapProfiling,
bool /* enable profiling */,
std::string /* filename prefix for profiles */)
// Asks the renderer to write the Tcmalloc heap profile to a file.
IPC_MESSAGE_CONTROL1(ViewMsg_WriteTcmallocHeapProfile,
FilePath::StringType /* filepath */)
#endif #endif
// Asks the renderer to send back V8 heap stats. // Asks the renderer to send back V8 heap stats.
...@@ -424,12 +414,9 @@ IPC_MESSAGE_CONTROL2(ViewHostMsg_RendererHistograms, ...@@ -424,12 +414,9 @@ IPC_MESSAGE_CONTROL2(ViewHostMsg_RendererHistograms,
#if defined USE_TCMALLOC #if defined USE_TCMALLOC
// Send back tcmalloc stats output. // Send back tcmalloc stats output.
IPC_MESSAGE_CONTROL1(ViewHostMsg_RendererTcmalloc, IPC_MESSAGE_CONTROL2(ViewHostMsg_RendererTcmalloc,
int /* pid */,
std::string /* tcmalloc debug output */) std::string /* tcmalloc debug output */)
// Send back tcmalloc profile to write to a file.
IPC_MESSAGE_CONTROL2(ViewHostMsg_WriteTcmallocHeapProfile_ACK,
FilePath::StringType /* filepath */,
std::string /* heap profile */)
#endif #endif
// Sends back stats about the V8 heap. // Sends back stats about the V8 heap.
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "net/base/net_module.h" #include "net/base/net_module.h"
#include "third_party/sqlite/sqlite3.h" #include "third_party/sqlite/sqlite3.h"
#include "third_party/tcmalloc/chromium/src/google/malloc_extension.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/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflightResultCache.h"
...@@ -408,10 +407,6 @@ bool ChromeRenderProcessObserver::OnControlMessageReceived( ...@@ -408,10 +407,6 @@ bool ChromeRenderProcessObserver::OnControlMessageReceived(
IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup)
#if defined(USE_TCMALLOC) #if defined(USE_TCMALLOC)
IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc)
IPC_MESSAGE_HANDLER(ViewMsg_SetTcmallocHeapProfiling,
OnSetTcmallocHeapProfiling)
IPC_MESSAGE_HANDLER(ViewMsg_WriteTcmallocHeapProfile,
OnWriteTcmallocHeapProfile)
#endif #endif
IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats)
IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats)
...@@ -463,35 +458,11 @@ void ChromeRenderProcessObserver::OnGetCacheResourceStats() { ...@@ -463,35 +458,11 @@ void ChromeRenderProcessObserver::OnGetCacheResourceStats() {
void ChromeRenderProcessObserver::OnGetRendererTcmalloc() { void ChromeRenderProcessObserver::OnGetRendererTcmalloc() {
std::string result; std::string result;
char buffer[1024 * 32]; char buffer[1024 * 32];
base::ProcessId pid = base::GetCurrentProcId();
MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); MallocExtension::instance()->GetStats(buffer, sizeof(buffer));
result.append(buffer); result.append(buffer);
Send(new ViewHostMsg_RendererTcmalloc(result)); Send(new ViewHostMsg_RendererTcmalloc(pid, result));
} }
void ChromeRenderProcessObserver::OnSetTcmallocHeapProfiling(
bool profiling, const std::string& filename_prefix) {
if (profiling)
HeapProfilerStart(filename_prefix.c_str());
else
HeapProfilerStop();
}
void ChromeRenderProcessObserver::OnWriteTcmallocHeapProfile(
const FilePath::StringType& filename) {
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( void ChromeRenderProcessObserver::OnSetFieldTrialGroup(
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <string> #include <string>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "content/renderer/render_process_observer.h" #include "content/renderer/render_process_observer.h"
...@@ -50,8 +49,6 @@ class ChromeRenderProcessObserver : public RenderProcessObserver { ...@@ -50,8 +49,6 @@ class ChromeRenderProcessObserver : public RenderProcessObserver {
void OnSetFieldTrialGroup(const std::string& fiel_trial_name, void OnSetFieldTrialGroup(const std::string& fiel_trial_name,
const std::string& group_name); const std::string& group_name);
void OnGetRendererTcmalloc(); void OnGetRendererTcmalloc();
void OnSetTcmallocHeapProfiling(bool profiling, const std::string& prefix);
void OnWriteTcmallocHeapProfile(const FilePath::StringType& filename);
void OnGetV8HeapStats(); void OnGetV8HeapStats();
void OnPurgeMemory(); void OnPurgeMemory();
......
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