| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/extensions/extension_process_manager.h" | 14 #include "chrome/browser/extensions/extension_process_manager.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/view_type_utils.h" | 17 #include "chrome/browser/view_type_utils.h" |
| 18 #include "chrome/common/chrome_process_type.h" |
| 18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "content/public/browser/browser_child_process_host_iterator.h" | 21 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/child_process_data.h" | 23 #include "content/public/browser/child_process_data.h" |
| 23 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/bindings_policy.h" | 29 #include "content/public/common/bindings_policy.h" |
| 29 #include "content/public/common/process_type.h" | |
| 30 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 | 33 |
| 34 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 34 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 35 #include "content/public/browser/zygote_host_linux.h" | 35 #include "content/public/browser/zygote_host_linux.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 using base::StringPrintf; | 38 using base::StringPrintf; |
| 39 using content::BrowserChildProcessHostIterator; | 39 using content::BrowserChildProcessHostIterator; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 64 return "Background App"; | 64 return "Background App"; |
| 65 case RENDERER_UNKNOWN: | 65 case RENDERER_UNKNOWN: |
| 66 default: | 66 default: |
| 67 NOTREACHED() << "Unknown renderer process type!"; | 67 NOTREACHED() << "Unknown renderer process type!"; |
| 68 return "Unknown"; | 68 return "Unknown"; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 // static | 72 // static |
| 73 std::string ProcessMemoryInformation::GetFullTypeNameInEnglish( | 73 std::string ProcessMemoryInformation::GetFullTypeNameInEnglish( |
| 74 content::ProcessType type, | 74 int process_type, |
| 75 RendererProcessType rtype) { | 75 RendererProcessType rtype) { |
| 76 if (type == content::PROCESS_TYPE_RENDERER) | 76 if (process_type == content::PROCESS_TYPE_RENDERER) |
| 77 return GetRendererTypeNameInEnglish(rtype); | 77 return GetRendererTypeNameInEnglish(rtype); |
| 78 return content::GetProcessTypeNameInEnglish(type); | 78 return content::GetProcessTypeNameInEnglish(process_type); |
| 79 } | 79 } |
| 80 | 80 |
| 81 ProcessMemoryInformation::ProcessMemoryInformation() | 81 ProcessMemoryInformation::ProcessMemoryInformation() |
| 82 : pid(0), | 82 : pid(0), |
| 83 num_processes(0), | 83 num_processes(0), |
| 84 is_diagnostics(false), | 84 is_diagnostics(false), |
| 85 type(content::PROCESS_TYPE_UNKNOWN), | 85 process_type(content::PROCESS_TYPE_UNKNOWN), |
| 86 renderer_type(RENDERER_UNKNOWN) { | 86 renderer_type(RENDERER_UNKNOWN) { |
| 87 } | 87 } |
| 88 | 88 |
| 89 ProcessMemoryInformation::~ProcessMemoryInformation() {} | 89 ProcessMemoryInformation::~ProcessMemoryInformation() {} |
| 90 | 90 |
| 91 bool ProcessMemoryInformation::operator<( | 91 bool ProcessMemoryInformation::operator<( |
| 92 const ProcessMemoryInformation& rhs) const { | 92 const ProcessMemoryInformation& rhs) const { |
| 93 return working_set.priv < rhs.working_set.priv; | 93 return working_set.priv < rhs.working_set.priv; |
| 94 } | 94 } |
| 95 | 95 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 log.reserve(4096); | 142 log.reserve(4096); |
| 143 ProcessMemoryInformationList processes = ChromeBrowser()->processes; | 143 ProcessMemoryInformationList processes = ChromeBrowser()->processes; |
| 144 // Sort by memory consumption, low to high. | 144 // Sort by memory consumption, low to high. |
| 145 std::sort(processes.begin(), processes.end()); | 145 std::sort(processes.begin(), processes.end()); |
| 146 // Print from high to low. | 146 // Print from high to low. |
| 147 for (ProcessMemoryInformationList::reverse_iterator iter1 = | 147 for (ProcessMemoryInformationList::reverse_iterator iter1 = |
| 148 processes.rbegin(); | 148 processes.rbegin(); |
| 149 iter1 != processes.rend(); | 149 iter1 != processes.rend(); |
| 150 ++iter1) { | 150 ++iter1) { |
| 151 log += ProcessMemoryInformation::GetFullTypeNameInEnglish( | 151 log += ProcessMemoryInformation::GetFullTypeNameInEnglish( |
| 152 iter1->type, iter1->renderer_type); | 152 iter1->process_type, iter1->renderer_type); |
| 153 if (!iter1->titles.empty()) { | 153 if (!iter1->titles.empty()) { |
| 154 log += " ["; | 154 log += " ["; |
| 155 for (std::vector<string16>::const_iterator iter2 = | 155 for (std::vector<string16>::const_iterator iter2 = |
| 156 iter1->titles.begin(); | 156 iter1->titles.begin(); |
| 157 iter2 != iter1->titles.end(); ++iter2) { | 157 iter2 != iter1->titles.end(); ++iter2) { |
| 158 if (iter2 != iter1->titles.begin()) | 158 if (iter2 != iter1->titles.begin()) |
| 159 log += "|"; | 159 log += "|"; |
| 160 log += UTF16ToUTF8(*iter2); | 160 log += UTF16ToUTF8(*iter2); |
| 161 } | 161 } |
| 162 log += "]"; | 162 log += "]"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 176 // Collect the list of child processes. A 0 |handle| means that | 176 // Collect the list of child processes. A 0 |handle| means that |
| 177 // the process is being launched, so we skip it. | 177 // the process is being launched, so we skip it. |
| 178 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { | 178 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { |
| 179 ProcessMemoryInformation info; | 179 ProcessMemoryInformation info; |
| 180 if (!iter.GetData().handle) | 180 if (!iter.GetData().handle) |
| 181 continue; | 181 continue; |
| 182 info.pid = base::GetProcId(iter.GetData().handle); | 182 info.pid = base::GetProcId(iter.GetData().handle); |
| 183 if (!info.pid) | 183 if (!info.pid) |
| 184 continue; | 184 continue; |
| 185 | 185 |
| 186 info.type = iter.GetData().type; | 186 info.process_type = iter.GetData().process_type; |
| 187 info.renderer_type = ProcessMemoryInformation::RENDERER_UNKNOWN; | 187 info.renderer_type = ProcessMemoryInformation::RENDERER_UNKNOWN; |
| 188 info.titles.push_back(iter.GetData().name); | 188 info.titles.push_back(iter.GetData().name); |
| 189 child_info.push_back(info); | 189 child_info.push_back(info); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Now go do expensive memory lookups from the file thread. | 192 // Now go do expensive memory lookups from the file thread. |
| 193 BrowserThread::PostTask( | 193 BrowserThread::PostTask( |
| 194 BrowserThread::FILE, FROM_HERE, | 194 BrowserThread::FILE, FROM_HERE, |
| 195 base::Bind(&MemoryDetails::CollectProcessData, this, child_info)); | 195 base::Bind(&MemoryDetails::CollectProcessData, this, child_info)); |
| 196 } | 196 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 218 content::RenderProcessHost::AllHostsIterator()); | 218 content::RenderProcessHost::AllHostsIterator()); |
| 219 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { | 219 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { |
| 220 content::RenderProcessHost* render_process_host = | 220 content::RenderProcessHost* render_process_host = |
| 221 renderer_iter.GetCurrentValue(); | 221 renderer_iter.GetCurrentValue(); |
| 222 DCHECK(render_process_host); | 222 DCHECK(render_process_host); |
| 223 // Ignore processes that don't have a connection, such as crashed tabs. | 223 // Ignore processes that don't have a connection, such as crashed tabs. |
| 224 if (!render_process_host->HasConnection() || | 224 if (!render_process_host->HasConnection() || |
| 225 process.pid != base::GetProcId(render_process_host->GetHandle())) { | 225 process.pid != base::GetProcId(render_process_host->GetHandle())) { |
| 226 continue; | 226 continue; |
| 227 } | 227 } |
| 228 process.type = content::PROCESS_TYPE_RENDERER; | 228 process.process_type = content::PROCESS_TYPE_RENDERER; |
| 229 Profile* profile = | 229 Profile* profile = |
| 230 Profile::FromBrowserContext( | 230 Profile::FromBrowserContext( |
| 231 render_process_host->GetBrowserContext()); | 231 render_process_host->GetBrowserContext()); |
| 232 ExtensionService* extension_service = profile->GetExtensionService(); | 232 ExtensionService* extension_service = profile->GetExtensionService(); |
| 233 extensions::ProcessMap* extension_process_map = NULL; | 233 extensions::ProcessMap* extension_process_map = NULL; |
| 234 // No extensions on Android. So extension_service can be NULL. | 234 // No extensions on Android. So extension_service can be NULL. |
| 235 if (extension_service) | 235 if (extension_service) |
| 236 extension_process_map = extension_service->process_map(); | 236 extension_process_map = extension_service->process_map(); |
| 237 | 237 |
| 238 // The RenderProcessHost may host multiple WebContentses. Any | 238 // The RenderProcessHost may host multiple WebContentses. Any |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 chrome::kChromeUIMemoryURL)) || | 336 chrome::kChromeUIMemoryURL)) || |
| 337 (pending_entry && | 337 (pending_entry && |
| 338 LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(), | 338 LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(), |
| 339 chrome::kChromeUIMemoryURL))) | 339 chrome::kChromeUIMemoryURL))) |
| 340 process.is_diagnostics = true; | 340 process.is_diagnostics = true; |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 344 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 345 if (process.pid == zygote_pid) { | 345 if (process.pid == zygote_pid) { |
| 346 process.type = content::PROCESS_TYPE_ZYGOTE; | 346 process.process_type = content::PROCESS_TYPE_ZYGOTE; |
| 347 } else if (process.pid == sandbox_helper_pid) { | 347 } else if (process.pid == sandbox_helper_pid) { |
| 348 process.type = content::PROCESS_TYPE_SANDBOX_HELPER; | 348 process.process_type = content::PROCESS_TYPE_SANDBOX_HELPER; |
| 349 } | 349 } |
| 350 #endif | 350 #endif |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Get rid of other Chrome processes that are from a different profile. | 353 // Get rid of other Chrome processes that are from a different profile. |
| 354 for (size_t index = 0; index < chrome_browser->processes.size(); | 354 for (size_t index = 0; index < chrome_browser->processes.size(); |
| 355 index++) { | 355 index++) { |
| 356 if (chrome_browser->processes[index].type == | 356 if (chrome_browser->processes[index].process_type == |
| 357 content::PROCESS_TYPE_UNKNOWN) { | 357 content::PROCESS_TYPE_UNKNOWN) { |
| 358 chrome_browser->processes.erase( | 358 chrome_browser->processes.erase( |
| 359 chrome_browser->processes.begin() + index); | 359 chrome_browser->processes.begin() + index); |
| 360 index--; | 360 index--; |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 if (user_metrics_mode_ == UPDATE_USER_METRICS) | 364 if (user_metrics_mode_ == UPDATE_USER_METRICS) |
| 365 UpdateHistograms(); | 365 UpdateHistograms(); |
| 366 | 366 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 377 int extension_count = 0; | 377 int extension_count = 0; |
| 378 int plugin_count = 0; | 378 int plugin_count = 0; |
| 379 int pepper_plugin_count = 0; | 379 int pepper_plugin_count = 0; |
| 380 int pepper_plugin_broker_count = 0; | 380 int pepper_plugin_broker_count = 0; |
| 381 int renderer_count = 0; | 381 int renderer_count = 0; |
| 382 int other_count = 0; | 382 int other_count = 0; |
| 383 int worker_count = 0; | 383 int worker_count = 0; |
| 384 for (size_t index = 0; index < browser.processes.size(); index++) { | 384 for (size_t index = 0; index < browser.processes.size(); index++) { |
| 385 int sample = static_cast<int>(browser.processes[index].working_set.priv); | 385 int sample = static_cast<int>(browser.processes[index].working_set.priv); |
| 386 aggregate_memory += sample; | 386 aggregate_memory += sample; |
| 387 switch (browser.processes[index].type) { | 387 switch (browser.processes[index].process_type) { |
| 388 case content::PROCESS_TYPE_BROWSER: | 388 case content::PROCESS_TYPE_BROWSER: |
| 389 UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample); | 389 UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample); |
| 390 break; | 390 break; |
| 391 case content::PROCESS_TYPE_RENDERER: { | 391 case content::PROCESS_TYPE_RENDERER: { |
| 392 ProcessMemoryInformation::RendererProcessType renderer_type = | 392 ProcessMemoryInformation::RendererProcessType renderer_type = |
| 393 browser.processes[index].renderer_type; | 393 browser.processes[index].renderer_type; |
| 394 switch (renderer_type) { | 394 switch (renderer_type) { |
| 395 case ProcessMemoryInformation::RENDERER_EXTENSION: | 395 case ProcessMemoryInformation::RENDERER_EXTENSION: |
| 396 UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample); | 396 UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample); |
| 397 extension_count++; | 397 extension_count++; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 425 other_count++; | 425 other_count++; |
| 426 break; | 426 break; |
| 427 case content::PROCESS_TYPE_ZYGOTE: | 427 case content::PROCESS_TYPE_ZYGOTE: |
| 428 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); | 428 UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); |
| 429 other_count++; | 429 other_count++; |
| 430 break; | 430 break; |
| 431 case content::PROCESS_TYPE_SANDBOX_HELPER: | 431 case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 432 UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample); | 432 UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample); |
| 433 other_count++; | 433 other_count++; |
| 434 break; | 434 break; |
| 435 case content::PROCESS_TYPE_NACL_LOADER: | |
| 436 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample); | |
| 437 other_count++; | |
| 438 break; | |
| 439 case content::PROCESS_TYPE_NACL_BROKER: | |
| 440 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample); | |
| 441 other_count++; | |
| 442 break; | |
| 443 case content::PROCESS_TYPE_GPU: | 435 case content::PROCESS_TYPE_GPU: |
| 444 UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample); | 436 UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample); |
| 445 other_count++; | 437 other_count++; |
| 446 break; | 438 break; |
| 447 case content::PROCESS_TYPE_PPAPI_PLUGIN: | 439 case content::PROCESS_TYPE_PPAPI_PLUGIN: |
| 448 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample); | 440 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample); |
| 449 pepper_plugin_count++; | 441 pepper_plugin_count++; |
| 450 break; | 442 break; |
| 451 case content::PROCESS_TYPE_PPAPI_BROKER: | 443 case content::PROCESS_TYPE_PPAPI_BROKER: |
| 452 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPluginBroker", sample); | 444 UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPluginBroker", sample); |
| 453 pepper_plugin_broker_count++; | 445 pepper_plugin_broker_count++; |
| 454 break; | 446 break; |
| 447 case PROCESS_TYPE_NACL_LOADER: |
| 448 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample); |
| 449 other_count++; |
| 450 break; |
| 451 case PROCESS_TYPE_NACL_BROKER: |
| 452 UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample); |
| 453 other_count++; |
| 454 break; |
| 455 default: | 455 default: |
| 456 NOTREACHED(); | 456 NOTREACHED(); |
| 457 break; | 457 break; |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore", | 460 UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore", |
| 461 RenderWidgetHost::BackingStoreMemorySize() / 1024); | 461 RenderWidgetHost::BackingStoreMemorySize() / 1024); |
| 462 #if defined(OS_CHROMEOS) | 462 #if defined(OS_CHROMEOS) |
| 463 // Chrome OS exposes system-wide graphics driver memory which has historically | 463 // Chrome OS exposes system-wide graphics driver memory which has historically |
| 464 // been a source of leak/bloat. | 464 // been a source of leak/bloat. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 478 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount", | 478 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginBrokerProcessCount", |
| 479 pepper_plugin_broker_count); | 479 pepper_plugin_broker_count); |
| 480 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); | 480 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); |
| 481 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 481 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
| 482 // TODO(viettrungluu): Do we want separate counts for the other | 482 // TODO(viettrungluu): Do we want separate counts for the other |
| 483 // (platform-specific) process types? | 483 // (platform-specific) process types? |
| 484 | 484 |
| 485 int total_sample = static_cast<int>(aggregate_memory / 1000); | 485 int total_sample = static_cast<int>(aggregate_memory / 1000); |
| 486 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); | 486 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
| 487 } | 487 } |
| OLD | NEW |