| OLD | NEW |
| 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_process_host.h" | |
| 22 #include "content/browser/renderer_host/render_view_host.h" | 21 #include "content/browser/renderer_host/render_view_host.h" |
| 23 #include "content/browser/tab_contents/navigation_entry.h" | 22 #include "content/browser/tab_contents/navigation_entry.h" |
| 24 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
| 25 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/common/bindings_policy.h" | 26 #include "content/public/common/bindings_policy.h" |
| 27 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 | 30 |
| 31 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 31 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 32 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 32 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| 33 #include "content/browser/zygote_host_linux.h" | 33 #include "content/browser/zygote_host_linux.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ProcessData* const chrome_browser = ChromeBrowser(); | 123 ProcessData* const chrome_browser = ChromeBrowser(); |
| 124 // Get more information about the process. | 124 // Get more information about the process. |
| 125 for (size_t index = 0; index < chrome_browser->processes.size(); | 125 for (size_t index = 0; index < chrome_browser->processes.size(); |
| 126 index++) { | 126 index++) { |
| 127 // Check if it's a renderer, if so get the list of page titles in it and | 127 // Check if it's a renderer, if so get the list of page titles in it and |
| 128 // check if it's a diagnostics-related process. We skip about:memory pages. | 128 // check if it's a diagnostics-related process. We skip about:memory pages. |
| 129 // Iterate the RenderProcessHosts to find the tab contents. | 129 // Iterate the RenderProcessHosts to find the tab contents. |
| 130 ProcessMemoryInformation& process = | 130 ProcessMemoryInformation& process = |
| 131 chrome_browser->processes[index]; | 131 chrome_browser->processes[index]; |
| 132 | 132 |
| 133 for (RenderProcessHost::iterator renderer_iter( | 133 for (content::RenderProcessHost::iterator renderer_iter( |
| 134 RenderProcessHost::AllHostsIterator()); !renderer_iter.IsAtEnd(); | 134 content::RenderProcessHost::AllHostsIterator()); |
| 135 renderer_iter.Advance()) { | 135 !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { |
| 136 RenderProcessHost* render_process_host = renderer_iter.GetCurrentValue(); | 136 content::RenderProcessHost* render_process_host = |
| 137 renderer_iter.GetCurrentValue(); |
| 137 DCHECK(render_process_host); | 138 DCHECK(render_process_host); |
| 138 // Ignore processes that don't have a connection, such as crashed tabs. | 139 // Ignore processes that don't have a connection, such as crashed tabs. |
| 139 if (!render_process_host->HasConnection() || | 140 if (!render_process_host->HasConnection() || |
| 140 process.pid != base::GetProcId(render_process_host->GetHandle())) { | 141 process.pid != base::GetProcId(render_process_host->GetHandle())) { |
| 141 continue; | 142 continue; |
| 142 } | 143 } |
| 143 process.type = ChildProcessInfo::RENDER_PROCESS; | 144 process.type = ChildProcessInfo::RENDER_PROCESS; |
| 144 Profile* profile = | 145 Profile* profile = |
| 145 Profile::FromBrowserContext(render_process_host->browser_context()); | 146 Profile::FromBrowserContext( |
| 147 render_process_host->GetBrowserContext()); |
| 146 ExtensionService* extension_service = profile->GetExtensionService(); | 148 ExtensionService* extension_service = profile->GetExtensionService(); |
| 147 extensions::ProcessMap* extension_process_map = | 149 extensions::ProcessMap* extension_process_map = |
| 148 extension_service->process_map(); | 150 extension_service->process_map(); |
| 149 | 151 |
| 150 // The RenderProcessHost may host multiple TabContents. Any | 152 // The RenderProcessHost may host multiple TabContents. Any |
| 151 // of them which contain diagnostics information make the whole | 153 // of them which contain diagnostics information make the whole |
| 152 // process be considered a diagnostics process. | 154 // process be considered a diagnostics process. |
| 153 // | 155 // |
| 154 // NOTE: This is a bit dangerous. We know that for now, listeners | 156 // NOTE: This is a bit dangerous. We know that for now, listeners |
| 155 // are always RenderWidgetHosts. But in theory, they don't | 157 // are always RenderWidgetHosts. But in theory, they don't |
| 156 // have to be. | 158 // have to be. |
| 157 RenderProcessHost::listeners_iterator iter( | 159 content::RenderProcessHost::listeners_iterator iter( |
| 158 render_process_host->ListenersIterator()); | 160 render_process_host->ListenersIterator()); |
| 159 for (; !iter.IsAtEnd(); iter.Advance()) { | 161 for (; !iter.IsAtEnd(); iter.Advance()) { |
| 160 const RenderWidgetHost* widget = | 162 const RenderWidgetHost* widget = |
| 161 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); | 163 static_cast<const RenderWidgetHost*>(iter.GetCurrentValue()); |
| 162 DCHECK(widget); | 164 DCHECK(widget); |
| 163 if (!widget || !widget->IsRenderView()) | 165 if (!widget || !widget->IsRenderView()) |
| 164 continue; | 166 continue; |
| 165 | 167 |
| 166 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); | 168 const RenderViewHost* host = static_cast<const RenderViewHost*>(widget); |
| 167 RenderViewHostDelegate* host_delegate = host->delegate(); | 169 RenderViewHostDelegate* host_delegate = host->delegate(); |
| 168 DCHECK(host_delegate); | 170 DCHECK(host_delegate); |
| 169 GURL url = host_delegate->GetURL(); | 171 GURL url = host_delegate->GetURL(); |
| 170 content::ViewType type = host_delegate->GetRenderViewType(); | 172 content::ViewType type = host_delegate->GetRenderViewType(); |
| 171 if (host->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI) { | 173 if (host->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI) { |
| 172 // TODO(erikkay) the type for devtools doesn't actually appear to | 174 // TODO(erikkay) the type for devtools doesn't actually appear to |
| 173 // be set. | 175 // be set. |
| 174 if (type == content::VIEW_TYPE_DEV_TOOLS_UI) | 176 if (type == content::VIEW_TYPE_DEV_TOOLS_UI) |
| 175 process.renderer_type = ChildProcessInfo::RENDERER_DEVTOOLS; | 177 process.renderer_type = ChildProcessInfo::RENDERER_DEVTOOLS; |
| 176 else | 178 else |
| 177 process.renderer_type = ChildProcessInfo::RENDERER_CHROME; | 179 process.renderer_type = ChildProcessInfo::RENDERER_CHROME; |
| 178 } else if (extension_process_map->Contains(host->process()->id())) { | 180 } else if (extension_process_map->Contains(host->process()->GetID())) { |
| 179 // For our purposes, don't count processes containing only hosted apps | 181 // For our purposes, don't count processes containing only hosted apps |
| 180 // as extension processes. See also: crbug.com/102533. | 182 // as extension processes. See also: crbug.com/102533. |
| 181 std::set<std::string> extension_ids = | 183 std::set<std::string> extension_ids = |
| 182 extension_process_map->GetExtensionsInProcess( | 184 extension_process_map->GetExtensionsInProcess( |
| 183 host->process()->id()); | 185 host->process()->GetID()); |
| 184 for (std::set<std::string>::iterator iter = extension_ids.begin(); | 186 for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 185 iter != extension_ids.end(); ++iter) { | 187 iter != extension_ids.end(); ++iter) { |
| 186 const Extension* extension = | 188 const Extension* extension = |
| 187 extension_service->GetExtensionById(*iter, false); | 189 extension_service->GetExtensionById(*iter, false); |
| 188 if (extension && !extension->is_hosted_app()) { | 190 if (extension && !extension->is_hosted_app()) { |
| 189 process.renderer_type = ChildProcessInfo::RENDERER_EXTENSION; | 191 process.renderer_type = ChildProcessInfo::RENDERER_EXTENSION; |
| 190 break; | 192 break; |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 TabContents* contents = host_delegate->GetAsTabContents(); | 196 TabContents* contents = host_delegate->GetAsTabContents(); |
| 195 if (!contents) { | 197 if (!contents) { |
| 196 if (extension_process_map->Contains(host->process()->id())) { | 198 if (extension_process_map->Contains(host->process()->GetID())) { |
| 197 const Extension* extension = | 199 const Extension* extension = |
| 198 extension_service->GetExtensionByURL(url); | 200 extension_service->GetExtensionByURL(url); |
| 199 if (extension) { | 201 if (extension) { |
| 200 string16 title = UTF8ToUTF16(extension->name()); | 202 string16 title = UTF8ToUTF16(extension->name()); |
| 201 process.titles.push_back(title); | 203 process.titles.push_back(title); |
| 202 } | 204 } |
| 203 } else if (process.renderer_type == | 205 } else if (process.renderer_type == |
| 204 ChildProcessInfo::RENDERER_UNKNOWN) { | 206 ChildProcessInfo::RENDERER_UNKNOWN) { |
| 205 process.titles.push_back(UTF8ToUTF16(url.spec())); | 207 process.titles.push_back(UTF8ToUTF16(url.spec())); |
| 206 switch (type) { | 208 switch (type) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", | 381 UMA_HISTOGRAM_COUNTS_100("Memory.PepperPluginProcessCount", |
| 380 pepper_plugin_count); | 382 pepper_plugin_count); |
| 381 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); | 383 UMA_HISTOGRAM_COUNTS_100("Memory.RendererProcessCount", renderer_count); |
| 382 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 384 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
| 383 // TODO(viettrungluu): Do we want separate counts for the other | 385 // TODO(viettrungluu): Do we want separate counts for the other |
| 384 // (platform-specific) process types? | 386 // (platform-specific) process types? |
| 385 | 387 |
| 386 int total_sample = static_cast<int>(aggregate_memory / 1000); | 388 int total_sample = static_cast<int>(aggregate_memory / 1000); |
| 387 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); | 389 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
| 388 } | 390 } |
| OLD | NEW |