blob: 8c3a6c2c075c94424e095009bcd7d021ae906d10 [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]4306df72012-04-20 18:58:5712#include "base/stringprintf.h"
[email protected]64048bd2010-03-08 23:28:5813#include "base/utf_string_conversions.h"
[email protected]8add5412011-10-01 21:02:1414#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]79dc42cd2011-01-08 21:43:3515#include "chrome/browser/extensions/extension_service.h"
16#include "chrome/browser/profiles/profile.h"
[email protected]299d7f12012-05-23 05:31:1517#include "chrome/browser/view_type_utils.h"
[email protected]fcf79352010-12-28 20:13:2018#include "chrome/common/extensions/extension.h"
[email protected]cd3d7892009-03-04 23:55:0619#include "chrome/common/url_constants.h"
[email protected]4967f792012-01-20 22:14:4020#include "content/public/browser/browser_child_process_host_iterator.h"
[email protected]c38831a12011-10-28 12:44:4921#include "content/public/browser/browser_thread.h"
[email protected]9c1662b2012-03-06 15:44:3322#include "content/public/browser/child_process_data.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]9c1662b2012-03-06 15:44:3326#include "content/public/browser/render_view_host.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]a423c9e2012-03-06 18:02:3134#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]c2c68b1f2012-02-25 00:29:1535#include "content/public/browser/zygote_host_linux.h"
[email protected]54fd1d32009-09-01 00:12:5836#endif
initial.commit09911bf2008-07-26 23:55:2937
[email protected]4306df72012-04-20 18:58:5738using base::StringPrintf;
[email protected]4967f792012-01-20 22:14:4039using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:3940using content::BrowserThread;
[email protected]10f417c52011-12-28 21:04:2341using content::NavigationEntry;
[email protected]eaabba22012-03-07 15:02:1142using content::RenderViewHost;
43using content::RenderWidgetHost;
[email protected]83ff91c2012-01-05 20:54:1344using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:3445using extensions::Extension;
[email protected]631bb742011-11-02 11:29:3946
[email protected]2c1978a2011-11-29 17:02:3947// static
48std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish(
49 RendererProcessType type) {
50 switch (type) {
51 case RENDERER_NORMAL:
52 return "Tab";
53 case RENDERER_CHROME:
54 return "Tab (Chrome)";
55 case RENDERER_EXTENSION:
56 return "Extension";
57 case RENDERER_DEVTOOLS:
58 return "Devtools";
59 case RENDERER_INTERSTITIAL:
60 return "Interstitial";
61 case RENDERER_NOTIFICATION:
62 return "Notification";
63 case RENDERER_BACKGROUND_APP:
64 return "Background App";
65 case RENDERER_UNKNOWN:
66 default:
67 NOTREACHED() << "Unknown renderer process type!";
68 return "Unknown";
69 }
70}
71
72// static
73std::string ProcessMemoryInformation::GetFullTypeNameInEnglish(
[email protected]bd5d6cf2011-12-01 00:39:1274 content::ProcessType type,
[email protected]2c1978a2011-11-29 17:02:3975 RendererProcessType rtype) {
[email protected]bd5d6cf2011-12-01 00:39:1276 if (type == content::PROCESS_TYPE_RENDERER)
[email protected]2c1978a2011-11-29 17:02:3977 return GetRendererTypeNameInEnglish(rtype);
[email protected]a54311142011-12-01 05:13:4178 return content::GetProcessTypeNameInEnglish(type);
[email protected]2c1978a2011-11-29 17:02:3979}
80
[email protected]8e383412010-10-19 16:57:0381ProcessMemoryInformation::ProcessMemoryInformation()
82 : pid(0),
83 num_processes(0),
84 is_diagnostics(false),
[email protected]bd5d6cf2011-12-01 00:39:1285 type(content::PROCESS_TYPE_UNKNOWN),
[email protected]2c1978a2011-11-29 17:02:3986 renderer_type(RENDERER_UNKNOWN) {
[email protected]8e383412010-10-19 16:57:0387}
88
89ProcessMemoryInformation::~ProcessMemoryInformation() {}
90
[email protected]8e23c882012-05-05 01:14:1191bool ProcessMemoryInformation::operator<(
92 const ProcessMemoryInformation& rhs) const {
93 return working_set.priv < rhs.working_set.priv;
94}
95
[email protected]93aa89c72010-10-20 21:32:0496ProcessData::ProcessData() {}
97
98ProcessData::ProcessData(const ProcessData& rhs)
99 : name(rhs.name),
100 process_name(rhs.process_name),
101 processes(rhs.processes) {
102}
103
104ProcessData::~ProcessData() {}
105
106ProcessData& ProcessData::operator=(const ProcessData& rhs) {
107 name = rhs.name;
108 process_name = rhs.process_name;
109 processes = rhs.processes;
110 return *this;
111}
112
initial.commit09911bf2008-07-26 23:55:29113// About threading:
114//
115// This operation will hit no fewer than 3 threads.
116//
[email protected]8be45842012-04-13 19:49:29117// The BrowserChildProcessHostIterator can only be accessed from the IO thread.
initial.commit09911bf2008-07-26 23:55:29118//
119// The RenderProcessHostIterator can only be accessed from the UI thread.
120//
121// This operation can take 30-100ms to complete. We never want to have
122// one task run for that long on the UI or IO threads. So, we run the
123// expensive parts of this operation over on the file thread.
124//
[email protected]4306df72012-04-20 18:58:57125void MemoryDetails::StartFetch(UserMetricsMode user_metrics_mode) {
[email protected]9bb480ee2011-08-03 21:41:16126 // This might get called from the UI or FILE threads, but should not be
127 // getting called from the IO thread.
[email protected]f8b3ef82010-10-11 02:45:52128 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]4306df72012-04-20 18:58:57129 user_metrics_mode_ = user_metrics_mode;
initial.commit09911bf2008-07-26 23:55:29130
131 // In order to process this request, we need to use the plugin information.
132 // However, plugin process information is only available from the IO thread.
[email protected]f8b3ef82010-10-11 02:45:52133 BrowserThread::PostTask(
134 BrowserThread::IO, FROM_HERE,
[email protected]24d69692011-10-21 18:26:51135 base::Bind(&MemoryDetails::CollectChildInfoOnIOThread, this));
initial.commit09911bf2008-07-26 23:55:29136}
137
[email protected]8e383412010-10-19 16:57:03138MemoryDetails::~MemoryDetails() {}
139
[email protected]4306df72012-04-20 18:58:57140std::string MemoryDetails::ToLogString() {
141 std::string log;
142 log.reserve(4096);
[email protected]8e23c882012-05-05 01:14:11143 ProcessMemoryInformationList processes = ChromeBrowser()->processes;
144 // Sort by memory consumption, low to high.
145 std::sort(processes.begin(), processes.end());
146 // Print from high to low.
147 for (ProcessMemoryInformationList::reverse_iterator iter1 =
148 processes.rbegin();
149 iter1 != processes.rend();
150 ++iter1) {
[email protected]4306df72012-04-20 18:58:57151 log += ProcessMemoryInformation::GetFullTypeNameInEnglish(
152 iter1->type, iter1->renderer_type);
153 if (!iter1->titles.empty()) {
154 log += " [";
155 for (std::vector<string16>::const_iterator iter2 =
156 iter1->titles.begin();
157 iter2 != iter1->titles.end(); ++iter2) {
158 if (iter2 != iter1->titles.begin())
159 log += "|";
160 log += UTF16ToUTF8(*iter2);
161 }
162 log += "]";
163 }
164 log += StringPrintf(" %d MB private, %d MB shared\n",
165 static_cast<int>(iter1->working_set.priv) / 1024,
166 static_cast<int>(iter1->working_set.shared) / 1024);
167 }
168 return log;
169}
170
[email protected]a27a9382009-02-11 23:55:10171void MemoryDetails::CollectChildInfoOnIOThread() {
[email protected]f8b3ef82010-10-11 02:45:52172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
initial.commit09911bf2008-07-26 23:55:29173
[email protected]a27a9382009-02-11 23:55:10174 std::vector<ProcessMemoryInformation> child_info;
175
[email protected]a436d922009-02-13 23:16:42176 // Collect the list of child processes.
[email protected]4967f792012-01-20 22:14:40177 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
[email protected]a27a9382009-02-11 23:55:10178 ProcessMemoryInformation info;
[email protected]4967f792012-01-20 22:14:40179 info.pid = base::GetProcId(iter.GetData().handle);
[email protected]a27a9382009-02-11 23:55:10180 if (!info.pid)
181 continue;
182
[email protected]4967f792012-01-20 22:14:40183 info.type = iter.GetData().type;
[email protected]2c1978a2011-11-29 17:02:39184 info.renderer_type = ProcessMemoryInformation::RENDERER_UNKNOWN;
[email protected]4967f792012-01-20 22:14:40185 info.titles.push_back(iter.GetData().name);
[email protected]a27a9382009-02-11 23:55:10186 child_info.push_back(info);
initial.commit09911bf2008-07-26 23:55:29187 }
188
189 // Now go do expensive memory lookups from the file thread.
[email protected]f8b3ef82010-10-11 02:45:52190 BrowserThread::PostTask(
191 BrowserThread::FILE, FROM_HERE,
[email protected]24d69692011-10-21 18:26:51192 base::Bind(&MemoryDetails::CollectProcessData, this, child_info));
initial.commit09911bf2008-07-26 23:55:29193}
194
[email protected]a27a9382009-02-11 23:55:10195void MemoryDetails::CollectChildInfoOnUIThread() {
[email protected]f8b3ef82010-10-11 02:45:52196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
initial.commit09911bf2008-07-26 23:55:29197
[email protected]a423c9e2012-03-06 18:02:31198#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]c2c68b1f2012-02-25 00:29:15199 const pid_t zygote_pid = content::ZygoteHost::GetInstance()->GetPid();
[email protected]52356d22012-02-29 18:34:20200 const pid_t sandbox_helper_pid =
201 content::ZygoteHost::GetInstance()->GetSandboxHelperPid();
[email protected]54fd1d32009-09-01 00:12:58202#endif
203
204 ProcessData* const chrome_browser = ChromeBrowser();
[email protected]a27a9382009-02-11 23:55:10205 // Get more information about the process.
[email protected]54fd1d32009-09-01 00:12:58206 for (size_t index = 0; index < chrome_browser->processes.size();
initial.commit09911bf2008-07-26 23:55:29207 index++) {
[email protected]a27a9382009-02-11 23:55:10208 // Check if it's a renderer, if so get the list of page titles in it and
[email protected]fcf79352010-12-28 20:13:20209 // check if it's a diagnostics-related process. We skip about:memory pages.
210 // Iterate the RenderProcessHosts to find the tab contents.
[email protected]54fd1d32009-09-01 00:12:58211 ProcessMemoryInformation& process =
212 chrome_browser->processes[index];
213
[email protected]f3b1a082011-11-18 00:34:30214 for (content::RenderProcessHost::iterator renderer_iter(
215 content::RenderProcessHost::AllHostsIterator());
216 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) {
217 content::RenderProcessHost* render_process_host =
218 renderer_iter.GetCurrentValue();
[email protected]fcf79352010-12-28 20:13:20219 DCHECK(render_process_host);
[email protected]8a34e6602010-10-02 17:29:43220 // Ignore processes that don't have a connection, such as crashed tabs.
[email protected]fcf79352010-12-28 20:13:20221 if (!render_process_host->HasConnection() ||
222 process.pid != base::GetProcId(render_process_host->GetHandle())) {
[email protected]a27a9382009-02-11 23:55:10223 continue;
[email protected]201b2732009-11-13 18:57:46224 }
[email protected]bd5d6cf2011-12-01 00:39:12225 process.type = content::PROCESS_TYPE_RENDERER;
[email protected]9b62ecf2011-07-27 20:23:08226 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30227 Profile::FromBrowserContext(
228 render_process_host->GetBrowserContext());
[email protected]79dc42cd2011-01-08 21:43:35229 ExtensionService* extension_service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46230 extensions::ProcessMap* extension_process_map =
231 extension_service->process_map();
[email protected]79dc42cd2011-01-08 21:43:35232
[email protected]0932b30c2012-04-17 13:25:10233 // The RenderProcessHost may host multiple WebContentses. Any
[email protected]a27a9382009-02-11 23:55:10234 // of them which contain diagnostics information make the whole
235 // process be considered a diagnostics process.
[email protected]4b6ebd932012-03-16 08:50:46236 content::RenderProcessHost::RenderWidgetHostsIterator iter(
237 render_process_host->GetRenderWidgetHostsIterator());
[email protected]9de09f82009-08-17 20:13:53238 for (; !iter.IsAtEnd(); iter.Advance()) {
[email protected]4b6ebd932012-03-16 08:50:46239 const RenderWidgetHost* widget = iter.GetCurrentValue();
[email protected]a27a9382009-02-11 23:55:10240 DCHECK(widget);
241 if (!widget || !widget->IsRenderView())
242 continue;
initial.commit09911bf2008-07-26 23:55:29243
[email protected]299d7f12012-05-23 05:31:15244 RenderViewHost* host =
[email protected]9c1662b2012-03-06 15:44:33245 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
[email protected]299d7f12012-05-23 05:31:15246 WebContents* contents = WebContents::FromRenderViewHost(host);
247 GURL url;
248 if (contents)
249 url = contents->GetURL();
250 chrome::ViewType type = chrome::GetViewType(contents);
[email protected]9f76c1e2012-03-05 15:15:58251 if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) {
[email protected]746d3052012-05-22 15:15:47252 process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME;
[email protected]9f76c1e2012-03-05 15:15:58253 } else if (extension_process_map->Contains(
254 host->GetProcess()->GetID())) {
[email protected]6f371442011-11-09 06:45:46255 // For our purposes, don't count processes containing only hosted apps
256 // as extension processes. See also: crbug.com/102533.
257 std::set<std::string> extension_ids =
258 extension_process_map->GetExtensionsInProcess(
[email protected]9f76c1e2012-03-05 15:15:58259 host->GetProcess()->GetID());
[email protected]6f371442011-11-09 06:45:46260 for (std::set<std::string>::iterator iter = extension_ids.begin();
261 iter != extension_ids.end(); ++iter) {
262 const Extension* extension =
263 extension_service->GetExtensionById(*iter, false);
264 if (extension && !extension->is_hosted_app()) {
[email protected]2c1978a2011-11-29 17:02:39265 process.renderer_type =
266 ProcessMemoryInformation::RENDERER_EXTENSION;
[email protected]6f371442011-11-09 06:45:46267 break;
268 }
269 }
[email protected]fcf79352010-12-28 20:13:20270 }
[email protected]299d7f12012-05-23 05:31:15271 if (extension_process_map->Contains(host->GetProcess()->GetID())) {
272 const Extension* extension =
273 extension_service->extensions()->GetByID(url.host());
274 if (extension) {
275 string16 title = UTF8ToUTF16(extension->name());
276 process.titles.push_back(title);
[email protected]04d9cc402012-08-17 22:30:12277 process.renderer_type =
278 ProcessMemoryInformation::RENDERER_EXTENSION;
279 continue;
[email protected]fcf79352010-12-28 20:13:20280 }
[email protected]fcf79352010-12-28 20:13:20281 }
282
[email protected]299d7f12012-05-23 05:31:15283 if (!contents) {
284 process.renderer_type =
285 ProcessMemoryInformation::RENDERER_INTERSTITIAL;
286 continue;
287 }
288
289 if (type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
290 process.titles.push_back(UTF8ToUTF16(url.spec()));
291 process.renderer_type =
292 ProcessMemoryInformation::RENDERER_BACKGROUND_APP;
293 continue;
294 }
295
296 if (type == chrome::VIEW_TYPE_NOTIFICATION) {
297 process.titles.push_back(UTF8ToUTF16(url.spec()));
298 process.renderer_type =
299 ProcessMemoryInformation::RENDERER_NOTIFICATION;
300 continue;
301 }
302
303 // Since we have a WebContents and and the renderer type hasn't been
[email protected]fcf79352010-12-28 20:13:20304 // set yet, it must be a normal tabbed renderer.
[email protected]2c1978a2011-11-29 17:02:39305 if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN)
306 process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL;
[email protected]fcf79352010-12-28 20:13:20307
[email protected]4f260d02010-12-23 18:35:42308 string16 title = contents->GetTitle();
[email protected]a27a9382009-02-11 23:55:10309 if (!title.length())
[email protected]4f260d02010-12-23 18:35:42310 title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
[email protected]a27a9382009-02-11 23:55:10311 process.titles.push_back(title);
[email protected]cd3d7892009-03-04 23:55:06312
[email protected]ebe89e062009-08-13 23:16:54313 // We need to check the pending entry as well as the virtual_url to
[email protected]37ae3f22011-07-12 03:56:14314 // see if it's a chrome://memory URL (we don't want to count these in
315 // the total memory usage of the browser).
[email protected]cd3d7892009-03-04 23:55:06316 //
[email protected]37ae3f22011-07-12 03:56:14317 // When we reach here, chrome://memory will be the pending entry since
318 // we haven't responded with any data such that it would be committed.
319 // If you have another chrome://memory tab open (which would be
320 // committed), we don't want to count it either, so we also check the
321 // last committed entry.
[email protected]cd3d7892009-03-04 23:55:06322 //
323 // Either the pending or last committed entries can be NULL.
[email protected]10f417c52011-12-28 21:04:23324 const NavigationEntry* pending_entry =
[email protected]022af742011-12-28 18:37:25325 contents->GetController().GetPendingEntry();
[email protected]10f417c52011-12-28 21:04:23326 const NavigationEntry* last_committed_entry =
[email protected]f5fa20e2011-12-21 22:35:56327 contents->GetController().GetLastCommittedEntry();
[email protected]cd3d7892009-03-04 23:55:06328 if ((last_committed_entry &&
[email protected]36fc0392011-12-25 03:59:51329 LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(),
[email protected]37ae3f22011-07-12 03:56:14330 chrome::kChromeUIMemoryURL)) ||
[email protected]cd3d7892009-03-04 23:55:06331 (pending_entry &&
[email protected]36fc0392011-12-25 03:59:51332 LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(),
[email protected]37ae3f22011-07-12 03:56:14333 chrome::kChromeUIMemoryURL)))
[email protected]a27a9382009-02-11 23:55:10334 process.is_diagnostics = true;
initial.commit09911bf2008-07-26 23:55:29335 }
336 }
[email protected]54fd1d32009-09-01 00:12:58337
[email protected]a423c9e2012-03-06 18:02:31338#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]54fd1d32009-09-01 00:12:58339 if (process.pid == zygote_pid) {
[email protected]bd5d6cf2011-12-01 00:39:12340 process.type = content::PROCESS_TYPE_ZYGOTE;
[email protected]54fd1d32009-09-01 00:12:58341 } else if (process.pid == sandbox_helper_pid) {
[email protected]bd5d6cf2011-12-01 00:39:12342 process.type = content::PROCESS_TYPE_SANDBOX_HELPER;
[email protected]54fd1d32009-09-01 00:12:58343 }
344#endif
initial.commit09911bf2008-07-26 23:55:29345 }
346
[email protected]a27a9382009-02-11 23:55:10347 // Get rid of other Chrome processes that are from a different profile.
[email protected]54fd1d32009-09-01 00:12:58348 for (size_t index = 0; index < chrome_browser->processes.size();
[email protected]a27a9382009-02-11 23:55:10349 index++) {
[email protected]54fd1d32009-09-01 00:12:58350 if (chrome_browser->processes[index].type ==
[email protected]bd5d6cf2011-12-01 00:39:12351 content::PROCESS_TYPE_UNKNOWN) {
[email protected]54fd1d32009-09-01 00:12:58352 chrome_browser->processes.erase(
353 chrome_browser->processes.begin() + index);
[email protected]a436d922009-02-13 23:16:42354 index--;
[email protected]a27a9382009-02-11 23:55:10355 }
356 }
357
[email protected]4306df72012-04-20 18:58:57358 if (user_metrics_mode_ == UPDATE_USER_METRICS)
359 UpdateHistograms();
initial.commit09911bf2008-07-26 23:55:29360
361 OnDetailsAvailable();
362}
363
364void MemoryDetails::UpdateHistograms() {
365 // Reports a set of memory metrics to UMA.
[email protected]57c4b852009-08-17 21:59:29366 // Memory is measured in KB.
initial.commit09911bf2008-07-26 23:55:29367
[email protected]54fd1d32009-09-01 00:12:58368 const ProcessData& browser = *ChromeBrowser();
initial.commit09911bf2008-07-26 23:55:29369 size_t aggregate_memory = 0;
[email protected]fcf79352010-12-28 20:13:20370 int chrome_count = 0;
371 int extension_count = 0;
[email protected]a27a9382009-02-11 23:55:10372 int plugin_count = 0;
[email protected]eef348fb2011-08-01 21:11:08373 int pepper_plugin_count = 0;
[email protected]fcf79352010-12-28 20:13:20374 int renderer_count = 0;
375 int other_count = 0;
[email protected]a27a9382009-02-11 23:55:10376 int worker_count = 0;
initial.commit09911bf2008-07-26 23:55:29377 for (size_t index = 0; index < browser.processes.size(); index++) {
[email protected]921cd0cc2008-10-21 22:30:55378 int sample = static_cast<int>(browser.processes[index].working_set.priv);
379 aggregate_memory += sample;
[email protected]a27a9382009-02-11 23:55:10380 switch (browser.processes[index].type) {
[email protected]bd5d6cf2011-12-01 00:39:12381 case content::PROCESS_TYPE_BROWSER:
[email protected]f164cea2009-11-05 23:37:40382 UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample);
383 break;
[email protected]bd5d6cf2011-12-01 00:39:12384 case content::PROCESS_TYPE_RENDERER: {
[email protected]2c1978a2011-11-29 17:02:39385 ProcessMemoryInformation::RendererProcessType renderer_type =
[email protected]fcf79352010-12-28 20:13:20386 browser.processes[index].renderer_type;
387 switch (renderer_type) {
[email protected]2c1978a2011-11-29 17:02:39388 case ProcessMemoryInformation::RENDERER_EXTENSION:
[email protected]fcf79352010-12-28 20:13:20389 UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample);
390 extension_count++;
391 break;
[email protected]2c1978a2011-11-29 17:02:39392 case ProcessMemoryInformation::RENDERER_CHROME:
[email protected]fcf79352010-12-28 20:13:20393 UMA_HISTOGRAM_MEMORY_KB("Memory.Chrome", sample);
394 chrome_count++;
395 break;
[email protected]2c1978a2011-11-29 17:02:39396 case ProcessMemoryInformation::RENDERER_UNKNOWN:
[email protected]fcf79352010-12-28 20:13:20397 NOTREACHED() << "Unknown renderer process type.";
398 break;
[email protected]2c1978a2011-11-29 17:02:39399 case ProcessMemoryInformation::RENDERER_NORMAL:
[email protected]fcf79352010-12-28 20:13:20400 default:
401 // TODO(erikkay): Should we bother splitting out the other subtypes?
402 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer", sample);
403 renderer_count++;
404 break;
405 }
[email protected]f164cea2009-11-05 23:37:40406 break;
[email protected]fcf79352010-12-28 20:13:20407 }
[email protected]bd5d6cf2011-12-01 00:39:12408 case content::PROCESS_TYPE_PLUGIN:
[email protected]f164cea2009-11-05 23:37:40409 UMA_HISTOGRAM_MEMORY_KB("Memory.Plugin", sample);
410 plugin_count++;
411 break;
[email protected]bd5d6cf2011-12-01 00:39:12412 case content::PROCESS_TYPE_WORKER:
[email protected]f164cea2009-11-05 23:37:40413 UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample);
414 worker_count++;
415 break;
[email protected]bd5d6cf2011-12-01 00:39:12416 case content::PROCESS_TYPE_UTILITY:
[email protected]f164cea2009-11-05 23:37:40417 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample);
[email protected]fcf79352010-12-28 20:13:20418 other_count++;
[email protected]f164cea2009-11-05 23:37:40419 break;
[email protected]bd5d6cf2011-12-01 00:39:12420 case content::PROCESS_TYPE_ZYGOTE:
[email protected]f164cea2009-11-05 23:37:40421 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample);
[email protected]fcf79352010-12-28 20:13:20422 other_count++;
[email protected]f164cea2009-11-05 23:37:40423 break;
[email protected]bd5d6cf2011-12-01 00:39:12424 case content::PROCESS_TYPE_SANDBOX_HELPER:
[email protected]f164cea2009-11-05 23:37:40425 UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample);
[email protected]fcf79352010-12-28 20:13:20426 other_count++;
[email protected]f164cea2009-11-05 23:37:40427 break;
[email protected]bd5d6cf2011-12-01 00:39:12428 case content::PROCESS_TYPE_NACL_LOADER:
[email protected]f164cea2009-11-05 23:37:40429 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample);
[email protected]fcf79352010-12-28 20:13:20430 other_count++;
[email protected]f164cea2009-11-05 23:37:40431 break;
[email protected]bd5d6cf2011-12-01 00:39:12432 case content::PROCESS_TYPE_NACL_BROKER:
[email protected]aef8d5ae2010-03-17 22:40:52433 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample);
[email protected]fcf79352010-12-28 20:13:20434 other_count++;
[email protected]aef8d5ae2010-03-17 22:40:52435 break;
[email protected]bd5d6cf2011-12-01 00:39:12436 case content::PROCESS_TYPE_GPU:
[email protected]96fcbf2d2010-08-03 16:10:27437 UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample);
[email protected]fcf79352010-12-28 20:13:20438 other_count++;
[email protected]96fcbf2d2010-08-03 16:10:27439 break;
[email protected]bd5d6cf2011-12-01 00:39:12440 case content::PROCESS_TYPE_PPAPI_PLUGIN:
[email protected]eef348fb2011-08-01 21:11:08441 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample);
442 pepper_plugin_count++;
443 break;
[email protected]f164cea2009-11-05 23:37:40444 default:
445 NOTREACHED();
[email protected]eef348fb2011-08-01 21:11:08446 break;
initial.commit09911bf2008-07-26 23:55:29447 }
448 }
[email protected]57c4b852009-08-17 21:59:29449 UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore",
[email protected]0b07be452012-02-29 01:14:42450 RenderWidgetHost::BackingStoreMemorySize() / 1024);
[email protected]a27a9382009-02-11 23:55:10451
[email protected]553dba62009-02-24 19:08:23452 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount",
initial.commit09911bf2008-07-26 23:55:29453 static_cast<int>(browser.processes.size()));
[email protected]fcf79352010-12-28 20:13:20454 UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count);
455 UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count);
456 UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count);
[email protected]553dba62009-02-24 19:08:23457 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count);
[email protected]eef348fb2011-08-01 21:11:08458 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount",
459 pepper_plugin_count);
[email protected]fcf79352010-12-28 20:13:20460 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
[email protected]553dba62009-02-24 19:08:23461 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
[email protected]f164cea2009-11-05 23:37:40462 // TODO(viettrungluu): Do we want separate counts for the other
463 // (platform-specific) process types?
[email protected]921cd0cc2008-10-21 22:30:55464
465 int total_sample = static_cast<int>(aggregate_memory / 1000);
[email protected]553dba62009-02-24 19:08:23466 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample);
initial.commit09911bf2008-07-26 23:55:29467}