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

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

Issue 10151005: cros: Log per-process memory use on low memory events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months 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
OLDNEW
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/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/extensions/extension_process_manager.h" 14 #include "chrome/browser/extensions/extension_process_manager.h"
14 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_view_type.h" 17 #include "chrome/common/chrome_view_type.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/browser_child_process_host_iterator.h" 20 #include "content/public/browser/browser_child_process_host_iterator.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/child_process_data.h" 22 #include "content/public/browser/child_process_data.h"
22 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/render_view_host_delegate.h" 27 #include "content/public/browser/render_view_host_delegate.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 "content/public/common/process_type.h"
30 #include "grit/chromium_strings.h" 31 #include "grit/chromium_strings.h"
31 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
32 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
33 34
34 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 35 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
35 #include "content/public/browser/zygote_host_linux.h" 36 #include "content/public/browser/zygote_host_linux.h"
36 #endif 37 #endif
37 38
39 using base::StringPrintf;
38 using content::BrowserChildProcessHostIterator; 40 using content::BrowserChildProcessHostIterator;
39 using content::BrowserThread; 41 using content::BrowserThread;
40 using content::NavigationEntry; 42 using content::NavigationEntry;
41 using content::RenderViewHost; 43 using content::RenderViewHost;
42 using content::RenderWidgetHost; 44 using content::RenderWidgetHost;
43 using content::WebContents; 45 using content::WebContents;
44 46
45 // static 47 // static
46 std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish( 48 std::string ProcessMemoryInformation::GetRendererTypeNameInEnglish(
47 RendererProcessType type) { 49 RendererProcessType type) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 124
123 // In order to process this request, we need to use the plugin information. 125 // In order to process this request, we need to use the plugin information.
124 // However, plugin process information is only available from the IO thread. 126 // However, plugin process information is only available from the IO thread.
125 BrowserThread::PostTask( 127 BrowserThread::PostTask(
126 BrowserThread::IO, FROM_HERE, 128 BrowserThread::IO, FROM_HERE,
127 base::Bind(&MemoryDetails::CollectChildInfoOnIOThread, this)); 129 base::Bind(&MemoryDetails::CollectChildInfoOnIOThread, this));
128 } 130 }
129 131
130 MemoryDetails::~MemoryDetails() {} 132 MemoryDetails::~MemoryDetails() {}
131 133
134 std::string MemoryDetails::ToLogString() {
135 std::string log;
136 log.reserve(4096);
137 const ProcessData& chrome = *ChromeBrowser();
138 for (ProcessMemoryInformationList::const_iterator iter1 =
139 chrome.processes.begin();
140 iter1 != chrome.processes.end(); ++iter1) {
141 log += ProcessMemoryInformation::GetFullTypeNameInEnglish(
142 iter1->type, iter1->renderer_type);
143 if (!iter1->titles.empty()) {
144 log += " [";
145 for (std::vector<string16>::const_iterator iter2 =
146 iter1->titles.begin();
147 iter2 != iter1->titles.end(); ++iter2) {
148 if (iter2 != iter1->titles.begin())
149 log += "|";
150 log += UTF16ToUTF8(*iter2);
151 }
152 log += "]";
153 }
154 log += StringPrintf(" %d MB private, %d MB shared\n",
155 static_cast<int>(iter1->working_set.priv) / 1024,
156 static_cast<int>(iter1->working_set.shared) / 1024);
157 }
158 return log;
159 }
160
132 void MemoryDetails::CollectChildInfoOnIOThread() { 161 void MemoryDetails::CollectChildInfoOnIOThread() {
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
134 163
135 std::vector<ProcessMemoryInformation> child_info; 164 std::vector<ProcessMemoryInformation> child_info;
136 165
137 // Collect the list of child processes. 166 // Collect the list of child processes.
138 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { 167 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
139 ProcessMemoryInformation info; 168 ProcessMemoryInformation info;
140 info.pid = base::GetProcId(iter.GetData().handle); 169 info.pid = base::GetProcId(iter.GetData().handle);
141 if (!info.pid) 170 if (!info.pid)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 for (size_t index = 0; index < chrome_browser->processes.size(); 344 for (size_t index = 0; index < chrome_browser->processes.size();
316 index++) { 345 index++) {
317 if (chrome_browser->processes[index].type == 346 if (chrome_browser->processes[index].type ==
318 content::PROCESS_TYPE_UNKNOWN) { 347 content::PROCESS_TYPE_UNKNOWN) {
319 chrome_browser->processes.erase( 348 chrome_browser->processes.erase(
320 chrome_browser->processes.begin() + index); 349 chrome_browser->processes.begin() + index);
321 index--; 350 index--;
322 } 351 }
323 } 352 }
324 353
325 UpdateHistograms();
326
327 OnDetailsAvailable(); 354 OnDetailsAvailable();
328 } 355 }
329 356
330 void MemoryDetails::UpdateHistograms() { 357 void MemoryDetails::UpdateHistograms() {
331 // Reports a set of memory metrics to UMA. 358 // Reports a set of memory metrics to UMA.
332 // Memory is measured in KB. 359 // Memory is measured in KB.
333 360
334 const ProcessData& browser = *ChromeBrowser(); 361 const ProcessData& browser = *ChromeBrowser();
335 size_t aggregate_memory = 0; 362 size_t aggregate_memory = 0;
336 int chrome_count = 0; 363 int chrome_count = 0;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", 451 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount",
425 pepper_plugin_count); 452 pepper_plugin_count);
426 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); 453 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count);
427 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); 454 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count);
428 // TODO(viettrungluu): Do we want separate counts for the other 455 // TODO(viettrungluu): Do we want separate counts for the other
429 // (platform-specific) process types? 456 // (platform-specific) process types?
430 457
431 int total_sample = static_cast<int>(aggregate_memory / 1000); 458 int total_sample = static_cast<int>(aggregate_memory / 1000);
432 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); 459 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample);
433 } 460 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698