OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_version_info.h" | 7 #include "base/file_version_info.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_child_process_host.h" | 12 #include "chrome/browser/browser_child_process_host.h" |
13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/browser/renderer_host/backing_store_manager.h" | 14 #include "chrome/browser/renderer_host/backing_store_manager.h" |
15 #include "chrome/browser/renderer_host/render_process_host.h" | 15 #include "chrome/browser/renderer_host/render_process_host.h" |
16 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
17 #include "chrome/browser/tab_contents/navigation_entry.h" | 17 #include "chrome/browser/tab_contents/navigation_entry.h" |
18 #include "chrome/browser/tab_contents/tab_contents.h" | 18 #include "chrome/browser/tab_contents/tab_contents.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
21 | 21 |
22 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
23 #include "chrome/browser/zygote_host_linux.h" | 23 #include "chrome/browser/zygote_host_linux.h" |
24 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 24 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
25 #endif | 25 #endif |
26 | 26 |
| 27 ProcessMemoryInformation::ProcessMemoryInformation() |
| 28 : pid(0), |
| 29 num_processes(0), |
| 30 is_diagnostics(false), |
| 31 type(ChildProcessInfo::UNKNOWN_PROCESS) { |
| 32 } |
| 33 |
| 34 ProcessMemoryInformation::~ProcessMemoryInformation() {} |
| 35 |
27 // About threading: | 36 // About threading: |
28 // | 37 // |
29 // This operation will hit no fewer than 3 threads. | 38 // This operation will hit no fewer than 3 threads. |
30 // | 39 // |
31 // The ChildProcessInfo::Iterator can only be accessed from the IO thread. | 40 // The ChildProcessInfo::Iterator can only be accessed from the IO thread. |
32 // | 41 // |
33 // The RenderProcessHostIterator can only be accessed from the UI thread. | 42 // The RenderProcessHostIterator can only be accessed from the UI thread. |
34 // | 43 // |
35 // This operation can take 30-100ms to complete. We never want to have | 44 // This operation can take 30-100ms to complete. We never want to have |
36 // one task run for that long on the UI or IO threads. So, we run the | 45 // one task run for that long on the UI or IO threads. So, we run the |
37 // expensive parts of this operation over on the file thread. | 46 // expensive parts of this operation over on the file thread. |
38 // | 47 // |
39 | |
40 void MemoryDetails::StartFetch() { | 48 void MemoryDetails::StartFetch() { |
41 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 49 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
42 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 50 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
43 | 51 |
44 // In order to process this request, we need to use the plugin information. | 52 // In order to process this request, we need to use the plugin information. |
45 // However, plugin process information is only available from the IO thread. | 53 // However, plugin process information is only available from the IO thread. |
46 BrowserThread::PostTask( | 54 BrowserThread::PostTask( |
47 BrowserThread::IO, FROM_HERE, | 55 BrowserThread::IO, FROM_HERE, |
48 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnIOThread)); | 56 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnIOThread)); |
49 } | 57 } |
50 | 58 |
| 59 MemoryDetails::~MemoryDetails() {} |
| 60 |
51 void MemoryDetails::CollectChildInfoOnIOThread() { | 61 void MemoryDetails::CollectChildInfoOnIOThread() { |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
53 | 63 |
54 std::vector<ProcessMemoryInformation> child_info; | 64 std::vector<ProcessMemoryInformation> child_info; |
55 | 65 |
56 // Collect the list of child processes. | 66 // Collect the list of child processes. |
57 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 67 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
58 ProcessMemoryInformation info; | 68 ProcessMemoryInformation info; |
59 info.pid = base::GetProcId(iter->handle()); | 69 info.pid = base::GetProcId(iter->handle()); |
60 if (!info.pid) | 70 if (!info.pid) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", | 241 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", |
232 static_cast<int>(browser.processes.size())); | 242 static_cast<int>(browser.processes.size())); |
233 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); | 243 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); |
234 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 244 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
235 // TODO(viettrungluu): Do we want separate counts for the other | 245 // TODO(viettrungluu): Do we want separate counts for the other |
236 // (platform-specific) process types? | 246 // (platform-specific) process types? |
237 | 247 |
238 int total_sample = static_cast<int>(aggregate_memory / 1000); | 248 int total_sample = static_cast<int>(aggregate_memory / 1000); |
239 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); | 249 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
240 } | 250 } |
OLD | NEW |