| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include <psapi.h> | 6 #include <psapi.h> |
| 7 | 7 |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/browser/renderer_host/render_process_host.h" | 12 #include "chrome/browser/renderer_host/render_process_host.h" |
| 13 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 13 #include "chrome/browser/tab_contents/web_contents.h" | 14 #include "chrome/browser/tab_contents/web_contents.h" |
| 14 #include "chrome/common/child_process_host.h" | 15 #include "chrome/common/child_process_host.h" |
| 16 #include "chrome/common/url_constants.h" |
| 15 | 17 |
| 16 class RenderViewHostDelegate; | 18 class RenderViewHostDelegate; |
| 17 | 19 |
| 18 // Template of static data we use for finding browser process information. | 20 // Template of static data we use for finding browser process information. |
| 19 // These entries must match the ordering for MemoryDetails::BrowserProcess. | 21 // These entries must match the ordering for MemoryDetails::BrowserProcess. |
| 20 static ProcessData g_process_template[] = { | 22 static ProcessData g_process_template[] = { |
| 21 { L"Chromium", L"chrome.exe", }, | 23 { L"Chromium", L"chrome.exe", }, |
| 22 { L"IE", L"iexplore.exe", }, | 24 { L"IE", L"iexplore.exe", }, |
| 23 { L"Firefox", L"firefox.exe", }, | 25 { L"Firefox", L"firefox.exe", }, |
| 24 { L"Opera", L"opera.exe", }, | 26 { L"Opera", L"opera.exe", }, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 175 |
| 174 void MemoryDetails::CollectChildInfoOnUIThread() { | 176 void MemoryDetails::CollectChildInfoOnUIThread() { |
| 175 DCHECK(MessageLoop::current() == ui_loop_); | 177 DCHECK(MessageLoop::current() == ui_loop_); |
| 176 | 178 |
| 177 // Get more information about the process. | 179 // Get more information about the process. |
| 178 for (size_t index = 0; index < process_data_[CHROME_BROWSER].processes.size(); | 180 for (size_t index = 0; index < process_data_[CHROME_BROWSER].processes.size(); |
| 179 index++) { | 181 index++) { |
| 180 // Check if it's a renderer, if so get the list of page titles in it and | 182 // Check if it's a renderer, if so get the list of page titles in it and |
| 181 // check if it's a diagnostics-related process. We skip all diagnostics | 183 // check if it's a diagnostics-related process. We skip all diagnostics |
| 182 // pages (e.g. "about:xxx" URLs). Iterate the RenderProcessHosts to find | 184 // pages (e.g. "about:xxx" URLs). Iterate the RenderProcessHosts to find |
| 183 // the tab contents. If it is of type TAB_CONTENTS_ABOUT_UI, mark the | 185 // the tab contents. |
| 184 // process as diagnostics related. | |
| 185 RenderProcessHost::iterator renderer_iter; | 186 RenderProcessHost::iterator renderer_iter; |
| 186 for (renderer_iter = RenderProcessHost::begin(); renderer_iter != | 187 for (renderer_iter = RenderProcessHost::begin(); renderer_iter != |
| 187 RenderProcessHost::end(); ++renderer_iter) { | 188 RenderProcessHost::end(); ++renderer_iter) { |
| 188 DCHECK(renderer_iter->second); | 189 DCHECK(renderer_iter->second); |
| 189 ProcessMemoryInformation& process = | 190 ProcessMemoryInformation& process = |
| 190 process_data_[CHROME_BROWSER].processes[index]; | 191 process_data_[CHROME_BROWSER].processes[index]; |
| 191 if (process.pid != renderer_iter->second->process().pid()) | 192 if (process.pid != renderer_iter->second->process().pid()) |
| 192 continue; | 193 continue; |
| 193 process.type = ChildProcessInfo::RENDER_PROCESS; | 194 process.type = ChildProcessInfo::RENDER_PROCESS; |
| 194 // The RenderProcessHost may host multiple TabContents. Any | 195 // The RenderProcessHost may host multiple TabContents. Any |
| (...skipping 15 matching lines...) Expand all Loading... |
| 210 RenderViewHost* host = static_cast<RenderViewHost*>(widget); | 211 RenderViewHost* host = static_cast<RenderViewHost*>(widget); |
| 211 TabContents* contents = NULL; | 212 TabContents* contents = NULL; |
| 212 if (host->delegate()) | 213 if (host->delegate()) |
| 213 contents = host->delegate()->GetAsWebContents(); | 214 contents = host->delegate()->GetAsWebContents(); |
| 214 if (!contents) | 215 if (!contents) |
| 215 continue; | 216 continue; |
| 216 std::wstring title = UTF16ToWideHack(contents->GetTitle()); | 217 std::wstring title = UTF16ToWideHack(contents->GetTitle()); |
| 217 if (!title.length()) | 218 if (!title.length()) |
| 218 title = L"Untitled"; | 219 title = L"Untitled"; |
| 219 process.titles.push_back(title); | 220 process.titles.push_back(title); |
| 220 if (contents->type() == TAB_CONTENTS_ABOUT_UI) | 221 |
| 222 // We need to check the pending entry as well as the pending entry to |
| 223 // see if it's an about:memory URL (we don't want to count these in the |
| 224 // total memory usage of the browser). |
| 225 // |
| 226 // When we reach here, about:memory will be the pending entry since we |
| 227 // haven't responded with any data such that it would be committed. If |
| 228 // you have another about:memory tab open (which would be committed), |
| 229 // we don't want to count it either, so we also check the last committed |
| 230 // entry. |
| 231 // |
| 232 // Either the pending or last committed entries can be NULL. |
| 233 const NavigationEntry* pending_entry = NULL; |
| 234 //contents->controller()->GetPendingEntry(); |
| 235 const NavigationEntry* last_committed_entry = |
| 236 contents->controller()->GetLastCommittedEntry(); |
| 237 if ((last_committed_entry && |
| 238 LowerCaseEqualsASCII(last_committed_entry->display_url().spec(), |
| 239 chrome::kAboutMemoryURL)) || |
| 240 (pending_entry && |
| 241 LowerCaseEqualsASCII(pending_entry->display_url().spec(), |
| 242 chrome::kAboutMemoryURL))) |
| 221 process.is_diagnostics = true; | 243 process.is_diagnostics = true; |
| 222 } | 244 } |
| 223 } | 245 } |
| 224 } | 246 } |
| 225 | 247 |
| 226 // Get rid of other Chrome processes that are from a different profile. | 248 // Get rid of other Chrome processes that are from a different profile. |
| 227 for (size_t index = 0; index < process_data_[CHROME_BROWSER].processes.size(); | 249 for (size_t index = 0; index < process_data_[CHROME_BROWSER].processes.size(); |
| 228 index++) { | 250 index++) { |
| 229 if (process_data_[CHROME_BROWSER].processes[index].type == | 251 if (process_data_[CHROME_BROWSER].processes[index].type == |
| 230 ChildProcessInfo::UNKNOWN_PROCESS) { | 252 ChildProcessInfo::UNKNOWN_PROCESS) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 291 } |
| 270 | 292 |
| 271 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", | 293 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", |
| 272 static_cast<int>(browser.processes.size())); | 294 static_cast<int>(browser.processes.size())); |
| 273 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); | 295 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); |
| 274 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 296 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
| 275 | 297 |
| 276 int total_sample = static_cast<int>(aggregate_memory / 1000); | 298 int total_sample = static_cast<int>(aggregate_memory / 1000); |
| 277 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); | 299 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
| 278 } | 300 } |
| OLD | NEW |