Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/memory_details.cc

Issue 8760011: Move the ProcessType enum out to its own file. This is in preparation for getting rid of ChildPro... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/memory_details.h ('k') | chrome/browser/memory_details_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/memory_details.h" 5 #include "chrome/browser/memory_details.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_version_info.h" 8 #include "base/file_version_info.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/extensions/extension_process_manager.h" 13 #include "chrome/browser/extensions/extension_process_manager.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_view_types.h" 16 #include "chrome/common/chrome_view_types.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "content/browser/browser_child_process_host.h" 19 #include "content/browser/browser_child_process_host.h"
20 #include "content/browser/renderer_host/backing_store_manager.h" 20 #include "content/browser/renderer_host/backing_store_manager.h"
21 #include "content/browser/renderer_host/render_view_host.h" 21 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/tab_contents/navigation_entry.h" 22 #include "content/browser/tab_contents/navigation_entry.h"
23 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
24 #include "content/common/child_process_info.h"
24 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
26 #include "content/public/common/bindings_policy.h" 27 #include "content/public/common/bindings_policy.h"
27 #include "grit/chromium_strings.h" 28 #include "grit/chromium_strings.h"
28 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
30 31
31 #if defined(OS_POSIX) && !defined(OS_MACOSX) 32 #if defined(OS_POSIX) && !defined(OS_MACOSX)
32 #include "content/browser/renderer_host/render_sandbox_host_linux.h" 33 #include "content/browser/renderer_host/render_sandbox_host_linux.h"
33 #include "content/browser/zygote_host_linux.h" 34 #include "content/browser/zygote_host_linux.h"
(...skipping 21 matching lines...) Expand all
55 return "Background App"; 56 return "Background App";
56 case RENDERER_UNKNOWN: 57 case RENDERER_UNKNOWN:
57 default: 58 default:
58 NOTREACHED() << "Unknown renderer process type!"; 59 NOTREACHED() << "Unknown renderer process type!";
59 return "Unknown"; 60 return "Unknown";
60 } 61 }
61 } 62 }
62 63
63 // static 64 // static
64 std::string ProcessMemoryInformation::GetFullTypeNameInEnglish( 65 std::string ProcessMemoryInformation::GetFullTypeNameInEnglish(
65 ChildProcessInfo::ProcessType type, 66 content::ProcessType type,
66 RendererProcessType rtype) { 67 RendererProcessType rtype) {
67 if (type == ChildProcessInfo::RENDER_PROCESS) 68 if (type == content::PROCESS_TYPE_RENDERER)
68 return GetRendererTypeNameInEnglish(rtype); 69 return GetRendererTypeNameInEnglish(rtype);
69 return ChildProcessInfo::GetTypeNameInEnglish(type); 70 return ChildProcessInfo::GetTypeNameInEnglish(type);
70 } 71 }
71 72
72 ProcessMemoryInformation::ProcessMemoryInformation() 73 ProcessMemoryInformation::ProcessMemoryInformation()
73 : pid(0), 74 : pid(0),
74 num_processes(0), 75 num_processes(0),
75 is_diagnostics(false), 76 is_diagnostics(false),
76 type(ChildProcessInfo::UNKNOWN_PROCESS), 77 type(content::PROCESS_TYPE_UNKNOWN),
77 renderer_type(RENDERER_UNKNOWN) { 78 renderer_type(RENDERER_UNKNOWN) {
78 } 79 }
79 80
80 ProcessMemoryInformation::~ProcessMemoryInformation() {} 81 ProcessMemoryInformation::~ProcessMemoryInformation() {}
81 82
82 ProcessData::ProcessData() {} 83 ProcessData::ProcessData() {}
83 84
84 ProcessData::ProcessData(const ProcessData& rhs) 85 ProcessData::ProcessData(const ProcessData& rhs)
85 : name(rhs.name), 86 : name(rhs.name),
86 process_name(rhs.process_name), 87 process_name(rhs.process_name),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 content::RenderProcessHost::AllHostsIterator()); 169 content::RenderProcessHost::AllHostsIterator());
169 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { 170 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) {
170 content::RenderProcessHost* render_process_host = 171 content::RenderProcessHost* render_process_host =
171 renderer_iter.GetCurrentValue(); 172 renderer_iter.GetCurrentValue();
172 DCHECK(render_process_host); 173 DCHECK(render_process_host);
173 // Ignore processes that don't have a connection, such as crashed tabs. 174 // Ignore processes that don't have a connection, such as crashed tabs.
174 if (!render_process_host->HasConnection() || 175 if (!render_process_host->HasConnection() ||
175 process.pid != base::GetProcId(render_process_host->GetHandle())) { 176 process.pid != base::GetProcId(render_process_host->GetHandle())) {
176 continue; 177 continue;
177 } 178 }
178 process.type = ChildProcessInfo::RENDER_PROCESS; 179 process.type = content::PROCESS_TYPE_RENDERER;
179 Profile* profile = 180 Profile* profile =
180 Profile::FromBrowserContext( 181 Profile::FromBrowserContext(
181 render_process_host->GetBrowserContext()); 182 render_process_host->GetBrowserContext());
182 ExtensionService* extension_service = profile->GetExtensionService(); 183 ExtensionService* extension_service = profile->GetExtensionService();
183 extensions::ProcessMap* extension_process_map = 184 extensions::ProcessMap* extension_process_map =
184 extension_service->process_map(); 185 extension_service->process_map();
185 186
186 // The RenderProcessHost may host multiple TabContents. Any 187 // The RenderProcessHost may host multiple TabContents. Any
187 // of them which contain diagnostics information make the whole 188 // of them which contain diagnostics information make the whole
188 // process be considered a diagnostics process. 189 // process be considered a diagnostics process.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 chrome::kChromeUIMemoryURL)) || 293 chrome::kChromeUIMemoryURL)) ||
293 (pending_entry && 294 (pending_entry &&
294 LowerCaseEqualsASCII(pending_entry->virtual_url().spec(), 295 LowerCaseEqualsASCII(pending_entry->virtual_url().spec(),
295 chrome::kChromeUIMemoryURL))) 296 chrome::kChromeUIMemoryURL)))
296 process.is_diagnostics = true; 297 process.is_diagnostics = true;
297 } 298 }
298 } 299 }
299 300
300 #if defined(OS_POSIX) && !defined(OS_MACOSX) 301 #if defined(OS_POSIX) && !defined(OS_MACOSX)
301 if (process.pid == zygote_pid) { 302 if (process.pid == zygote_pid) {
302 process.type = ChildProcessInfo::ZYGOTE_PROCESS; 303 process.type = content::PROCESS_TYPE_ZYGOTE;
303 } else if (process.pid == sandbox_helper_pid) { 304 } else if (process.pid == sandbox_helper_pid) {
304 process.type = ChildProcessInfo::SANDBOX_HELPER_PROCESS; 305 process.type = content::PROCESS_TYPE_SANDBOX_HELPER;
305 } 306 }
306 #endif 307 #endif
307 } 308 }
308 309
309 // Get rid of other Chrome processes that are from a different profile. 310 // Get rid of other Chrome processes that are from a different profile.
310 for (size_t index = 0; index < chrome_browser->processes.size(); 311 for (size_t index = 0; index < chrome_browser->processes.size();
311 index++) { 312 index++) {
312 if (chrome_browser->processes[index].type == 313 if (chrome_browser->processes[index].type ==
313 ChildProcessInfo::UNKNOWN_PROCESS) { 314 content::PROCESS_TYPE_UNKNOWN) {
314 chrome_browser->processes.erase( 315 chrome_browser->processes.erase(
315 chrome_browser->processes.begin() + index); 316 chrome_browser->processes.begin() + index);
316 index--; 317 index--;
317 } 318 }
318 } 319 }
319 320
320 UpdateHistograms(); 321 UpdateHistograms();
321 322
322 OnDetailsAvailable(); 323 OnDetailsAvailable();
323 } 324 }
324 325
325 void MemoryDetails::UpdateHistograms() { 326 void MemoryDetails::UpdateHistograms() {
326 // Reports a set of memory metrics to UMA. 327 // Reports a set of memory metrics to UMA.
327 // Memory is measured in KB. 328 // Memory is measured in KB.
328 329
329 const ProcessData& browser = *ChromeBrowser(); 330 const ProcessData& browser = *ChromeBrowser();
330 size_t aggregate_memory = 0; 331 size_t aggregate_memory = 0;
331 int chrome_count = 0; 332 int chrome_count = 0;
332 int extension_count = 0; 333 int extension_count = 0;
333 int plugin_count = 0; 334 int plugin_count = 0;
334 int pepper_plugin_count = 0; 335 int pepper_plugin_count = 0;
335 int renderer_count = 0; 336 int renderer_count = 0;
336 int other_count = 0; 337 int other_count = 0;
337 int worker_count = 0; 338 int worker_count = 0;
338 for (size_t index = 0; index < browser.processes.size(); index++) { 339 for (size_t index = 0; index < browser.processes.size(); index++) {
339 int sample = static_cast<int>(browser.processes[index].working_set.priv); 340 int sample = static_cast<int>(browser.processes[index].working_set.priv);
340 aggregate_memory += sample; 341 aggregate_memory += sample;
341 switch (browser.processes[index].type) { 342 switch (browser.processes[index].type) {
342 case ChildProcessInfo::BROWSER_PROCESS: 343 case content::PROCESS_TYPE_BROWSER:
343 UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample); 344 UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample);
344 break; 345 break;
345 case ChildProcessInfo::RENDER_PROCESS: { 346 case content::PROCESS_TYPE_RENDERER: {
346 ProcessMemoryInformation::RendererProcessType renderer_type = 347 ProcessMemoryInformation::RendererProcessType renderer_type =
347 browser.processes[index].renderer_type; 348 browser.processes[index].renderer_type;
348 switch (renderer_type) { 349 switch (renderer_type) {
349 case ProcessMemoryInformation::RENDERER_EXTENSION: 350 case ProcessMemoryInformation::RENDERER_EXTENSION:
350 UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample); 351 UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample);
351 extension_count++; 352 extension_count++;
352 break; 353 break;
353 case ProcessMemoryInformation::RENDERER_CHROME: 354 case ProcessMemoryInformation::RENDERER_CHROME:
354 UMA_HISTOGRAM_MEMORY_KB("Memory.Chrome", sample); 355 UMA_HISTOGRAM_MEMORY_KB("Memory.Chrome", sample);
355 chrome_count++; 356 chrome_count++;
356 break; 357 break;
357 case ProcessMemoryInformation::RENDERER_UNKNOWN: 358 case ProcessMemoryInformation::RENDERER_UNKNOWN:
358 NOTREACHED() << "Unknown renderer process type."; 359 NOTREACHED() << "Unknown renderer process type.";
359 break; 360 break;
360 case ProcessMemoryInformation::RENDERER_NORMAL: 361 case ProcessMemoryInformation::RENDERER_NORMAL:
361 default: 362 default:
362 // TODO(erikkay): Should we bother splitting out the other subtypes? 363 // TODO(erikkay): Should we bother splitting out the other subtypes?
363 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer", sample); 364 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer", sample);
364 renderer_count++; 365 renderer_count++;
365 break; 366 break;
366 } 367 }
367 break; 368 break;
368 } 369 }
369 case ChildProcessInfo::PLUGIN_PROCESS: 370 case content::PROCESS_TYPE_PLUGIN:
370 UMA_HISTOGRAM_MEMORY_KB("Memory.Plugin", sample); 371 UMA_HISTOGRAM_MEMORY_KB("Memory.Plugin", sample);
371 plugin_count++; 372 plugin_count++;
372 break; 373 break;
373 case ChildProcessInfo::WORKER_PROCESS: 374 case content::PROCESS_TYPE_WORKER:
374 UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample); 375 UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample);
375 worker_count++; 376 worker_count++;
376 break; 377 break;
377 case ChildProcessInfo::UTILITY_PROCESS: 378 case content::PROCESS_TYPE_UTILITY:
378 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample); 379 UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample);
379 other_count++; 380 other_count++;
380 break; 381 break;
381 case ChildProcessInfo::ZYGOTE_PROCESS: 382 case content::PROCESS_TYPE_ZYGOTE:
382 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); 383 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample);
383 other_count++; 384 other_count++;
384 break; 385 break;
385 case ChildProcessInfo::SANDBOX_HELPER_PROCESS: 386 case content::PROCESS_TYPE_SANDBOX_HELPER:
386 UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample); 387 UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample);
387 other_count++; 388 other_count++;
388 break; 389 break;
389 case ChildProcessInfo::NACL_LOADER_PROCESS: 390 case content::PROCESS_TYPE_NACL_LOADER:
390 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample); 391 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample);
391 other_count++; 392 other_count++;
392 break; 393 break;
393 case ChildProcessInfo::NACL_BROKER_PROCESS: 394 case content::PROCESS_TYPE_NACL_BROKER:
394 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample); 395 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample);
395 other_count++; 396 other_count++;
396 break; 397 break;
397 case ChildProcessInfo::GPU_PROCESS: 398 case content::PROCESS_TYPE_GPU:
398 UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample); 399 UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample);
399 other_count++; 400 other_count++;
400 break; 401 break;
401 case ChildProcessInfo::PPAPI_PLUGIN_PROCESS: 402 case content::PROCESS_TYPE_PPAPI_PLUGIN:
402 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample); 403 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample);
403 pepper_plugin_count++; 404 pepper_plugin_count++;
404 break; 405 break;
405 default: 406 default:
406 NOTREACHED(); 407 NOTREACHED();
407 break; 408 break;
408 } 409 }
409 } 410 }
410 UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore", 411 UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore",
411 BackingStoreManager::MemorySize() / 1024); 412 BackingStoreManager::MemorySize() / 1024);
412 413
413 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", 414 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount",
414 static_cast<int>(browser.processes.size())); 415 static_cast<int>(browser.processes.size()));
415 UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count); 416 UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count);
416 UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count); 417 UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count);
417 UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count); 418 UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count);
418 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); 419 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count);
419 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", 420 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount",
420 pepper_plugin_count); 421 pepper_plugin_count);
421 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); 422 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
422 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); 423 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
423 // TODO(viettrungluu): Do we want separate counts for the other 424 // TODO(viettrungluu): Do we want separate counts for the other
424 // (platform-specific) process types? 425 // (platform-specific) process types?
425 426
426 int total_sample = static_cast<int>(aggregate_memory / 1000); 427 int total_sample = static_cast<int>(aggregate_memory / 1000);
427 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); 428 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample);
428 } 429 }
OLDNEW
« no previous file with comments | « chrome/browser/memory_details.h ('k') | chrome/browser/memory_details_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698