OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.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 "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
13 #include "chrome/browser/renderer_host/backing_store_manager.h" | 12 #include "chrome/browser/renderer_host/backing_store_manager.h" |
14 #include "chrome/browser/renderer_host/render_process_host.h" | 13 #include "chrome/browser/renderer_host/render_process_host.h" |
15 #include "chrome/browser/tab_contents/navigation_entry.h" | 14 #include "chrome/browser/tab_contents/navigation_entry.h" |
16 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
17 #include "chrome/common/child_process_host.h" | 16 #include "chrome/common/child_process_host.h" |
18 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
19 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
20 | 19 |
21 #if defined(OS_LINUX) | 20 #if defined(OS_LINUX) |
22 #include "chrome/browser/zygote_host_linux.h" | 21 #include "chrome/browser/zygote_host_linux.h" |
23 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 22 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
24 #endif | 23 #endif |
25 | 24 |
26 // About threading: | 25 // About threading: |
27 // | 26 // |
28 // This operation will hit no fewer than 3 threads. | 27 // This operation will hit no fewer than 3 threads. |
29 // | 28 // |
30 // The ChildProcessInfo::Iterator can only be accessed from the IO thread. | 29 // The ChildProcessInfo::Iterator can only be accessed from the IO thread. |
31 // | 30 // |
32 // The RenderProcessHostIterator can only be accessed from the UI thread. | 31 // The RenderProcessHostIterator can only be accessed from the UI thread. |
33 // | 32 // |
34 // This operation can take 30-100ms to complete. We never want to have | 33 // This operation can take 30-100ms to complete. We never want to have |
35 // one task run for that long on the UI or IO threads. So, we run the | 34 // one task run for that long on the UI or IO threads. So, we run the |
36 // expensive parts of this operation over on the file thread. | 35 // expensive parts of this operation over on the file thread. |
37 // | 36 // |
38 | 37 |
39 void MemoryDetails::StartFetch() { | 38 void MemoryDetails::StartFetch() { |
40 ui_loop_ = MessageLoop::current(); | 39 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::IO)); |
41 | 40 DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
42 DCHECK(ui_loop_ != g_browser_process->io_thread()->message_loop()); | |
43 DCHECK(ui_loop_ != g_browser_process->file_thread()->message_loop()); | |
44 | 41 |
45 // In order to process this request, we need to use the plugin information. | 42 // In order to process this request, we need to use the plugin information. |
46 // However, plugin process information is only available from the IO thread. | 43 // However, plugin process information is only available from the IO thread. |
47 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, | 44 ChromeThread::PostTask( |
| 45 ChromeThread::IO, FROM_HERE, |
48 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnIOThread)); | 46 NewRunnableMethod(this, &MemoryDetails::CollectChildInfoOnIOThread)); |
49 } | 47 } |
50 | 48 |
51 void MemoryDetails::CollectChildInfoOnIOThread() { | 49 void MemoryDetails::CollectChildInfoOnIOThread() { |
52 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 50 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
53 | 51 |
54 std::vector<ProcessMemoryInformation> child_info; | 52 std::vector<ProcessMemoryInformation> child_info; |
55 | 53 |
56 // Collect the list of child processes. | 54 // Collect the list of child processes. |
57 for (ChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 55 for (ChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
58 ProcessMemoryInformation info; | 56 ProcessMemoryInformation info; |
59 info.pid = base::GetProcId(iter->handle()); | 57 info.pid = base::GetProcId(iter->handle()); |
60 if (!info.pid) | 58 if (!info.pid) |
61 continue; | 59 continue; |
62 | 60 |
63 info.type = iter->type(); | 61 info.type = iter->type(); |
64 info.titles.push_back(iter->name()); | 62 info.titles.push_back(iter->name()); |
65 child_info.push_back(info); | 63 child_info.push_back(info); |
66 } | 64 } |
67 | 65 |
68 // Now go do expensive memory lookups from the file thread. | 66 // Now go do expensive memory lookups from the file thread. |
69 ChromeThread::PostTask( | 67 ChromeThread::PostTask( |
70 ChromeThread::FILE, FROM_HERE, | 68 ChromeThread::FILE, FROM_HERE, |
71 NewRunnableMethod(this, &MemoryDetails::CollectProcessData, child_info)); | 69 NewRunnableMethod(this, &MemoryDetails::CollectProcessData, child_info)); |
72 } | 70 } |
73 | 71 |
74 void MemoryDetails::CollectChildInfoOnUIThread() { | 72 void MemoryDetails::CollectChildInfoOnUIThread() { |
75 DCHECK(MessageLoop::current() == ui_loop_); | 73 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
76 | 74 |
77 #if defined(OS_LINUX) | 75 #if defined(OS_LINUX) |
78 const pid_t zygote_pid = Singleton<ZygoteHost>()->pid(); | 76 const pid_t zygote_pid = Singleton<ZygoteHost>()->pid(); |
79 const pid_t sandbox_helper_pid = Singleton<RenderSandboxHostLinux>()->pid(); | 77 const pid_t sandbox_helper_pid = Singleton<RenderSandboxHostLinux>()->pid(); |
80 #endif | 78 #endif |
81 | 79 |
82 ProcessData* const chrome_browser = ChromeBrowser(); | 80 ProcessData* const chrome_browser = ChromeBrowser(); |
83 // Get more information about the process. | 81 // Get more information about the process. |
84 for (size_t index = 0; index < chrome_browser->processes.size(); | 82 for (size_t index = 0; index < chrome_browser->processes.size(); |
85 index++) { | 83 index++) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 BackingStoreManager::MemorySize() / 1024); | 215 BackingStoreManager::MemorySize() / 1024); |
218 | 216 |
219 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", | 217 UMA_HISTOGRAM_COUNTS_100("Memory.ProcessCount", |
220 static_cast<int>(browser.processes.size())); | 218 static_cast<int>(browser.processes.size())); |
221 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); | 219 UMA_HISTOGRAM_COUNTS_100("Memory.PluginProcessCount", plugin_count); |
222 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); | 220 UMA_HISTOGRAM_COUNTS_100("Memory.WorkerProcessCount", worker_count); |
223 | 221 |
224 int total_sample = static_cast<int>(aggregate_memory / 1000); | 222 int total_sample = static_cast<int>(aggregate_memory / 1000); |
225 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); | 223 UMA_HISTOGRAM_MEMORY_MB("Memory.Total", total_sample); |
226 } | 224 } |
OLD | NEW |