Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1557)

Side by Side Diff: chrome/browser/task_manager/sampling/task_group.cc

Issue 2573183002: Add process start time and CPU time columns to task manager (Closed)
Patch Set: Fix nits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_manager/sampling/task_group.h" 5 #include "chrome/browser/task_manager/sampling/task_group.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/task_manager/sampling/shared_sampler.h" 13 #include "chrome/browser/task_manager/sampling/shared_sampler.h"
14 #include "chrome/browser/task_manager/task_manager_observer.h" 14 #include "chrome/browser/task_manager/task_manager_observer.h"
15 #include "components/nacl/browser/nacl_browser.h" 15 #include "components/nacl/browser/nacl_browser.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "gpu/ipc/common/memory_stats.h" 17 #include "gpu/ipc/common/memory_stats.h"
18 18
19 namespace task_manager { 19 namespace task_manager {
20 20
21 namespace { 21 namespace {
22 22
23 // A mask for the refresh types that are done in the background thread. 23 // A mask for the refresh types that are done in the background thread.
24 const int kBackgroundRefreshTypesMask = 24 const int kBackgroundRefreshTypesMask =
25 REFRESH_TYPE_CPU | 25 REFRESH_TYPE_CPU |
26 REFRESH_TYPE_MEMORY | 26 REFRESH_TYPE_MEMORY |
27 REFRESH_TYPE_IDLE_WAKEUPS | 27 REFRESH_TYPE_IDLE_WAKEUPS |
28 REFRESH_TYPE_START_TIME |
29 REFRESH_TYPE_CPU_TIME |
28 #if defined(OS_LINUX) 30 #if defined(OS_LINUX)
29 REFRESH_TYPE_FD_COUNT | 31 REFRESH_TYPE_FD_COUNT |
30 #endif // defined(OS_LINUX) 32 #endif // defined(OS_LINUX)
31 REFRESH_TYPE_PRIORITY; 33 REFRESH_TYPE_PRIORITY;
32 34
33 #if defined(OS_WIN) 35 #if defined(OS_WIN)
34 // Gets the GDI and USER Handles on Windows at one shot. 36 // Gets the GDI and USER Handles on Windows at one shot.
35 void GetWindowsHandles(base::ProcessHandle handle, 37 void GetWindowsHandles(base::ProcessHandle handle,
36 int64_t* out_gdi_current, 38 int64_t* out_gdi_current,
37 int64_t* out_gdi_peak, 39 int64_t* out_gdi_peak,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const scoped_refptr<SharedSampler>& shared_sampler, 71 const scoped_refptr<SharedSampler>& shared_sampler,
70 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) 72 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner)
71 : process_handle_(proc_handle), 73 : process_handle_(proc_handle),
72 process_id_(proc_id), 74 process_id_(proc_id),
73 on_background_calculations_done_(on_background_calculations_done), 75 on_background_calculations_done_(on_background_calculations_done),
74 worker_thread_sampler_(nullptr), 76 worker_thread_sampler_(nullptr),
75 shared_sampler_(shared_sampler), 77 shared_sampler_(shared_sampler),
76 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), 78 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask),
77 current_on_bg_done_flags_(0), 79 current_on_bg_done_flags_(0),
78 cpu_usage_(0.0), 80 cpu_usage_(0.0),
81 start_time_(0),
82 cpu_time_(0),
79 gpu_memory_(-1), 83 gpu_memory_(-1),
80 per_process_network_usage_(-1), 84 per_process_network_usage_(-1),
81 #if defined(OS_WIN) 85 #if defined(OS_WIN)
82 gdi_current_handles_(-1), 86 gdi_current_handles_(-1),
83 gdi_peak_handles_(-1), 87 gdi_peak_handles_(-1),
84 user_current_handles_(-1), 88 user_current_handles_(-1),
85 user_peak_handles_(-1), 89 user_peak_handles_(-1),
86 #endif // defined(OS_WIN) 90 #endif // defined(OS_WIN)
87 #if !defined(DISABLE_NACL) 91 #if !defined(DISABLE_NACL)
88 nacl_debug_stub_port_(-1), 92 nacl_debug_stub_port_(-1),
(...skipping 19 matching lines...) Expand all
108 weak_ptr_factory_.GetWeakPtr()), 112 weak_ptr_factory_.GetWeakPtr()),
109 #endif // defined(OS_LINUX) 113 #endif // defined(OS_LINUX)
110 base::Bind(&TaskGroup::OnProcessPriorityDone, 114 base::Bind(&TaskGroup::OnProcessPriorityDone,
111 weak_ptr_factory_.GetWeakPtr()))); 115 weak_ptr_factory_.GetWeakPtr())));
112 worker_thread_sampler_.swap(sampler); 116 worker_thread_sampler_.swap(sampler);
113 117
114 shared_sampler_->RegisterCallbacks( 118 shared_sampler_->RegisterCallbacks(
115 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, 119 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone,
116 weak_ptr_factory_.GetWeakPtr()), 120 weak_ptr_factory_.GetWeakPtr()),
117 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, 121 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone,
122 weak_ptr_factory_.GetWeakPtr()),
123 base::Bind(&TaskGroup::OnStartTimeRefreshDone,
124 weak_ptr_factory_.GetWeakPtr()),
125 base::Bind(&TaskGroup::OnCpuTimeRefreshDone,
118 weak_ptr_factory_.GetWeakPtr())); 126 weak_ptr_factory_.GetWeakPtr()));
119 } 127 }
120 128
121 TaskGroup::~TaskGroup() { 129 TaskGroup::~TaskGroup() {
122 shared_sampler_->UnregisterCallbacks(process_id_); 130 shared_sampler_->UnregisterCallbacks(process_id_);
123 } 131 }
124 132
125 void TaskGroup::AddTask(Task* task) { 133 void TaskGroup::AddTask(Task* task) {
126 DCHECK(task); 134 DCHECK(task);
127 tasks_.push_back(task); 135 tasks_.push_back(task);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // implementation supports that. The actual work is done on the worker thread. 192 // implementation supports that. The actual work is done on the worker thread.
185 // At the moment this is supported only on OS_WIN. 193 // At the moment this is supported only on OS_WIN.
186 if (shared_refresh_flags != 0) { 194 if (shared_refresh_flags != 0) {
187 shared_sampler_->Refresh(process_id_, shared_refresh_flags); 195 shared_sampler_->Refresh(process_id_, shared_refresh_flags);
188 refresh_flags &= ~shared_refresh_flags; 196 refresh_flags &= ~shared_refresh_flags;
189 } 197 }
190 198
191 // The remaining resource refreshes are time consuming and cannot be done on 199 // The remaining resource refreshes are time consuming and cannot be done on
192 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. 200 // the UI thread. Do them all on the worker thread using the TaskGroupSampler.
193 // 6- CPU usage. 201 // 6- CPU usage.
194 // 7- Memory usage. 202 // 7- Start time.
stanisc 2016/12/19 22:44:10 This is misleading because TaskGroupSampler doesn'
chengx 2016/12/20 00:51:12 I reverted the change.
195 // 8- Idle Wakeups per second. 203 // 8- CPU time.
196 // 9- (Linux and ChromeOS only) The number of file descriptors current open. 204 // 9- Memory usage.
197 // 10- Process priority (foreground vs. background). 205 // 10- Idle Wakeups per second.
206 // 11- (Linux and ChromeOS only) The number of file descriptors current open.
207 // 12- Process priority (foreground vs. background).
198 worker_thread_sampler_->Refresh(refresh_flags); 208 worker_thread_sampler_->Refresh(refresh_flags);
199 } 209 }
200 210
201 Task* TaskGroup::GetTaskById(TaskId task_id) const { 211 Task* TaskGroup::GetTaskById(TaskId task_id) const {
202 for (Task* task : tasks_) { 212 for (Task* task : tasks_) {
203 if (task->task_id() == task_id) 213 if (task->task_id() == task_id)
204 return task; 214 return task;
205 } 215 }
206 NOTREACHED(); 216 NOTREACHED();
207 return nullptr; 217 return nullptr;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 #endif // !defined(DISABLE_NACL) 256 #endif // !defined(DISABLE_NACL)
247 } 257 }
248 258
249 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { 259 void TaskGroup::OnCpuRefreshDone(double cpu_usage) {
250 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
251 261
252 cpu_usage_ = cpu_usage; 262 cpu_usage_ = cpu_usage;
253 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); 263 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU);
254 } 264 }
255 265
266 void TaskGroup::OnStartTimeRefreshDone(int64_t start_time) {
267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
268
269 start_time_ = start_time;
270 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_START_TIME);
271 }
272
273 void TaskGroup::OnCpuTimeRefreshDone(int64_t cpu_time) {
274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
275
276 cpu_time_ = cpu_time;
277 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU_TIME);
278 }
279
256 void TaskGroup::OnPhysicalMemoryUsageRefreshDone(int64_t physical_bytes) { 280 void TaskGroup::OnPhysicalMemoryUsageRefreshDone(int64_t physical_bytes) {
257 #if defined(OS_WIN) 281 #if defined(OS_WIN)
258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 282 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
259 283
260 memory_usage_.physical_bytes = physical_bytes; 284 memory_usage_.physical_bytes = physical_bytes;
261 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_PHYSICAL_MEMORY); 285 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_PHYSICAL_MEMORY);
262 #endif // OS_WIN 286 #endif // OS_WIN
263 } 287 }
264 288
265 void TaskGroup::OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage) { 289 void TaskGroup::OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 324
301 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { 325 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
302 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 326 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
303 327
304 current_on_bg_done_flags_ |= finished_refresh_type; 328 current_on_bg_done_flags_ |= finished_refresh_type;
305 if (AreBackgroundCalculationsDone()) 329 if (AreBackgroundCalculationsDone())
306 on_background_calculations_done_.Run(); 330 on_background_calculations_done_.Run();
307 } 331 }
308 332
309 } // namespace task_manager 333 } // namespace task_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698