diff options
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 46 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.h | 42 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 12 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 4 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 12 | ||||
-rw-r--r-- | chrome/renderer/render_thread.cc | 16 | ||||
-rw-r--r-- | chrome/renderer/render_thread.h | 3 |
7 files changed, 131 insertions, 4 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 746dd93..5a907c5 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -68,6 +68,13 @@ using sync_api::SyncManager; using base::Time; using base::TimeDelta; +#if defined(USE_TCMALLOC) +// Glue between the callback task and the method in the singleton. +void AboutTcmallocRendererCallback(base::ProcessId pid, std::string output) { + Singleton<AboutTcmallocOutputs>::get()->RendererCallback(pid, output); +} +#endif + namespace { // The paths used for the about pages. @@ -191,11 +198,42 @@ std::string AboutDns() { #if defined(USE_TCMALLOC) std::string AboutTcmalloc(const std::string& query) { std::string data; - char buffer[1024*32]; + AboutTcmallocOutputsType* outputs = + Singleton<AboutTcmallocOutputs>::get()->outputs(); + + // Display any stats for which we sent off requests the last time. + data.append("<html><head><title>About tcmalloc</title></head><body>\n"); + data.append("<p>Stats as of last page load;"); + data.append("reload to get stats as of this page load.</p>\n"); + data.append("<table width=\"100%\">\n"); + for (AboutTcmallocOutputsType::const_iterator oit = outputs->begin(); + oit != outputs->end(); + oit++) { + data.append("<tr><td bgcolor=\"yellow\">"); + data.append(oit->first); + data.append("</td></tr>\n"); + data.append("<tr><td><pre>\n"); + data.append(oit->second); + data.append("</pre></td></tr>\n"); + } + data.append("</table>\n"); + data.append("</body></html>\n"); + + // Reset our collector singleton. + outputs->clear(); + + // Populate the collector with stats from the local browser process + // and send off requests to all the renderer processes. + char buffer[1024 * 32]; MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); - data.append("<html><head><title>About tcmalloc</title></head><body><pre>\n"); - data.append(buffer); - data.append("</pre></body></html>\n"); + std::string browser("Browser"); + Singleton<AboutTcmallocOutputs>::get()->SetOutput(browser, buffer); + RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); + while (!it.IsAtEnd()) { + it.GetCurrentValue()->Send(new ViewMsg_GetRendererTcmalloc); + it.Advance(); + } + return data; } #endif diff --git a/chrome/browser/browser_about_handler.h b/chrome/browser/browser_about_handler.h index 87e5e75..56125ca 100644 --- a/chrome/browser/browser_about_handler.h +++ b/chrome/browser/browser_about_handler.h @@ -7,6 +7,13 @@ #ifndef CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_ #define CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_ +#include <map> +#include <string> + +#include "base/process.h" +#include "base/singleton.h" +#include "base/string_util.h" + class GURL; class Profile; @@ -23,4 +30,39 @@ bool WillHandleBrowserAboutURL(GURL* url, Profile* profile); // case, normal tab navigation should be skipped. bool HandleNonNavigationAboutURL(const GURL& url); +#if defined(USE_TCMALLOC) +// A map of header strings (e.g. "Browser", "Renderer PID 123") +// to the tcmalloc output collected for each process. +typedef std::map<std::string, std::string> AboutTcmallocOutputsType; + +class AboutTcmallocOutputs { + public: + AboutTcmallocOutputs() {} + + AboutTcmallocOutputsType* outputs() { return &outputs_; } + + // Records the output for a specified header string. + void SetOutput(std::string header, std::string output) { + outputs_[header] = output; + } + + // Callback for output returned from renderer processes. Adds + // the output for a canonical renderer header string that + // incorporates the pid. + void RendererCallback(base::ProcessId pid, std::string output) { + SetOutput(StringPrintf("Renderer PID %d", static_cast<int>(pid)), output); + } + + private: + AboutTcmallocOutputsType outputs_; + + friend struct DefaultSingletonTraits<AboutTcmallocOutputs>; + + DISALLOW_COPY_AND_ASSIGN(AboutTcmallocOutputs); +}; + +// Glue between the callback task and the method in the singleton. +void AboutTcmallocRendererCallback(base::ProcessId pid, std::string output); +#endif + #endif // CHROME_BROWSER_BROWSER_ABOUT_HANDLER_H_ diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 622f8e5e..c133d68 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -10,6 +10,7 @@ #include "base/histogram.h" #include "base/process_util.h" #include "base/thread.h" +#include "chrome/browser/browser_about_handler.h" #include "chrome/browser/child_process_security_policy.h" #include "chrome/browser/chrome_plugin_browsing_context.h" #include "chrome/browser/chrome_thread.h" @@ -372,6 +373,9 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { OnCloseIdleConnections) IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize) +#if defined(USE_TCMALLOC) + IPC_MESSAGE_HANDLER(ViewHostMsg_RendererTcmalloc, OnRendererTcmalloc) +#endif IPC_MESSAGE_UNHANDLED( handled = false) @@ -1047,3 +1051,11 @@ void ResourceMessageFilter::ReplyGetFileSize(int64 result, void* param) { // Getting file size callback done, decrease the ref count. Release(); } + +#if defined(USE_TCMALLOC) +void ResourceMessageFilter::OnRendererTcmalloc(base::ProcessId pid, + const std::string& output) { + ui_loop()->PostTask(FROM_HERE, + NewRunnableFunction(AboutTcmallocRendererCallback, pid, output)); +} +#endif diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 82bbcdc..a8a37af 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -16,6 +16,7 @@ #include "base/file_path.h" #include "base/gfx/rect.h" #include "base/gfx/native_widget_types.h" +#include "base/process.h" #include "base/ref_counted.h" #include "base/shared_memory.h" #include "base/string16.h" @@ -173,6 +174,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnDnsPrefetch(const std::vector<std::string>& hostnames); void OnRendererHistograms(int sequence_number, const std::vector<std::string>& histogram_info); +#if defined(USE_TCMALLOC) + void OnRendererTcmalloc(base::ProcessId pid, const std::string& output); +#endif void OnReceiveContextMenuMsg(const IPC::Message& msg); // Clipboard messages void OnClipboardWriteObjects(const Clipboard::ObjectMap& objects); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 9ec8ca9..3925798 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -541,6 +541,11 @@ IPC_BEGIN_MESSAGES(View) IPC_MESSAGE_CONTROL1(ViewMsg_GetRendererHistograms, int /* sequence number of Renderer Histograms. */) +#if defined(USE_TCMALLOC) + // Asks the renderer to send back tcmalloc stats. + IPC_MESSAGE_CONTROL0(ViewMsg_GetRendererTcmalloc) +#endif + // Notifies the renderer about ui theme changes IPC_MESSAGE_ROUTED0(ViewMsg_ThemeChanged) @@ -1360,6 +1365,13 @@ IPC_BEGIN_MESSAGES(ViewHost) int, /* sequence number of Renderer Histograms. */ std::vector<std::string>) +#if defined USE_TCMALLOC + // Send back tcmalloc stats output. + IPC_MESSAGE_CONTROL2(ViewHostMsg_RendererTcmalloc, + int /* pid */, + std::string /* tcmalloc debug output */) +#endif + // Request for a DNS prefetch of the names in the array. // NameList is typedef'ed std::vector<std::string> IPC_MESSAGE_CONTROL1(ViewHostMsg_DnsPrefetch, diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 09b043a..241ce45 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -12,6 +12,7 @@ #include "base/lazy_instance.h" #include "base/logging.h" #include "base/nullable_string16.h" +#include "base/process_util.h" #include "base/shared_memory.h" #include "base/stats_table.h" #include "base/string_util.h" @@ -277,6 +278,10 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms, OnGetRendererHistograms) +#if defined(USE_TCMALLOC) + IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, + OnGetRendererTcmalloc) +#endif IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) IPC_MESSAGE_HANDLER(ViewMsg_UserScripts_UpdatedScripts, @@ -363,6 +368,17 @@ void RenderThread::OnGetRendererHistograms(int sequence_number) { SendHistograms(sequence_number); } +#if defined(USE_TCMALLOC) +void RenderThread::OnGetRendererTcmalloc() { + std::string result; + char buffer[1024 * 32]; + int pid = base::GetCurrentProcId(); + MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); + result.append(buffer); + Send(new ViewHostMsg_RendererTcmalloc(pid, result)); +} +#endif + void RenderThread::InformHostOfCacheStats() { EnsureWebKitInitialized(); WebCache::UsageStats stats; diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h index 89f2c05..5f14260 100644 --- a/chrome/renderer/render_thread.h +++ b/chrome/renderer/render_thread.h @@ -172,6 +172,9 @@ class RenderThread : public RenderThreadBase, // Send all histograms to browser. void OnGetRendererHistograms(int sequence_number); + // Send tcmalloc info to browser. + void OnGetRendererTcmalloc(); + void OnExtensionMessageInvoke(const std::string& function_name, const ListValue& args); void OnPurgePluginListCache(bool reload_pages); |