blob: 727bb994f5bdfad62e342175a6d950d66692ea6c [file] [log] [blame]
[email protected]b0b67cf2012-01-18 21:59:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/memory_details.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]24d69692011-10-21 18:26:517#include "base/bind.h"
initial.commit09911bf2008-07-26 23:55:298#include "base/file_version_info.h"
[email protected]835d7c82010-10-14 04:38:389#include "base/metrics/histogram.h"
[email protected]76543b92009-08-31 17:27:4510#include "base/process_util.h"
[email protected]33b9df42010-07-29 06:46:3911#include "base/string_util.h"
[email protected]64048bd2010-03-08 23:28:5812#include "base/utf_string_conversions.h"
[email protected]8add5412011-10-01 21:02:1413#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]79dc42cd2011-01-08 21:43:3514#include "chrome/browser/extensions/extension_service.h"
15#include "chrome/browser/profiles/profile.h"
[email protected]14afc012011-12-01 01:04:3916#include "chrome/common/chrome_view_type.h"
[email protected]fcf79352010-12-28 20:13:2017#include "chrome/common/extensions/extension.h"
[email protected]cd3d7892009-03-04 23:55:0618#include "chrome/common/url_constants.h"
[email protected]f177ffd2012-01-20 07:51:5419#include "content/browser/browser_child_process_host.h"
[email protected]a01efd22011-03-01 00:38:3220#include "content/browser/renderer_host/backing_store_manager.h"
[email protected]a01efd22011-03-01 00:38:3221#include "content/browser/renderer_host/render_view_host.h"
[email protected]c38831a12011-10-28 12:44:4922#include "content/public/browser/browser_thread.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:2524#include "content/public/browser/navigation_entry.h"
[email protected]f3b1a082011-11-18 00:34:3025#include "content/public/browser/render_process_host.h"
[email protected]b0b67cf2012-01-18 21:59:5726#include "content/public/browser/render_view_host_delegate.h"
[email protected]83ff91c2012-01-05 20:54:1327#include "content/public/browser/web_contents.h"
[email protected]e091df82011-10-11 18:13:2128#include "content/public/common/bindings_policy.h"
[email protected]a54311142011-12-01 05:13:4129#include "content/public/common/process_type.h"
[email protected]ae5ca892009-07-30 18:00:4730#include "grit/chromium_strings.h"
[email protected]4f260d02010-12-23 18:35:4231#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1732#include "ui/base/l10n/l10n_util.h"
initial.commit09911bf2008-07-26 23:55:2933
[email protected]1fd5302c2011-05-28 04:06:4334#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a01efd22011-03-01 00:38:3235#include "content/browser/renderer_host/render_sandbox_host_linux.h"
[email protected]c38831a12011-10-28 12:44:4936#include "content/browser/zygote_host_linux.h"
[email protected]54fd1d32009-09-01 00:12:5837#endif
initial.commit09911bf2008-07-26 23:55:2938
[email protected]631bb742011-11-02 11:29:3939using content::BrowserThread;
[email protected]10f417c52011-12-28 21:04:2340using content::NavigationEntry;
[email protected]83ff91c2012-01-05 20:54:1341using content::WebContents;
[email protected]631bb742011-11-02 11:29:3942
[email protected]2c1978a2011-11-29 17:02:3943// static
44std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish(
45 RendererProcessType type) {
46 switch (type) {
47 case RENDERER_NORMAL:
48 return "Tab";
49 case RENDERER_CHROME:
50 return "Tab (Chrome)";
51 case RENDERER_EXTENSION:
52 return "Extension";
53 case RENDERER_DEVTOOLS:
54 return "Devtools";
55 case RENDERER_INTERSTITIAL:
56 return "Interstitial";
57 case RENDERER_NOTIFICATION:
58 return "Notification";
59 case RENDERER_BACKGROUND_APP:
60 return "Background App";
61 case RENDERER_UNKNOWN:
62 default:
63 NOTREACHED() << "Unknown renderer process type!";
64 return "Unknown";
65 }
66}
67
68// static
69std::string ProcessMemoryInformation::GetFullTypeNameInEnglish(
[email protected]bd5d6cf2011-12-01 00:39:1270 content::ProcessType type,
[email protected]2c1978a2011-11-29 17:02:3971 RendererProcessType rtype) {
[email protected]bd5d6cf2011-12-01 00:39:1272 if (type == content::PROCESS_TYPE_RENDERER)
[email protected]2c1978a2011-11-29 17:02:3973 return GetRendererTypeNameInEnglish(rtype);
[email protected]a54311142011-12-01 05:13:4174 return content::GetProcessTypeNameInEnglish(type);
[email protected]2c1978a2011-11-29 17:02:3975}
76
[email protected]8e383412010-10-19 16:57:0377ProcessMemoryInformation::ProcessMemoryInformation()
78 : pid(0),
79 num_processes(0),
80 is_diagnostics(false),
[email protected]bd5d6cf2011-12-01 00:39:1281 type(content::PROCESS_TYPE_UNKNOWN),
[email protected]2c1978a2011-11-29 17:02:3982 renderer_type(RENDERER_UNKNOWN) {
[email protected]8e383412010-10-19 16:57:0383}
84
85ProcessMemoryInformation::~ProcessMemoryInformation() {}
86
[email protected]93aa89c72010-10-20 21:32:0487ProcessData::ProcessData() {}
88
89ProcessData::ProcessData(const ProcessData& rhs)
90 : name(rhs.name),
91 process_name(rhs.process_name),
92 processes(rhs.processes) {
93}
94
95ProcessData::~ProcessData() {}
96
97ProcessData& ProcessData::operator=(const ProcessData& rhs) {
98 name = rhs.name;
99 process_name = rhs.process_name;
100 processes = rhs.processes;
101 return *this;
102}
103
initial.commit09911bf2008-07-26 23:55:29104// About threading:
105//
106// This operation will hit no fewer than 3 threads.
107//
[email protected]a436d922009-02-13 23:16:42108// The ChildProcessInfo::Iterator can only be accessed from the IO thread.
initial.commit09911bf2008-07-26 23:55:29109//
110// The RenderProcessHostIterator can only be accessed from the UI thread.
111//
112// This operation can take 30-100ms to complete. We never want to have
113// one task run for that long on the UI or IO threads. So, we run the
114// expensive parts of this operation over on the file thread.
115//
initial.commit09911bf2008-07-26 23:55:29116void MemoryDetails::StartFetch() {
[email protected]9bb480ee2011-08-03 21:41:16117 // This might get called from the UI or FILE threads, but should not be
118 // getting called from the IO thread.
[email protected]f8b3ef82010-10-11 02:45:52119 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29120
121 // In order to process this request, we need to use the plugin information.
122 // However, plugin process information is only available from the IO thread.
[email protected]f8b3ef82010-10-11 02:45:52123 BrowserThread::PostTask(
124 BrowserThread::IO, FROM_HERE,
[email protected]24d69692011-10-21 18:26:51125 base::Bind(&MemoryDetails::CollectChildInfoOnIOThread, this));
initial.commit09911bf2008-07-26 23:55:29126}
127
[email protected]8e383412010-10-19 16:57:03128MemoryDetails::~MemoryDetails() {}
129
[email protected]a27a9382009-02-11 23:55:10130void MemoryDetails::CollectChildInfoOnIOThread() {
[email protected]f8b3ef82010-10-11 02:45:52131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29132
[email protected]a27a9382009-02-11 23:55:10133 std::vector<ProcessMemoryInformation> child_info;
134
[email protected]a436d922009-02-13 23:16:42135 // Collect the list of child processes.
[email protected]f177ffd2012-01-20 07:51:54136 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) {
[email protected]a27a9382009-02-11 23:55:10137 ProcessMemoryInformation info;
[email protected]f177ffd2012-01-20 07:51:54138 info.pid = base::GetProcId(iter->data().handle);
[email protected]a27a9382009-02-11 23:55:10139 if (!info.pid)
140 continue;
141
[email protected]f177ffd2012-01-20 07:51:54142 info.type = iter->data().type;
[email protected]2c1978a2011-11-29 17:02:39143 info.renderer_type = ProcessMemoryInformation::RENDERER_UNKNOWN;
[email protected]f177ffd2012-01-20 07:51:54144 info.titles.push_back(iter->data().name);
[email protected]a27a9382009-02-11 23:55:10145 child_info.push_back(info);
initial.commit09911bf2008-07-26 23:55:29146 }
147
148 // Now go do expensive memory lookups from the file thread.
[email protected]f8b3ef82010-10-11 02:45:52149 BrowserThread::PostTask(
150 BrowserThread::FILE, FROM_HERE,
[email protected]24d69692011-10-21 18:26:51151 base::Bind(&MemoryDetails::CollectProcessData, this, child_info));
initial.commit09911bf2008-07-26 23:55:29152}
153
[email protected]a27a9382009-02-11 23:55:10154void MemoryDetails::CollectChildInfoOnUIThread() {
[email protected]f8b3ef82010-10-11 02:45:52155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
initial.commit09911bf2008-07-26 23:55:29156
[email protected]1fd5302c2011-05-28 04:06:43157#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]d3c6c0d72010-12-09 08:15:04158 const pid_t zygote_pid = ZygoteHost::GetInstance()->pid();
159 const pid_t sandbox_helper_pid = RenderSandboxHostLinux::GetInstance()->pid();
[email protected]54fd1d32009-09-01 00:12:58160#endif
161
162 ProcessData* const chrome_browser = ChromeBrowser();
[email protected]a27a9382009-02-11 23:55:10163 // Get more information about the process.
[email protected]54fd1d32009-09-01 00:12:58164 for (size_t index = 0; index < chrome_browser->processes.size();
initial.commit09911bf2008-07-26 23:55:29165 index++) {
[email protected]a27a9382009-02-11 23:55:10166 // Check if it's a renderer, if so get the list of page titles in it and
[email protected]fcf79352010-12-28 20:13:20167 // check if it's a diagnostics-related process. We skip about:memory pages.
168 // Iterate the RenderProcessHosts to find the tab contents.
[email protected]54fd1d32009-09-01 00:12:58169 ProcessMemoryInformation& process =
170 chrome_browser->processes[index];
171
[email protected]f3b1a082011-11-18 00:34:30172 for (content::RenderProcessHost::iterator renderer_iter(
173 content::RenderProcessHost::AllHostsIterator());
174 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) {
175 content::RenderProcessHost* render_process_host =
176 renderer_iter.GetCurrentValue();
[email protected]fcf79352010-12-28 20:13:20177 DCHECK(render_process_host);
[email protected]8a34e6602010-10-02 17:29:43178 // Ignore processes that don't have a connection, such as crashed tabs.
[email protected]fcf79352010-12-28 20:13:20179 if (!render_process_host->HasConnection() ||
180 process.pid != base::GetProcId(render_process_host->GetHandle())) {
[email protected]a27a9382009-02-11 23:55:10181 continue;
[email protected]201b2732009-11-13 18:57:46182 }
[email protected]bd5d6cf2011-12-01 00:39:12183 process.type = content::PROCESS_TYPE_RENDERER;
[email protected]9b62ecf2011-07-27 20:23:08184 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30185 Profile::FromBrowserContext(
186 render_process_host->GetBrowserContext());
[email protected]79dc42cd2011-01-08 21:43:35187 ExtensionService* extension_service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46188 extensions::ProcessMap* extension_process_map =
189 extension_service->process_map();
[email protected]79dc42cd2011-01-08 21:43:35190
[email protected]a27a9382009-02-11 23:55:10191 // The RenderProcessHost may host multiple TabContents. Any
192 // of them which contain diagnostics information make the whole
193 // process be considered a diagnostics process.
194 //
195 // NOTE: This is a bit dangerous. We know that for now, listeners
196 // are always RenderWidgetHosts. But in theory, they don't
197 // have to be.
[email protected]f3b1a082011-11-18 00:34:30198 content::RenderProcessHost::listeners_iterator iter(
[email protected]fcf79352010-12-28 20:13:20199 render_process_host->ListenersIterator());
[email protected]9de09f82009-08-17 20:13:53200 for (; !iter.IsAtEnd(); iter.Advance()) {
201 const RenderWidgetHost* widget =
202 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue());
[email protected]a27a9382009-02-11 23:55:10203 DCHECK(widget);
204 if (!widget || !widget->IsRenderView())
205 continue;
initial.commit09911bf2008-07-26 23:55:29206
[email protected]9de09f82009-08-17 20:13:53207 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget);
[email protected]b0b67cf2012-01-18 21:59:57208 content::RenderViewHostDelegate* host_delegate = host->delegate();
[email protected]4e6ffde2011-03-11 00:59:27209 DCHECK(host_delegate);
[email protected]fcf79352010-12-28 20:13:20210 GURL url = host_delegate->GetURL();
[email protected]da4dfc42011-10-12 15:53:56211 content::ViewType type = host_delegate->GetRenderViewType();
[email protected]e091df82011-10-11 18:13:21212 if (host->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI) {
[email protected]fcf79352010-12-28 20:13:20213 // TODO(erikkay) the type for devtools doesn't actually appear to
214 // be set.
[email protected]da4dfc42011-10-12 15:53:56215 if (type == content::VIEW_TYPE_DEV_TOOLS_UI)
[email protected]2c1978a2011-11-29 17:02:39216 process.renderer_type = ProcessMemoryInformation::RENDERER_DEVTOOLS;
[email protected]fcf79352010-12-28 20:13:20217 else
[email protected]2c1978a2011-11-29 17:02:39218 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME;
[email protected]f3b1a082011-11-18 00:34:30219 } else if (extension_process_map->Contains(host->process()->GetID())) {
[email protected]6f371442011-11-09 06:45:46220 // For our purposes, don't count processes containing only hosted apps
221 // as extension processes. See also: crbug.com/102533.
222 std::set<std::string> extension_ids =
223 extension_process_map->GetExtensionsInProcess(
[email protected]f3b1a082011-11-18 00:34:30224 host->process()->GetID());
[email protected]6f371442011-11-09 06:45:46225 for (std::set<std::string>::iterator iter = extension_ids.begin();
226 iter != extension_ids.end(); ++iter) {
227 const Extension* extension =
228 extension_service->GetExtensionById(*iter, false);
229 if (extension && !extension->is_hosted_app()) {
[email protected]2c1978a2011-11-29 17:02:39230 process.renderer_type =
231 ProcessMemoryInformation::RENDERER_EXTENSION;
[email protected]6f371442011-11-09 06:45:46232 break;
233 }
234 }
[email protected]fcf79352010-12-28 20:13:20235 }
[email protected]83ff91c2012-01-05 20:54:13236 WebContents* contents = host_delegate->GetAsWebContents();
[email protected]fcf79352010-12-28 20:13:20237 if (!contents) {
[email protected]f3b1a082011-11-18 00:34:30238 if (extension_process_map->Contains(host->process()->GetID())) {
[email protected]79dc42cd2011-01-08 21:43:35239 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44240 extension_service->extensions()->GetByID(url.host());
[email protected]79dc42cd2011-01-08 21:43:35241 if (extension) {
242 string16 title = UTF8ToUTF16(extension->name());
243 process.titles.push_back(title);
244 }
[email protected]fcf79352010-12-28 20:13:20245 } else if (process.renderer_type ==
[email protected]2c1978a2011-11-29 17:02:39246 ProcessMemoryInformation::RENDERER_UNKNOWN) {
[email protected]fcf79352010-12-28 20:13:20247 process.titles.push_back(UTF8ToUTF16(url.spec()));
248 switch (type) {
[email protected]da4dfc42011-10-12 15:53:56249 case chrome::VIEW_TYPE_BACKGROUND_CONTENTS:
[email protected]fcf79352010-12-28 20:13:20250 process.renderer_type =
[email protected]2c1978a2011-11-29 17:02:39251 ProcessMemoryInformation::RENDERER_BACKGROUND_APP;
[email protected]fcf79352010-12-28 20:13:20252 break;
[email protected]da4dfc42011-10-12 15:53:56253 case content::VIEW_TYPE_INTERSTITIAL_PAGE:
[email protected]2c1978a2011-11-29 17:02:39254 process.renderer_type =
255 ProcessMemoryInformation::RENDERER_INTERSTITIAL;
[email protected]fcf79352010-12-28 20:13:20256 break;
[email protected]da4dfc42011-10-12 15:53:56257 case chrome::VIEW_TYPE_NOTIFICATION:
[email protected]2c1978a2011-11-29 17:02:39258 process.renderer_type =
259 ProcessMemoryInformation::RENDERER_NOTIFICATION;
[email protected]fcf79352010-12-28 20:13:20260 break;
261 default:
[email protected]2c1978a2011-11-29 17:02:39262 process.renderer_type =
263 ProcessMemoryInformation::RENDERER_UNKNOWN;
[email protected]fcf79352010-12-28 20:13:20264 break;
265 }
266 }
[email protected]a27a9382009-02-11 23:55:10267 continue;
[email protected]fcf79352010-12-28 20:13:20268 }
269
[email protected]83ff91c2012-01-05 20:54:13270 // Since We have a WebContents and and the renderer type hasn't been
[email protected]fcf79352010-12-28 20:13:20271 // set yet, it must be a normal tabbed renderer.
[email protected]2c1978a2011-11-29 17:02:39272 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN)
273 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL;
[email protected]fcf79352010-12-28 20:13:20274
[email protected]4f260d02010-12-23 18:35:42275 string16 title = contents->GetTitle();
[email protected]a27a9382009-02-11 23:55:10276 if (!title.length())
[email protected]4f260d02010-12-23 18:35:42277 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
[email protected]a27a9382009-02-11 23:55:10278 process.titles.push_back(title);
[email protected]cd3d7892009-03-04 23:55:06279
[email protected]ebe89e062009-08-13 23:16:54280 // We need to check the pending entry as well as the virtual_url to
[email protected]37ae3f22011-07-12 03:56:14281 // see if it's a chrome://memory URL (we don't want to count these in
282 // the total memory usage of the browser).
[email protected]cd3d7892009-03-04 23:55:06283 //
[email protected]37ae3f22011-07-12 03:56:14284 // When we reach here, chrome://memory will be the pending entry since
285 // we haven't responded with any data such that it would be committed.
286 // If you have another chrome://memory tab open (which would be
287 // committed), we don't want to count it either, so we also check the
288 // last committed entry.
[email protected]cd3d7892009-03-04 23:55:06289 //
290 // Either the pending or last committed entries can be NULL.
[email protected]10f417c52011-12-28 21:04:23291 const NavigationEntry* pending_entry =
[email protected]022af742011-12-28 18:37:25292 contents->GetController().GetPendingEntry();
[email protected]10f417c52011-12-28 21:04:23293 const NavigationEntry* last_committed_entry =
[email protected]f5fa20e2011-12-21 22:35:56294 contents->GetController().GetLastCommittedEntry();
[email protected]cd3d7892009-03-04 23:55:06295 if ((last_committed_entry &&
[email protected]36fc0392011-12-25 03:59:51296 LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(),
[email protected]37ae3f22011-07-12 03:56:14297 chrome::kChromeUIMemoryURL)) ||
[email protected]cd3d7892009-03-04 23:55:06298 (pending_entry &&
[email protected]36fc0392011-12-25 03:59:51299 LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(),
[email protected]37ae3f22011-07-12 03:56:14300 chrome::kChromeUIMemoryURL)))
[email protected]a27a9382009-02-11 23:55:10301 process.is_diagnostics = true;
initial.commit09911bf2008-07-26 23:55:29302 }
303 }
[email protected]54fd1d32009-09-01 00:12:58304
[email protected]1fd5302c2011-05-28 04:06:43305#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]54fd1d32009-09-01 00:12:58306 if (process.pid == zygote_pid) {
[email protected]bd5d6cf2011-12-01 00:39:12307 process.type = content::PROCESS_TYPE_ZYGOTE;
[email protected]54fd1d32009-09-01 00:12:58308 } else if (process.pid == sandbox_helper_pid) {
[email protected]bd5d6cf2011-12-01 00:39:12309 process.type = content::PROCESS_TYPE_SANDBOX_HELPER;
[email protected]54fd1d32009-09-01 00:12:58310 }
311#endif
initial.commit09911bf2008-07-26 23:55:29312 }
313
[email protected]a27a9382009-02-11 23:55:10314 // Get rid of other Chrome processes that are from a different profile.
[email protected]54fd1d32009-09-01 00:12:58315 for (size_t index = 0; index < chrome_browser->processes.size();
[email protected]a27a9382009-02-11 23:55:10316 index++) {
[email protected]54fd1d32009-09-01 00:12:58317 if (chrome_browser->processes[index].type ==
[email protected]bd5d6cf2011-12-01 00:39:12318 content::PROCESS_TYPE_UNKNOWN) {
[email protected]54fd1d32009-09-01 00:12:58319 chrome_browser->processes.erase(
320 chrome_browser->processes.begin() + index);
[email protected]a436d922009-02-13 23:16:42321 index--;
[email protected]a27a9382009-02-11 23:55:10322 }
323 }
324
initial.commit09911bf2008-07-26 23:55:29325 UpdateHistograms();
326
327 OnDetailsAvailable();
328}
329
330void MemoryDetails::UpdateHistograms() {
331 // Reports a set of memory metrics to UMA.
[email protected]57c4b852009-08-17 21:59:29332 // Memory is measured in KB.
initial.commit09911bf2008-07-26 23:55:29333
[email protected]54fd1d32009-09-01 00:12:58334 const ProcessData& browser = *ChromeBrowser();
initial.commit09911bf2008-07-26 23:55:29335 size_t aggregate_memory = 0;
[email protected]fcf79352010-12-28 20:13:20336 int chrome_count = 0;
337 int extension_count = 0;
[email protected]a27a9382009-02-11 23:55:10338 int plugin_count = 0;
[email protected]eef348fb2011-08-01 21:11:08339 int pepper_plugin_count = 0;
[email protected]fcf79352010-12-28 20:13:20340 int renderer_count = 0;
341 int other_count = 0;
[email protected]a27a9382009-02-11 23:55:10342 int worker_count = 0;
initial.commit09911bf2008-07-26 23:55:29343 for (size_t index = 0; index < browser.processes.size(); index++) {
[email protected]921cd0cc2008-10-21 22:30:55344 int sample = static_cast<int>(browser.processes[index].working_set.priv);
345 aggregate_memory += sample;
[email protected]a27a9382009-02-11 23:55:10346 switch (browser.processes[index].type) {
[email protected]bd5d6cf2011-12-01 00:39:12347 case content::PROCESS_TYPE_BROWSER:
[email protected]f164cea2009-11-05 23:37:40348 UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample);
349 break;
[email protected]bd5d6cf2011-12-01 00:39:12350 case content::PROCESS_TYPE_RENDERER: {
[email protected]2c1978a2011-11-29 17:02:39351 ProcessMemoryInformation::RendererProcessType renderer_type =
[email protected]fcf79352010-12-28 20:13:20352 browser.processes[index].renderer_type;
353 switch (renderer_type) {
[email protected]2c1978a2011-11-29 17:02:39354 case ProcessMemoryInformation::RENDERER_EXTENSION:
[email protected]fcf79352010-12-28 20:13:20355 UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample);
356 extension_count++;
357 break;
[email protected]2c1978a2011-11-29 17:02:39358 case ProcessMemoryInformation::RENDERER_CHROME:
[email protected]fcf79352010-12-28 20:13:20359 UMA_HISTOGRAM_MEMORY_KB("Memory.Chrome", sample);
360 chrome_count++;
361 break;
[email protected]2c1978a2011-11-29 17:02:39362 case ProcessMemoryInformation::RENDERER_UNKNOWN:
[email protected]fcf79352010-12-28 20:13:20363 NOTREACHED() << "Unknown renderer process type.";
364 break;
[email protected]2c1978a2011-11-29 17:02:39365 case ProcessMemoryInformation::RENDERER_NORMAL:
[email protected]fcf79352010-12-28 20:13:20366 default:
367 // TODO(erikkay): Should we bother splitting out the other subtypes?
368 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer", sample);
369 renderer_count++;
370 break;
371 }
[email protected]f164cea2009-11-05 23:37:40372 break;
[email protected]fcf79352010-12-28 20:13:20373 }
[email protected]bd5d6cf2011-12-01 00:39:12374 case content::PROCESS_TYPE_PLUGIN:
[email protected]f164cea2009-11-05 23:37:40375 UMA_HISTOGRAM_MEMORY_KB("Memory.Plugin", sample);
376 plugin_count++;
377 break;
[email protected]bd5d6cf2011-12-01 00:39:12378 case content::PROCESS_TYPE_WORKER:
[email protected]f164cea2009-11-05 23:37:40379 UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample);
380 worker_count++;
381 break;
[email protected]bd5d6cf2011-12-01 00:39:12382 case content::PROCESS_TYPE_UTILITY:
[email protected]f164cea2009-11-05 23:37:40383 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample);
[email protected]fcf79352010-12-28 20:13:20384 other_count++;
[email protected]f164cea2009-11-05 23:37:40385 break;
[email protected]bd5d6cf2011-12-01 00:39:12386 case content::PROCESS_TYPE_ZYGOTE:
[email protected]f164cea2009-11-05 23:37:40387 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample);
[email protected]fcf79352010-12-28 20:13:20388 other_count++;
[email protected]f164cea2009-11-05 23:37:40389 break;
[email protected]bd5d6cf2011-12-01 00:39:12390 case content::PROCESS_TYPE_SANDBOX_HELPER:
[email protected]f164cea2009-11-05 23:37:40391 UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample);
[email protected]fcf79352010-12-28 20:13:20392 other_count++;
[email protected]f164cea2009-11-05 23:37:40393 break;
[email protected]bd5d6cf2011-12-01 00:39:12394 case content::PROCESS_TYPE_NACL_LOADER:
[email protected]f164cea2009-11-05 23:37:40395 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample);
[email protected]fcf79352010-12-28 20:13:20396 other_count++;
[email protected]f164cea2009-11-05 23:37:40397 break;
[email protected]bd5d6cf2011-12-01 00:39:12398 case content::PROCESS_TYPE_NACL_BROKER:
[email protected]aef8d5ae2010-03-17 22:40:52399 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample);
[email protected]fcf79352010-12-28 20:13:20400 other_count++;
[email protected]aef8d5ae2010-03-17 22:40:52401 break;
[email protected]bd5d6cf2011-12-01 00:39:12402 case content::PROCESS_TYPE_GPU:
[email protected]96fcbf2d2010-08-03 16:10:27403 UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample);
[email protected]fcf79352010-12-28 20:13:20404 other_count++;
[email protected]96fcbf2d2010-08-03 16:10:27405 break;
[email protected]bd5d6cf2011-12-01 00:39:12406 case content::PROCESS_TYPE_PPAPI_PLUGIN:
[email protected]eef348fb2011-08-01 21:11:08407 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample);
408 pepper_plugin_count++;
409 break;
[email protected]f164cea2009-11-05 23:37:40410 default:
411 NOTREACHED();
[email protected]eef348fb2011-08-01 21:11:08412 break;
initial.commit09911bf2008-07-26 23:55:29413 }
414 }
[email protected]57c4b852009-08-17 21:59:29415 UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore",
416 BackingStoreManager::MemorySize() / 1024);
[email protected]a27a9382009-02-11 23:55:10417
[email protected]553dba62009-02-24 19:08:23418 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount",
initial.commit09911bf2008-07-26 23:55:29419 static_cast<int>(browser.processes.size()));
[email protected]fcf79352010-12-28 20:13:20420 UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count);
421 UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count);
422 UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count);
[email protected]553dba62009-02-24 19:08:23423 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count);
[email protected]eef348fb2011-08-01 21:11:08424 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount",
425 pepper_plugin_count);
[email protected]fcf79352010-12-28 20:13:20426 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
[email protected]553dba62009-02-24 19:08:23427 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
[email protected]f164cea2009-11-05 23:37:40428 // TODO(viettrungluu): Do we want separate counts for the other
429 // (platform-specific) process types?
[email protected]921cd0cc2008-10-21 22:30:55430
431 int total_sample = static_cast<int>(aggregate_memory / 1000);
[email protected]553dba62009-02-24 19:08:23432 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample);
initial.commit09911bf2008-07-26 23:55:29433}