[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/memory_details.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 24d6969 | 2011-10-21 18:26:51 | [diff] [blame] | 7 | #include "base/bind.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include "base/file_version_info.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 9 | #include "base/metrics/histogram.h" |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 10 | #include "base/process_util.h" |
[email protected] | 33b9df4 | 2010-07-29 06:46:39 | [diff] [blame] | 11 | #include "base/string_util.h" |
[email protected] | 64048bd | 2010-03-08 23:28:58 | [diff] [blame] | 12 | #include "base/utf_string_conversions.h" |
[email protected] | 8add541 | 2011-10-01 21:02:14 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_service.h" |
| 15 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 14afc01 | 2011-12-01 01:04:39 | [diff] [blame] | 16 | #include "chrome/common/chrome_view_type.h" |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 17 | #include "chrome/common/extensions/extension.h" |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 18 | #include "chrome/common/url_constants.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 19 | #include "content/browser/browser_child_process_host.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 20 | #include "content/browser/renderer_host/backing_store_manager.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 21 | #include "content/browser/renderer_host/render_view_host.h" |
| 22 | #include "content/browser/tab_contents/navigation_entry.h" |
| 23 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 24 | #include "content/public/browser/browser_thread.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 25 | #include "content/public/browser/render_process_host.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 26 | #include "content/public/common/bindings_policy.h" |
[email protected] | a5431114 | 2011-12-01 05:13:41 | [diff] [blame] | 27 | #include "content/public/common/process_type.h" |
[email protected] | ae5ca89 | 2009-07-30 18:00:47 | [diff] [blame] | 28 | #include "grit/chromium_strings.h" |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 29 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 30 | #include "ui/base/l10n/l10n_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 32 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 33 | #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 34 | #include "content/browser/zygote_host_linux.h" |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 35 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 37 | using content::BrowserThread; |
| 38 | |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 39 | // static |
| 40 | std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish( |
| 41 | RendererProcessType type) { |
| 42 | switch (type) { |
| 43 | case RENDERER_NORMAL: |
| 44 | return "Tab"; |
| 45 | case RENDERER_CHROME: |
| 46 | return "Tab (Chrome)"; |
| 47 | case RENDERER_EXTENSION: |
| 48 | return "Extension"; |
| 49 | case RENDERER_DEVTOOLS: |
| 50 | return "Devtools"; |
| 51 | case RENDERER_INTERSTITIAL: |
| 52 | return "Interstitial"; |
| 53 | case RENDERER_NOTIFICATION: |
| 54 | return "Notification"; |
| 55 | case RENDERER_BACKGROUND_APP: |
| 56 | return "Background App"; |
| 57 | case RENDERER_UNKNOWN: |
| 58 | default: |
| 59 | NOTREACHED() << "Unknown renderer process type!"; |
| 60 | return "Unknown"; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // static |
| 65 | std::string ProcessMemoryInformation::GetFullTypeNameInEnglish( |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 66 | content::ProcessType type, |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 67 | RendererProcessType rtype) { |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 68 | if (type == content::PROCESS_TYPE_RENDERER) |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 69 | return GetRendererTypeNameInEnglish(rtype); |
[email protected] | a5431114 | 2011-12-01 05:13:41 | [diff] [blame] | 70 | return content::GetProcessTypeNameInEnglish(type); |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 73 | ProcessMemoryInformation::ProcessMemoryInformation() |
| 74 | : pid(0), |
| 75 | num_processes(0), |
| 76 | is_diagnostics(false), |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 77 | type(content::PROCESS_TYPE_UNKNOWN), |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 78 | renderer_type(RENDERER_UNKNOWN) { |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | ProcessMemoryInformation::~ProcessMemoryInformation() {} |
| 82 | |
[email protected] | 93aa89c7 | 2010-10-20 21:32:04 | [diff] [blame] | 83 | ProcessData::ProcessData() {} |
| 84 | |
| 85 | ProcessData::ProcessData(const ProcessData& rhs) |
| 86 | : name(rhs.name), |
| 87 | process_name(rhs.process_name), |
| 88 | processes(rhs.processes) { |
| 89 | } |
| 90 | |
| 91 | ProcessData::~ProcessData() {} |
| 92 | |
| 93 | ProcessData& ProcessData::operator=(const ProcessData& rhs) { |
| 94 | name = rhs.name; |
| 95 | process_name = rhs.process_name; |
| 96 | processes = rhs.processes; |
| 97 | return *this; |
| 98 | } |
| 99 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | // About threading: |
| 101 | // |
| 102 | // This operation will hit no fewer than 3 threads. |
| 103 | // |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 104 | // The ChildProcessInfo::Iterator can only be accessed from the IO thread. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | // |
| 106 | // The RenderProcessHostIterator can only be accessed from the UI thread. |
| 107 | // |
| 108 | // This operation can take 30-100ms to complete. We never want to have |
| 109 | // one task run for that long on the UI or IO threads. So, we run the |
| 110 | // expensive parts of this operation over on the file thread. |
| 111 | // |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | void MemoryDetails::StartFetch() { |
[email protected] | 9bb480ee | 2011-08-03 21:41:16 | [diff] [blame] | 113 | // This might get called from the UI or FILE threads, but should not be |
| 114 | // getting called from the IO thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 115 | DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | |
| 117 | // In order to process this request, we need to use the plugin information. |
| 118 | // However, plugin process information is only available from the IO thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 119 | BrowserThread::PostTask( |
| 120 | BrowserThread::IO, FROM_HERE, |
[email protected] | 24d6969 | 2011-10-21 18:26:51 | [diff] [blame] | 121 | base::Bind(&MemoryDetails::CollectChildInfoOnIOThread, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | } |
| 123 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 124 | MemoryDetails::~MemoryDetails() {} |
| 125 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 126 | void MemoryDetails::CollectChildInfoOnIOThread() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 127 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 128 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 129 | std::vector<ProcessMemoryInformation> child_info; |
| 130 | |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 131 | // Collect the list of child processes. |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 132 | for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 133 | ProcessMemoryInformation info; |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 134 | info.pid = base::GetProcId(iter->handle()); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 135 | if (!info.pid) |
| 136 | continue; |
| 137 | |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 138 | info.type = iter->type(); |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 139 | info.renderer_type = ProcessMemoryInformation::RENDERER_UNKNOWN; |
[email protected] | 68b9e72b | 2011-08-05 23:08:22 | [diff] [blame] | 140 | info.titles.push_back(iter->name()); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 141 | child_info.push_back(info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | // Now go do expensive memory lookups from the file thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 145 | BrowserThread::PostTask( |
| 146 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 24d6969 | 2011-10-21 18:26:51 | [diff] [blame] | 147 | base::Bind(&MemoryDetails::CollectProcessData, this, child_info)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 150 | void MemoryDetails::CollectChildInfoOnUIThread() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 151 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 152 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 153 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 154 | const pid_t zygote_pid = ZygoteHost::GetInstance()->pid(); |
| 155 | const pid_t sandbox_helper_pid = RenderSandboxHostLinux::GetInstance()->pid(); |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 156 | #endif |
| 157 | |
| 158 | ProcessData* const chrome_browser = ChromeBrowser(); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 159 | // Get more information about the process. |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 160 | for (size_t index = 0; index < chrome_browser->processes.size(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 161 | index++) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 162 | // Check if it's a renderer, if so get the list of page titles in it and |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 163 | // check if it's a diagnostics-related process. We skip about:memory pages. |
| 164 | // Iterate the RenderProcessHosts to find the tab contents. |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 165 | ProcessMemoryInformation& process = |
| 166 | chrome_browser->processes[index]; |
| 167 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 168 | for (content::RenderProcessHost::iterator renderer_iter( |
| 169 | content::RenderProcessHost::AllHostsIterator()); |
| 170 | !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { |
| 171 | content::RenderProcessHost* render_process_host = |
| 172 | renderer_iter.GetCurrentValue(); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 173 | DCHECK(render_process_host); |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 174 | // Ignore processes that don't have a connection, such as crashed tabs. |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 175 | if (!render_process_host->HasConnection() || |
| 176 | process.pid != base::GetProcId(render_process_host->GetHandle())) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 177 | continue; |
[email protected] | 201b273 | 2009-11-13 18:57:46 | [diff] [blame] | 178 | } |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 179 | process.type = content::PROCESS_TYPE_RENDERER; |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 180 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 181 | Profile::FromBrowserContext( |
| 182 | render_process_host->GetBrowserContext()); |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 183 | ExtensionService* extension_service = profile->GetExtensionService(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 184 | extensions::ProcessMap* extension_process_map = |
| 185 | extension_service->process_map(); |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 186 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 187 | // The RenderProcessHost may host multiple TabContents. Any |
| 188 | // of them which contain diagnostics information make the whole |
| 189 | // process be considered a diagnostics process. |
| 190 | // |
| 191 | // NOTE: This is a bit dangerous. We know that for now, listeners |
| 192 | // are always RenderWidgetHosts. But in theory, they don't |
| 193 | // have to be. |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 194 | content::RenderProcessHost::listeners_iterator iter( |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 195 | render_process_host->ListenersIterator()); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 196 | for (; !iter.IsAtEnd(); iter.Advance()) { |
| 197 | const RenderWidgetHost* widget = |
| 198 | static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 199 | DCHECK(widget); |
| 200 | if (!widget || !widget->IsRenderView()) |
| 201 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 202 | |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 203 | const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 204 | RenderViewHostDelegate* host_delegate = host->delegate(); |
[email protected] | 4e6ffde | 2011-03-11 00:59:27 | [diff] [blame] | 205 | DCHECK(host_delegate); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 206 | GURL url = host_delegate->GetURL(); |
[email protected] | da4dfc4 | 2011-10-12 15:53:56 | [diff] [blame] | 207 | content::ViewType type = host_delegate->GetRenderViewType(); |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 208 | if (host->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI) { |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 209 | // TODO(erikkay) the type for devtools doesn't actually appear to |
| 210 | // be set. |
[email protected] | da4dfc4 | 2011-10-12 15:53:56 | [diff] [blame] | 211 | if (type == content::VIEW_TYPE_DEV_TOOLS_UI) |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 212 | process.renderer_type = ProcessMemoryInformation::RENDERER_DEVTOOLS; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 213 | else |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 214 | process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 215 | } else if (extension_process_map->Contains(host->process()->GetID())) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 216 | // For our purposes, don't count processes containing only hosted apps |
| 217 | // as extension processes. See also: crbug.com/102533. |
| 218 | std::set<std::string> extension_ids = |
| 219 | extension_process_map->GetExtensionsInProcess( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 220 | host->process()->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 221 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 222 | iter != extension_ids.end(); ++iter) { |
| 223 | const Extension* extension = |
| 224 | extension_service->GetExtensionById(*iter, false); |
| 225 | if (extension && !extension->is_hosted_app()) { |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 226 | process.renderer_type = |
| 227 | ProcessMemoryInformation::RENDERER_EXTENSION; |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 228 | break; |
| 229 | } |
| 230 | } |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 231 | } |
[email protected] | 4e6ffde | 2011-03-11 00:59:27 | [diff] [blame] | 232 | TabContents* contents = host_delegate->GetAsTabContents(); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 233 | if (!contents) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 234 | if (extension_process_map->Contains(host->process()->GetID())) { |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 235 | const Extension* extension = |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame^] | 236 | extension_service->extensions()->GetByID(url.host()); |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 237 | if (extension) { |
| 238 | string16 title = UTF8ToUTF16(extension->name()); |
| 239 | process.titles.push_back(title); |
| 240 | } |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 241 | } else if (process.renderer_type == |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 242 | ProcessMemoryInformation::RENDERER_UNKNOWN) { |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 243 | process.titles.push_back(UTF8ToUTF16(url.spec())); |
| 244 | switch (type) { |
[email protected] | da4dfc4 | 2011-10-12 15:53:56 | [diff] [blame] | 245 | case chrome::VIEW_TYPE_BACKGROUND_CONTENTS: |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 246 | process.renderer_type = |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 247 | ProcessMemoryInformation::RENDERER_BACKGROUND_APP; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 248 | break; |
[email protected] | da4dfc4 | 2011-10-12 15:53:56 | [diff] [blame] | 249 | case content::VIEW_TYPE_INTERSTITIAL_PAGE: |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 250 | process.renderer_type = |
| 251 | ProcessMemoryInformation::RENDERER_INTERSTITIAL; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 252 | break; |
[email protected] | da4dfc4 | 2011-10-12 15:53:56 | [diff] [blame] | 253 | case chrome::VIEW_TYPE_NOTIFICATION: |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 254 | process.renderer_type = |
| 255 | ProcessMemoryInformation::RENDERER_NOTIFICATION; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 256 | break; |
| 257 | default: |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 258 | process.renderer_type = |
| 259 | ProcessMemoryInformation::RENDERER_UNKNOWN; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 260 | break; |
| 261 | } |
| 262 | } |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 263 | continue; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | // Since We have a TabContents and and the renderer type hasn't been |
| 267 | // set yet, it must be a normal tabbed renderer. |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 268 | if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN) |
| 269 | process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 270 | |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 271 | string16 title = contents->GetTitle(); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 272 | if (!title.length()) |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 273 | title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 274 | process.titles.push_back(title); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 275 | |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 276 | // We need to check the pending entry as well as the virtual_url to |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 277 | // see if it's a chrome://memory URL (we don't want to count these in |
| 278 | // the total memory usage of the browser). |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 279 | // |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 280 | // When we reach here, chrome://memory will be the pending entry since |
| 281 | // we haven't responded with any data such that it would be committed. |
| 282 | // If you have another chrome://memory tab open (which would be |
| 283 | // committed), we don't want to count it either, so we also check the |
| 284 | // last committed entry. |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 285 | // |
| 286 | // Either the pending or last committed entries can be NULL. |
[email protected] | 6df4074 | 2009-03-19 22:24:50 | [diff] [blame] | 287 | const NavigationEntry* pending_entry = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 288 | contents->controller().pending_entry(); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 289 | const NavigationEntry* last_committed_entry = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 290 | contents->controller().GetLastCommittedEntry(); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 291 | if ((last_committed_entry && |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 292 | LowerCaseEqualsASCII(last_committed_entry->virtual_url().spec(), |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 293 | chrome::kChromeUIMemoryURL)) || |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 294 | (pending_entry && |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 295 | LowerCaseEqualsASCII(pending_entry->virtual_url().spec(), |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 296 | chrome::kChromeUIMemoryURL))) |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 297 | process.is_diagnostics = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 298 | } |
| 299 | } |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 300 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 301 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 302 | if (process.pid == zygote_pid) { |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 303 | process.type = content::PROCESS_TYPE_ZYGOTE; |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 304 | } else if (process.pid == sandbox_helper_pid) { |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 305 | process.type = content::PROCESS_TYPE_SANDBOX_HELPER; |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 306 | } |
| 307 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 308 | } |
| 309 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 310 | // Get rid of other Chrome processes that are from a different profile. |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 311 | for (size_t index = 0; index < chrome_browser->processes.size(); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 312 | index++) { |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 313 | if (chrome_browser->processes[index].type == |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 314 | content::PROCESS_TYPE_UNKNOWN) { |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 315 | chrome_browser->processes.erase( |
| 316 | chrome_browser->processes.begin() + index); |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 317 | index--; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 321 | UpdateHistograms(); |
| 322 | |
| 323 | OnDetailsAvailable(); |
| 324 | } |
| 325 | |
| 326 | void MemoryDetails::UpdateHistograms() { |
| 327 | // Reports a set of memory metrics to UMA. |
[email protected] | 57c4b85 | 2009-08-17 21:59:29 | [diff] [blame] | 328 | // Memory is measured in KB. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 329 | |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 330 | const ProcessData& browser = *ChromeBrowser(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 331 | size_t aggregate_memory = 0; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 332 | int chrome_count = 0; |
| 333 | int extension_count = 0; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 334 | int plugin_count = 0; |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 335 | int pepper_plugin_count = 0; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 336 | int renderer_count = 0; |
| 337 | int other_count = 0; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 338 | int worker_count = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 339 | for (size_t index = 0; index < browser.processes.size(); index++) { |
[email protected] | 921cd0cc | 2008-10-21 22:30:55 | [diff] [blame] | 340 | int sample = static_cast<int>(browser.processes[index].working_set.priv); |
| 341 | aggregate_memory += sample; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 342 | switch (browser.processes[index].type) { |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 343 | case content::PROCESS_TYPE_BROWSER: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 344 | UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample); |
| 345 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 346 | case content::PROCESS_TYPE_RENDERER: { |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 347 | ProcessMemoryInformation::RendererProcessType renderer_type = |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 348 | browser.processes[index].renderer_type; |
| 349 | switch (renderer_type) { |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 350 | case ProcessMemoryInformation::RENDERER_EXTENSION: |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 351 | UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample); |
| 352 | extension_count++; |
| 353 | break; |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 354 | case ProcessMemoryInformation::RENDERER_CHROME: |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 355 | UMA_HISTOGRAM_MEMORY_KB("Memory.Chrome", sample); |
| 356 | chrome_count++; |
| 357 | break; |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 358 | case ProcessMemoryInformation::RENDERER_UNKNOWN: |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 359 | NOTREACHED() << "Unknown renderer process type."; |
| 360 | break; |
[email protected] | 2c1978a | 2011-11-29 17:02:39 | [diff] [blame] | 361 | case ProcessMemoryInformation::RENDERER_NORMAL: |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 362 | default: |
| 363 | // TODO(erikkay): Should we bother splitting out the other subtypes? |
| 364 | UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer", sample); |
| 365 | renderer_count++; |
| 366 | break; |
| 367 | } |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 368 | break; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 369 | } |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 370 | case content::PROCESS_TYPE_PLUGIN: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 371 | UMA_HISTOGRAM_MEMORY_KB("Memory.Plugin", sample); |
| 372 | plugin_count++; |
| 373 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 374 | case content::PROCESS_TYPE_WORKER: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 375 | UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample); |
| 376 | worker_count++; |
| 377 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 378 | case content::PROCESS_TYPE_UTILITY: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 379 | UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 380 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 381 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 382 | case content::PROCESS_TYPE_ZYGOTE: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 383 | UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 384 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 385 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 386 | case content::PROCESS_TYPE_SANDBOX_HELPER: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 387 | UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 388 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 389 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 390 | case content::PROCESS_TYPE_NACL_LOADER: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 391 | UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 392 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 393 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 394 | case content::PROCESS_TYPE_NACL_BROKER: |
[email protected] | aef8d5ae | 2010-03-17 22:40:52 | [diff] [blame] | 395 | UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 396 | other_count++; |
[email protected] | aef8d5ae | 2010-03-17 22:40:52 | [diff] [blame] | 397 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 398 | case content::PROCESS_TYPE_GPU: |
[email protected] | 96fcbf2d | 2010-08-03 16:10:27 | [diff] [blame] | 399 | UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 400 | other_count++; |
[email protected] | 96fcbf2d | 2010-08-03 16:10:27 | [diff] [blame] | 401 | break; |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 402 | case content::PROCESS_TYPE_PPAPI_PLUGIN: |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 403 | UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample); |
| 404 | pepper_plugin_count++; |
| 405 | break; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 406 | default: |
| 407 | NOTREACHED(); |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 408 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 409 | } |
| 410 | } |
[email protected] | 57c4b85 | 2009-08-17 21:59:29 | [diff] [blame] | 411 | UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore", |
| 412 | BackingStoreManager::MemorySize() / 1024); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 413 | |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 414 | UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 415 | static_cast<int>(browser.processes.size())); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 416 | UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count); |
| 417 | UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count); |
| 418 | UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count); |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 419 | UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 420 | UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", |
| 421 | pepper_plugin_count); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 422 | UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 423 | UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 424 | // TODO(viettrungluu): Do we want separate counts for the other |
| 425 | // (platform-specific) process types? |
[email protected] | 921cd0cc | 2008-10-21 22:30:55 | [diff] [blame] | 426 | |
| 427 | int total_sample = static_cast<int>(aggregate_memory / 1000); |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 428 | UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 429 | } |