[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/memory_details.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
| 7 | #include "base/file_version_info.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 8 | #include "base/metrics/histogram.h" |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 9 | #include "base/process_util.h" |
[email protected] | 33b9df4 | 2010-07-29 06:46:39 | [diff] [blame] | 10 | #include "base/string_util.h" |
[email protected] | 64048bd | 2010-03-08 23:28:58 | [diff] [blame] | 11 | #include "base/utf_string_conversions.h" |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_service.h" |
| 13 | #include "chrome/browser/profiles/profile.h" |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 14 | #include "chrome/common/extensions/extension.h" |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 15 | #include "chrome/common/url_constants.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 16 | #include "content/browser/browser_child_process_host.h" |
| 17 | #include "content/browser/browser_thread.h" |
| 18 | #include "content/browser/renderer_host/backing_store_manager.h" |
| 19 | #include "content/browser/renderer_host/render_process_host.h" |
| 20 | #include "content/browser/renderer_host/render_view_host.h" |
| 21 | #include "content/browser/tab_contents/navigation_entry.h" |
| 22 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 23 | #include "content/common/bindings_policy.h" |
[email protected] | ae5ca89 | 2009-07-30 18:00:47 | [diff] [blame] | 24 | #include "grit/chromium_strings.h" |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 25 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 26 | #include "ui/base/l10n/l10n_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 28 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 29 | #include "content/browser/zygote_host_linux.h" |
| 30 | #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 31 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 33 | ProcessMemoryInformation::ProcessMemoryInformation() |
| 34 | : pid(0), |
| 35 | num_processes(0), |
| 36 | is_diagnostics(false), |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 37 | type(ChildProcessInfo::UNKNOWN_PROCESS), |
| 38 | renderer_type(ChildProcessInfo::RENDERER_UNKNOWN) { |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | ProcessMemoryInformation::~ProcessMemoryInformation() {} |
| 42 | |
[email protected] | 93aa89c7 | 2010-10-20 21:32:04 | [diff] [blame] | 43 | ProcessData::ProcessData() {} |
| 44 | |
| 45 | ProcessData::ProcessData(const ProcessData& rhs) |
| 46 | : name(rhs.name), |
| 47 | process_name(rhs.process_name), |
| 48 | processes(rhs.processes) { |
| 49 | } |
| 50 | |
| 51 | ProcessData::~ProcessData() {} |
| 52 | |
| 53 | ProcessData& ProcessData::operator=(const ProcessData& rhs) { |
| 54 | name = rhs.name; |
| 55 | process_name = rhs.process_name; |
| 56 | processes = rhs.processes; |
| 57 | return *this; |
| 58 | } |
| 59 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | // About threading: |
| 61 | // |
| 62 | // This operation will hit no fewer than 3 threads. |
| 63 | // |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 64 | // The ChildProcessInfo::Iterator can only be accessed from the IO thread. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | // |
| 66 | // The RenderProcessHostIterator can only be accessed from the UI thread. |
| 67 | // |
| 68 | // This operation can take 30-100ms to complete. We never want to have |
| 69 | // one task run for that long on the UI or IO threads. So, we run the |
| 70 | // expensive parts of this operation over on the file thread. |
| 71 | // |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 72 | void MemoryDetails::StartFetch() { |
[email protected] | 9bb480ee | 2011-08-03 21:41:16 | [diff] [blame^] | 73 | // This might get called from the UI or FILE threads, but should not be |
| 74 | // getting called from the IO thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 75 | DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 76 | |
| 77 | // In order to process this request, we need to use the plugin information. |
| 78 | // However, plugin process information is only available from the IO thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 79 | BrowserThread::PostTask( |
| 80 | BrowserThread::IO, FROM_HERE, |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 81 | NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnIOThread)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 84 | MemoryDetails::~MemoryDetails() {} |
| 85 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 86 | void MemoryDetails::CollectChildInfoOnIOThread() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 87 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 89 | std::vector<ProcessMemoryInformation> child_info; |
| 90 | |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 91 | // Collect the list of child processes. |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 92 | for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 93 | ProcessMemoryInformation info; |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 94 | info.pid = base::GetProcId(iter->handle()); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 95 | if (!info.pid) |
| 96 | continue; |
| 97 | |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 98 | info.type = iter->type(); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 99 | info.renderer_type = iter->renderer_type(); |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 100 | info.titles.push_back(WideToUTF16Hack(iter->name())); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 101 | child_info.push_back(info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | // Now go do expensive memory lookups from the file thread. |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 105 | BrowserThread::PostTask( |
| 106 | BrowserThread::FILE, FROM_HERE, |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 107 | NewRunnableMethod(this, &MemoryDetails::CollectProcessData, child_info)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 110 | void MemoryDetails::CollectChildInfoOnUIThread() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 111 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 113 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 114 | const pid_t zygote_pid = ZygoteHost::GetInstance()->pid(); |
| 115 | const pid_t sandbox_helper_pid = RenderSandboxHostLinux::GetInstance()->pid(); |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 116 | #endif |
| 117 | |
| 118 | ProcessData* const chrome_browser = ChromeBrowser(); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 119 | // Get more information about the process. |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 120 | for (size_t index = 0; index < chrome_browser->processes.size(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 121 | index++) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 122 | // Check if it's a renderer, if so get the list of page titles in it and |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 123 | // check if it's a diagnostics-related process. We skip about:memory pages. |
| 124 | // Iterate the RenderProcessHosts to find the tab contents. |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 125 | ProcessMemoryInformation& process = |
| 126 | chrome_browser->processes[index]; |
| 127 | |
[email protected] | 019191a | 2009-10-02 20:37:27 | [diff] [blame] | 128 | for (RenderProcessHost::iterator renderer_iter( |
| 129 | RenderProcessHost::AllHostsIterator()); !renderer_iter.IsAtEnd(); |
| 130 | renderer_iter.Advance()) { |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 131 | RenderProcessHost* render_process_host = renderer_iter.GetCurrentValue(); |
| 132 | DCHECK(render_process_host); |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 133 | // Ignore processes that don't have a connection, such as crashed tabs. |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 134 | if (!render_process_host->HasConnection() || |
| 135 | process.pid != base::GetProcId(render_process_host->GetHandle())) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 136 | continue; |
[email protected] | 201b273 | 2009-11-13 18:57:46 | [diff] [blame] | 137 | } |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 138 | process.type = ChildProcessInfo::RENDER_PROCESS; |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 139 | Profile* profile = |
| 140 | Profile::FromBrowserContext(render_process_host->browser_context()); |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 141 | ExtensionService* extension_service = profile->GetExtensionService(); |
| 142 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 143 | // The RenderProcessHost may host multiple TabContents. Any |
| 144 | // of them which contain diagnostics information make the whole |
| 145 | // process be considered a diagnostics process. |
| 146 | // |
| 147 | // NOTE: This is a bit dangerous. We know that for now, listeners |
| 148 | // are always RenderWidgetHosts. But in theory, they don't |
| 149 | // have to be. |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 150 | RenderProcessHost::listeners_iterator iter( |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 151 | render_process_host->ListenersIterator()); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 152 | for (; !iter.IsAtEnd(); iter.Advance()) { |
| 153 | const RenderWidgetHost* widget = |
| 154 | static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 155 | DCHECK(widget); |
| 156 | if (!widget || !widget->IsRenderView()) |
| 157 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 159 | const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 160 | RenderViewHostDelegate* host_delegate = host->delegate(); |
[email protected] | 4e6ffde | 2011-03-11 00:59:27 | [diff] [blame] | 161 | DCHECK(host_delegate); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 162 | GURL url = host_delegate->GetURL(); |
| 163 | ViewType::Type type = host_delegate->GetRenderViewType(); |
[email protected] | c09163a | 2011-02-15 00:05:55 | [diff] [blame] | 164 | if (host->enabled_bindings() & BindingsPolicy::WEB_UI) { |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 165 | // TODO(erikkay) the type for devtools doesn't actually appear to |
| 166 | // be set. |
| 167 | if (type == ViewType::DEV_TOOLS_UI) |
| 168 | process.renderer_type = ChildProcessInfo::RENDERER_DEVTOOLS; |
| 169 | else |
| 170 | process.renderer_type = ChildProcessInfo::RENDERER_CHROME; |
| 171 | } else if (host->enabled_bindings() & BindingsPolicy::EXTENSION) { |
| 172 | process.renderer_type = ChildProcessInfo::RENDERER_EXTENSION; |
| 173 | } |
[email protected] | 4e6ffde | 2011-03-11 00:59:27 | [diff] [blame] | 174 | TabContents* contents = host_delegate->GetAsTabContents(); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 175 | if (!contents) { |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 176 | if (host->process()->is_extension_process()) { |
[email protected] | 79dc42cd | 2011-01-08 21:43:35 | [diff] [blame] | 177 | const Extension* extension = |
| 178 | extension_service->GetExtensionByURL(url); |
| 179 | if (extension) { |
| 180 | string16 title = UTF8ToUTF16(extension->name()); |
| 181 | process.titles.push_back(title); |
| 182 | } |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 183 | } else if (process.renderer_type == |
| 184 | ChildProcessInfo::RENDERER_UNKNOWN) { |
| 185 | process.titles.push_back(UTF8ToUTF16(url.spec())); |
| 186 | switch (type) { |
| 187 | case ViewType::BACKGROUND_CONTENTS: |
| 188 | process.renderer_type = |
| 189 | ChildProcessInfo::RENDERER_BACKGROUND_APP; |
| 190 | break; |
| 191 | case ViewType::INTERSTITIAL_PAGE: |
| 192 | process.renderer_type = ChildProcessInfo::RENDERER_INTERSTITIAL; |
| 193 | break; |
| 194 | case ViewType::NOTIFICATION: |
| 195 | process.renderer_type = ChildProcessInfo::RENDERER_NOTIFICATION; |
| 196 | break; |
| 197 | default: |
| 198 | process.renderer_type = ChildProcessInfo::RENDERER_UNKNOWN; |
| 199 | break; |
| 200 | } |
| 201 | } |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 202 | continue; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | // Since We have a TabContents and and the renderer type hasn't been |
| 206 | // set yet, it must be a normal tabbed renderer. |
| 207 | if (process.renderer_type == ChildProcessInfo::RENDERER_UNKNOWN) |
| 208 | process.renderer_type = ChildProcessInfo::RENDERER_NORMAL; |
| 209 | |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 210 | string16 title = contents->GetTitle(); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 211 | if (!title.length()) |
[email protected] | 4f260d0 | 2010-12-23 18:35:42 | [diff] [blame] | 212 | title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 213 | process.titles.push_back(title); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 214 | |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 215 | // We need to check the pending entry as well as the virtual_url to |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 216 | // see if it's a chrome://memory URL (we don't want to count these in |
| 217 | // the total memory usage of the browser). |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 218 | // |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 219 | // When we reach here, chrome://memory will be the pending entry since |
| 220 | // we haven't responded with any data such that it would be committed. |
| 221 | // If you have another chrome://memory tab open (which would be |
| 222 | // committed), we don't want to count it either, so we also check the |
| 223 | // last committed entry. |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 224 | // |
| 225 | // Either the pending or last committed entries can be NULL. |
[email protected] | 6df4074 | 2009-03-19 22:24:50 | [diff] [blame] | 226 | const NavigationEntry* pending_entry = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 227 | contents->controller().pending_entry(); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 228 | const NavigationEntry* last_committed_entry = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 229 | contents->controller().GetLastCommittedEntry(); |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 230 | if ((last_committed_entry && |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 231 | LowerCaseEqualsASCII(last_committed_entry->virtual_url().spec(), |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 232 | chrome::kChromeUIMemoryURL)) || |
[email protected] | cd3d789 | 2009-03-04 23:55:06 | [diff] [blame] | 233 | (pending_entry && |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 234 | LowerCaseEqualsASCII(pending_entry->virtual_url().spec(), |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 235 | chrome::kChromeUIMemoryURL))) |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 236 | process.is_diagnostics = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | } |
| 238 | } |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 239 | |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 240 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 241 | if (process.pid == zygote_pid) { |
| 242 | process.type = ChildProcessInfo::ZYGOTE_PROCESS; |
| 243 | } else if (process.pid == sandbox_helper_pid) { |
| 244 | process.type = ChildProcessInfo::SANDBOX_HELPER_PROCESS; |
| 245 | } |
| 246 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 247 | } |
| 248 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 249 | // Get rid of other Chrome processes that are from a different profile. |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 250 | for (size_t index = 0; index < chrome_browser->processes.size(); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 251 | index++) { |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 252 | if (chrome_browser->processes[index].type == |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 253 | ChildProcessInfo::UNKNOWN_PROCESS) { |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 254 | chrome_browser->processes.erase( |
| 255 | chrome_browser->processes.begin() + index); |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 256 | index--; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 260 | UpdateHistograms(); |
| 261 | |
| 262 | OnDetailsAvailable(); |
| 263 | } |
| 264 | |
| 265 | void MemoryDetails::UpdateHistograms() { |
| 266 | // Reports a set of memory metrics to UMA. |
[email protected] | 57c4b85 | 2009-08-17 21:59:29 | [diff] [blame] | 267 | // Memory is measured in KB. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 268 | |
[email protected] | 54fd1d3 | 2009-09-01 00:12:58 | [diff] [blame] | 269 | const ProcessData& browser = *ChromeBrowser(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 270 | size_t aggregate_memory = 0; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 271 | int chrome_count = 0; |
| 272 | int extension_count = 0; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 273 | int plugin_count = 0; |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 274 | int pepper_plugin_count = 0; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 275 | int renderer_count = 0; |
| 276 | int other_count = 0; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 277 | int worker_count = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 278 | for (size_t index = 0; index < browser.processes.size(); index++) { |
[email protected] | 921cd0cc | 2008-10-21 22:30:55 | [diff] [blame] | 279 | int sample = static_cast<int>(browser.processes[index].working_set.priv); |
| 280 | aggregate_memory += sample; |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 281 | switch (browser.processes[index].type) { |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 282 | case ChildProcessInfo::BROWSER_PROCESS: |
| 283 | UMA_HISTOGRAM_MEMORY_KB("Memory.Browser", sample); |
| 284 | break; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 285 | case ChildProcessInfo::RENDER_PROCESS: { |
| 286 | ChildProcessInfo::RendererProcessType renderer_type = |
| 287 | browser.processes[index].renderer_type; |
| 288 | switch (renderer_type) { |
| 289 | case ChildProcessInfo::RENDERER_EXTENSION: |
| 290 | UMA_HISTOGRAM_MEMORY_KB("Memory.Extension", sample); |
| 291 | extension_count++; |
| 292 | break; |
| 293 | case ChildProcessInfo::RENDERER_CHROME: |
| 294 | UMA_HISTOGRAM_MEMORY_KB("Memory.Chrome", sample); |
| 295 | chrome_count++; |
| 296 | break; |
| 297 | case ChildProcessInfo::RENDERER_UNKNOWN: |
| 298 | NOTREACHED() << "Unknown renderer process type."; |
| 299 | break; |
| 300 | case ChildProcessInfo::RENDERER_NORMAL: |
| 301 | default: |
| 302 | // TODO(erikkay): Should we bother splitting out the other subtypes? |
| 303 | UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer", sample); |
| 304 | renderer_count++; |
| 305 | break; |
| 306 | } |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 307 | break; |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 308 | } |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 309 | case ChildProcessInfo::PLUGIN_PROCESS: |
| 310 | UMA_HISTOGRAM_MEMORY_KB("Memory.Plugin", sample); |
| 311 | plugin_count++; |
| 312 | break; |
| 313 | case ChildProcessInfo::WORKER_PROCESS: |
| 314 | UMA_HISTOGRAM_MEMORY_KB("Memory.Worker", sample); |
| 315 | worker_count++; |
| 316 | break; |
| 317 | case ChildProcessInfo::UTILITY_PROCESS: |
| 318 | UMA_HISTOGRAM_MEMORY_KB("Memory.Utility", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 319 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 320 | break; |
| 321 | case ChildProcessInfo::ZYGOTE_PROCESS: |
| 322 | UMA_HISTOGRAM_MEMORY_KB("Memory.Zygote", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 323 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 324 | break; |
| 325 | case ChildProcessInfo::SANDBOX_HELPER_PROCESS: |
| 326 | UMA_HISTOGRAM_MEMORY_KB("Memory.SandboxHelper", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 327 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 328 | break; |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 329 | case ChildProcessInfo::NACL_LOADER_PROCESS: |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 330 | UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClient", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 331 | other_count++; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 332 | break; |
[email protected] | aef8d5ae | 2010-03-17 22:40:52 | [diff] [blame] | 333 | case ChildProcessInfo::NACL_BROKER_PROCESS: |
| 334 | UMA_HISTOGRAM_MEMORY_KB("Memory.NativeClientBroker", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 335 | other_count++; |
[email protected] | aef8d5ae | 2010-03-17 22:40:52 | [diff] [blame] | 336 | break; |
[email protected] | 96fcbf2d | 2010-08-03 16:10:27 | [diff] [blame] | 337 | case ChildProcessInfo::GPU_PROCESS: |
| 338 | UMA_HISTOGRAM_MEMORY_KB("Memory.Gpu", sample); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 339 | other_count++; |
[email protected] | 96fcbf2d | 2010-08-03 16:10:27 | [diff] [blame] | 340 | break; |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 341 | case ChildProcessInfo::PPAPI_PLUGIN_PROCESS: |
| 342 | UMA_HISTOGRAM_MEMORY_KB("Memory.PepperPlugin", sample); |
| 343 | pepper_plugin_count++; |
| 344 | break; |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 345 | default: |
| 346 | NOTREACHED(); |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 347 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 348 | } |
| 349 | } |
[email protected] | 57c4b85 | 2009-08-17 21:59:29 | [diff] [blame] | 350 | UMA_HISTOGRAM_MEMORY_KB("Memory.BackingStore", |
| 351 | BackingStoreManager::MemorySize() / 1024); |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 352 | |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 353 | UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 354 | static_cast<int>(browser.processes.size())); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 355 | UMA_HISTOGRAM_COUNTS_100("Memory.ChromeProcessCount", chrome_count); |
| 356 | UMA_HISTOGRAM_COUNTS_100("Memory.ExtensionProcessCount", extension_count); |
| 357 | UMA_HISTOGRAM_COUNTS_100("Memory.OtherProcessCount", other_count); |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 358 | UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); |
[email protected] | eef348fb | 2011-08-01 21:11:08 | [diff] [blame] | 359 | UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", |
| 360 | pepper_plugin_count); |
[email protected] | fcf7935 | 2010-12-28 20:13:20 | [diff] [blame] | 361 | UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 362 | UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
[email protected] | f164cea | 2009-11-05 23:37:40 | [diff] [blame] | 363 | // TODO(viettrungluu): Do we want separate counts for the other |
| 364 | // (platform-specific) process types? |
[email protected] | 921cd0cc | 2008-10-21 22:30:55 | [diff] [blame] | 365 | |
| 366 | int total_sample = static_cast<int>(aggregate_memory / 1000); |
[email protected] | 553dba6 | 2009-02-24 19:08:23 | [diff] [blame] | 367 | UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 368 | } |