OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/task_management/sampling/task_group_sampler.h" | 5 #include "chrome/browser/task_management/sampling/task_group_sampler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "build/build_config.h" |
9 #include "chrome/browser/task_management/task_manager_observer.h" | 10 #include "chrome/browser/task_management/task_manager_observer.h" |
10 #include "content/public/browser/browser_child_process_host.h" | 11 #include "content/public/browser/browser_child_process_host.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 | 13 |
13 namespace task_management { | 14 namespace task_management { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 base::ProcessMetrics* CreateProcessMetrics(base::ProcessHandle handle) { | 18 base::ProcessMetrics* CreateProcessMetrics(base::ProcessHandle handle) { |
18 #if !defined(OS_MACOSX) | 19 #if !defined(OS_MACOSX) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 on_process_priority_callback_(on_process_priority) { | 53 on_process_priority_callback_(on_process_priority) { |
53 DCHECK(blocking_pool_runner.get()); | 54 DCHECK(blocking_pool_runner.get()); |
54 | 55 |
55 // This object will be created on the UI thread, however the sequenced checker | 56 // This object will be created on the UI thread, however the sequenced checker |
56 // will be used to assert we're running the expensive operations on one of the | 57 // will be used to assert we're running the expensive operations on one of the |
57 // blocking pool threads. | 58 // blocking pool threads. |
58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
59 worker_pool_sequenced_checker_.DetachFromSequence(); | 60 worker_pool_sequenced_checker_.DetachFromSequence(); |
60 } | 61 } |
61 | 62 |
62 void TaskGroupSampler::Refresh(int64 refresh_flags) { | 63 void TaskGroupSampler::Refresh(int64_t refresh_flags) { |
63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 64 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
64 | 65 |
65 if (IsResourceRefreshEnabled(REFRESH_TYPE_CPU, refresh_flags)) { | 66 if (IsResourceRefreshEnabled(REFRESH_TYPE_CPU, refresh_flags)) { |
66 base::PostTaskAndReplyWithResult( | 67 base::PostTaskAndReplyWithResult( |
67 blocking_pool_runner_.get(), | 68 blocking_pool_runner_.get(), |
68 FROM_HERE, | 69 FROM_HERE, |
69 base::Bind(&TaskGroupSampler::RefreshCpuUsage, this), | 70 base::Bind(&TaskGroupSampler::RefreshCpuUsage, this), |
70 on_cpu_refresh_callback_); | 71 on_cpu_refresh_callback_); |
71 } | 72 } |
72 | 73 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 MemoryUsageStats TaskGroupSampler::RefreshMemoryUsage() { | 120 MemoryUsageStats TaskGroupSampler::RefreshMemoryUsage() { |
120 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); | 121 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
121 | 122 |
122 // TODO(afakhry): Integrate Bruce's CL for faster retrieval of physical memory | 123 // TODO(afakhry): Integrate Bruce's CL for faster retrieval of physical memory |
123 // on Windows here. | 124 // on Windows here. |
124 | 125 |
125 MemoryUsageStats memory_usage; | 126 MemoryUsageStats memory_usage; |
126 // Refreshing the physical/private/shared memory at one shot. | 127 // Refreshing the physical/private/shared memory at one shot. |
127 base::WorkingSetKBytes ws_usage; | 128 base::WorkingSetKBytes ws_usage; |
128 if (process_metrics_->GetWorkingSetKBytes(&ws_usage)) { | 129 if (process_metrics_->GetWorkingSetKBytes(&ws_usage)) { |
129 memory_usage.private_bytes = static_cast<int64>(ws_usage.priv * 1024); | 130 memory_usage.private_bytes = static_cast<int64_t>(ws_usage.priv * 1024); |
130 memory_usage.shared_bytes = static_cast<int64>(ws_usage.shared * 1024); | 131 memory_usage.shared_bytes = static_cast<int64_t>(ws_usage.shared * 1024); |
131 #if defined(OS_LINUX) | 132 #if defined(OS_LINUX) |
132 // On Linux private memory is also resident. Just use it. | 133 // On Linux private memory is also resident. Just use it. |
133 memory_usage.physical_bytes = memory_usage.private_bytes; | 134 memory_usage.physical_bytes = memory_usage.private_bytes; |
134 #else | 135 #else |
135 // Memory = working_set.private which is working set minus shareable. This | 136 // Memory = working_set.private which is working set minus shareable. This |
136 // avoids the unpredictable counting that occurs when calculating memory as | 137 // avoids the unpredictable counting that occurs when calculating memory as |
137 // working set minus shared (renderer code counted when one tab is open and | 138 // working set minus shared (renderer code counted when one tab is open and |
138 // not counted when two or more are open) and it is much more efficient to | 139 // not counted when two or more are open) and it is much more efficient to |
139 // calculate on Windows. | 140 // calculate on Windows. |
140 memory_usage.physical_bytes = | 141 memory_usage.physical_bytes = |
141 static_cast<int64>(process_metrics_->GetWorkingSetSize()); | 142 static_cast<int64_t>(process_metrics_->GetWorkingSetSize()); |
142 memory_usage.physical_bytes -= | 143 memory_usage.physical_bytes -= |
143 static_cast<int64>(ws_usage.shareable * 1024); | 144 static_cast<int64_t>(ws_usage.shareable * 1024); |
144 #endif | 145 #endif |
145 } | 146 } |
146 | 147 |
147 return memory_usage; | 148 return memory_usage; |
148 } | 149 } |
149 | 150 |
150 int TaskGroupSampler::RefreshIdleWakeupsPerSecond() { | 151 int TaskGroupSampler::RefreshIdleWakeupsPerSecond() { |
151 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); | 152 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
152 | 153 |
153 return process_metrics_->GetIdleWakeupsPerSecond(); | 154 return process_metrics_->GetIdleWakeupsPerSecond(); |
154 } | 155 } |
155 | 156 |
156 #if defined(OS_LINUX) | 157 #if defined(OS_LINUX) |
157 int TaskGroupSampler::RefreshOpenFdCount() { | 158 int TaskGroupSampler::RefreshOpenFdCount() { |
158 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); | 159 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
159 | 160 |
160 return process_metrics_->GetOpenFdCount(); | 161 return process_metrics_->GetOpenFdCount(); |
161 } | 162 } |
162 #endif // defined(OS_LINUX) | 163 #endif // defined(OS_LINUX) |
163 | 164 |
164 bool TaskGroupSampler::RefreshProcessPriority() { | 165 bool TaskGroupSampler::RefreshProcessPriority() { |
165 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); | 166 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
166 | 167 |
167 return process_.IsProcessBackgrounded(); | 168 return process_.IsProcessBackgrounded(); |
168 } | 169 } |
169 | 170 |
170 } // namespace task_management | 171 } // namespace task_management |
OLD | NEW |