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

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: Addess CR questions Created 3 years, 12 months 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 #if defined(OS_WIN)
29 REFRESH_TYPE_START_TIME |
30 REFRESH_TYPE_CPU_TIME |
31 #endif // defined(OS_WIN)
28 #if defined(OS_LINUX) 32 #if defined(OS_LINUX)
29 REFRESH_TYPE_FD_COUNT | 33 REFRESH_TYPE_FD_COUNT |
30 #endif // defined(OS_LINUX) 34 #endif // defined(OS_LINUX)
31 REFRESH_TYPE_PRIORITY; 35 REFRESH_TYPE_PRIORITY;
32 36
33 #if defined(OS_WIN) 37 #if defined(OS_WIN)
34 // Gets the GDI and USER Handles on Windows at one shot. 38 // Gets the GDI and USER Handles on Windows at one shot.
35 void GetWindowsHandles(base::ProcessHandle handle, 39 void GetWindowsHandles(base::ProcessHandle handle,
36 int64_t* out_gdi_current, 40 int64_t* out_gdi_current,
37 int64_t* out_gdi_peak, 41 int64_t* out_gdi_peak,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const scoped_refptr<SharedSampler>& shared_sampler, 73 const scoped_refptr<SharedSampler>& shared_sampler,
70 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) 74 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner)
71 : process_handle_(proc_handle), 75 : process_handle_(proc_handle),
72 process_id_(proc_id), 76 process_id_(proc_id),
73 on_background_calculations_done_(on_background_calculations_done), 77 on_background_calculations_done_(on_background_calculations_done),
74 worker_thread_sampler_(nullptr), 78 worker_thread_sampler_(nullptr),
75 shared_sampler_(shared_sampler), 79 shared_sampler_(shared_sampler),
76 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), 80 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask),
77 current_on_bg_done_flags_(0), 81 current_on_bg_done_flags_(0),
78 cpu_usage_(0.0), 82 cpu_usage_(0.0),
83 start_time_(0),
84 cpu_time_(0),
79 gpu_memory_(-1), 85 gpu_memory_(-1),
80 per_process_network_usage_(-1), 86 per_process_network_usage_(-1),
81 #if defined(OS_WIN) 87 #if defined(OS_WIN)
82 gdi_current_handles_(-1), 88 gdi_current_handles_(-1),
83 gdi_peak_handles_(-1), 89 gdi_peak_handles_(-1),
84 user_current_handles_(-1), 90 user_current_handles_(-1),
85 user_peak_handles_(-1), 91 user_peak_handles_(-1),
86 #endif // defined(OS_WIN) 92 #endif // defined(OS_WIN)
87 #if !defined(DISABLE_NACL) 93 #if !defined(DISABLE_NACL)
88 nacl_debug_stub_port_(-1), 94 nacl_debug_stub_port_(-1),
(...skipping 19 matching lines...) Expand all
108 weak_ptr_factory_.GetWeakPtr()), 114 weak_ptr_factory_.GetWeakPtr()),
109 #endif // defined(OS_LINUX) 115 #endif // defined(OS_LINUX)
110 base::Bind(&TaskGroup::OnProcessPriorityDone, 116 base::Bind(&TaskGroup::OnProcessPriorityDone,
111 weak_ptr_factory_.GetWeakPtr()))); 117 weak_ptr_factory_.GetWeakPtr())));
112 worker_thread_sampler_.swap(sampler); 118 worker_thread_sampler_.swap(sampler);
113 119
114 shared_sampler_->RegisterCallbacks( 120 shared_sampler_->RegisterCallbacks(
115 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, 121 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone,
116 weak_ptr_factory_.GetWeakPtr()), 122 weak_ptr_factory_.GetWeakPtr()),
117 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, 123 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone,
124 weak_ptr_factory_.GetWeakPtr()),
125 base::Bind(&TaskGroup::OnStartTimeRefreshDone,
126 weak_ptr_factory_.GetWeakPtr()),
127 base::Bind(&TaskGroup::OnCpuTimeRefreshDone,
118 weak_ptr_factory_.GetWeakPtr())); 128 weak_ptr_factory_.GetWeakPtr()));
119 } 129 }
120 130
121 TaskGroup::~TaskGroup() { 131 TaskGroup::~TaskGroup() {
122 shared_sampler_->UnregisterCallbacks(process_id_); 132 shared_sampler_->UnregisterCallbacks(process_id_);
123 } 133 }
124 134
125 void TaskGroup::AddTask(Task* task) { 135 void TaskGroup::AddTask(Task* task) {
126 DCHECK(task); 136 DCHECK(task);
127 tasks_.push_back(task); 137 tasks_.push_back(task);
(...skipping 118 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(uint64_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(uint64_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