| 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 "app/l10n_util.h" |
| 8 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_thread.h" | 12 #include "chrome/browser/chrome_thread.h" |
| 12 #include "chrome/browser/renderer_host/render_process_host.h" | 13 #include "chrome/browser/renderer_host/render_process_host.h" |
| 13 #include "chrome/browser/tab_contents/navigation_entry.h" | 14 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/child_process_host.h" | 16 #include "chrome/common/child_process_host.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "grit/chromium_strings.h" |
| 17 | 19 |
| 18 class RenderViewHostDelegate; | 20 class RenderViewHostDelegate; |
| 19 | 21 |
| 20 // Template of static data we use for finding browser process information. | 22 // Template of static data we use for finding browser process information. |
| 21 // These entries must match the ordering for MemoryDetails::BrowserProcess. | 23 // These entries must match the ordering for MemoryDetails::BrowserProcess. |
| 22 static ProcessData | 24 static ProcessData g_process_template[MemoryDetails::MAX_BROWSERS]; |
| 23 g_process_template[MemoryDetails::MAX_BROWSERS] = { | |
| 24 { L"Chromium", L"chrome.exe", }, | |
| 25 { L"IE", L"iexplore.exe", }, | |
| 26 { L"Firefox", L"firefox.exe", }, | |
| 27 { L"Opera", L"opera.exe", }, | |
| 28 { L"Safari", L"safari.exe", }, | |
| 29 { L"IE (64bit)", L"iexplore.exe", }, | |
| 30 { L"Konqueror", L"konqueror.exe", }, | |
| 31 }; | |
| 32 | |
| 33 | 25 |
| 34 // About threading: | 26 // About threading: |
| 35 // | 27 // |
| 36 // This operation will hit no fewer than 3 threads. | 28 // This operation will hit no fewer than 3 threads. |
| 37 // | 29 // |
| 38 // The ChildProcessInfo::Iterator can only be accessed from the IO thread. | 30 // The ChildProcessInfo::Iterator can only be accessed from the IO thread. |
| 39 // | 31 // |
| 40 // The RenderProcessHostIterator can only be accessed from the UI thread. | 32 // The RenderProcessHostIterator can only be accessed from the UI thread. |
| 41 // | 33 // |
| 42 // This operation can take 30-100ms to complete. We never want to have | 34 // This operation can take 30-100ms to complete. We never want to have |
| 43 // one task run for that long on the UI or IO threads. So, we run the | 35 // one task run for that long on the UI or IO threads. So, we run the |
| 44 // expensive parts of this operation over on the file thread. | 36 // expensive parts of this operation over on the file thread. |
| 45 // | 37 // |
| 46 | 38 |
| 47 MemoryDetails::MemoryDetails() | 39 MemoryDetails::MemoryDetails() |
| 48 : ui_loop_(NULL) { | 40 : ui_loop_(NULL) { |
| 41 static const std::wstring google_browser_name = |
| 42 l10n_util::GetString(IDS_PRODUCT_NAME); |
| 43 ProcessData g_process_template[MemoryDetails::MAX_BROWSERS] = { |
| 44 { google_browser_name.c_str(), L"chrome.exe", }, |
| 45 { L"IE", L"iexplore.exe", }, |
| 46 { L"Firefox", L"firefox.exe", }, |
| 47 { L"Opera", L"opera.exe", }, |
| 48 { L"Safari", L"safari.exe", }, |
| 49 { L"IE (64bit)", L"iexplore.exe", }, |
| 50 { L"Konqueror", L"konqueror.exe", }, |
| 51 }; |
| 52 |
| 49 for (int index = 0; index < arraysize(g_process_template); ++index) { | 53 for (int index = 0; index < arraysize(g_process_template); ++index) { |
| 50 process_data_[index].name = g_process_template[index].name; | 54 process_data_[index].name = g_process_template[index].name; |
| 51 process_data_[index].process_name = g_process_template[index].process_name; | 55 process_data_[index].process_name = g_process_template[index].process_name; |
| 52 } | 56 } |
| 53 } | 57 } |
| 54 | 58 |
| 55 void MemoryDetails::StartFetch() { | 59 void MemoryDetails::StartFetch() { |
| 56 ui_loop_ = MessageLoop::current(); | 60 ui_loop_ = MessageLoop::current(); |
| 57 | 61 |
| 58 DCHECK(ui_loop_ != g_browser_process->io_thread()->message_loop()); | 62 DCHECK(ui_loop_ != g_browser_process->io_thread()->message_loop()); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 304 } |
| 301 | 305 |
| 302 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", | 306 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", |
| 303 static_cast<int>(browser.processes.size())); | 307 static_cast<int>(browser.processes.size())); |
| 304 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); | 308 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); |
| 305 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 309 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
| 306 | 310 |
| 307 int total_sample = static_cast<int>(aggregate_memory / 1000); | 311 int total_sample = static_cast<int>(aggregate_memory / 1000); |
| 308 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); | 312 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
| 309 } | 313 } |
| OLD | NEW |