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

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

Issue 2178733002: Task manager should support Idle Wakeups on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build error on win_clang Created 4 years, 4 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_management/sampling/task_group.h" 5 #include "chrome/browser/task_management/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_management/sampling/shared_sampler.h"
13 #include "chrome/browser/task_management/task_manager_observer.h" 14 #include "chrome/browser/task_management/task_manager_observer.h"
14 #include "components/nacl/browser/nacl_browser.h" 15 #include "components/nacl/browser/nacl_browser.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "gpu/ipc/common/memory_stats.h" 17 #include "gpu/ipc/common/memory_stats.h"
17 18
18 namespace task_management { 19 namespace task_management {
19 20
20 namespace { 21 namespace {
21 22
22 // 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.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 59 }
59 } 60 }
60 #endif // defined(OS_WIN) 61 #endif // defined(OS_WIN)
61 62
62 } // namespace 63 } // namespace
63 64
64 TaskGroup::TaskGroup( 65 TaskGroup::TaskGroup(
65 base::ProcessHandle proc_handle, 66 base::ProcessHandle proc_handle,
66 base::ProcessId proc_id, 67 base::ProcessId proc_id,
67 const base::Closure& on_background_calculations_done, 68 const base::Closure& on_background_calculations_done,
69 const scoped_refptr<SharedSampler>& shared_sampler,
68 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) 70 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner)
69 : process_handle_(proc_handle), 71 : process_handle_(proc_handle),
70 process_id_(proc_id), 72 process_id_(proc_id),
71 on_background_calculations_done_(on_background_calculations_done), 73 on_background_calculations_done_(on_background_calculations_done),
72 worker_thread_sampler_(nullptr), 74 worker_thread_sampler_(nullptr),
75 shared_sampler_(shared_sampler),
73 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), 76 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask),
74 current_on_bg_done_flags_(0), 77 current_on_bg_done_flags_(0),
75 cpu_usage_(0.0), 78 cpu_usage_(0.0),
76 gpu_memory_(-1), 79 gpu_memory_(-1),
77 per_process_network_usage_(-1), 80 per_process_network_usage_(-1),
78 #if defined(OS_WIN) 81 #if defined(OS_WIN)
79 gdi_current_handles_(-1), 82 gdi_current_handles_(-1),
80 gdi_peak_handles_(-1), 83 gdi_peak_handles_(-1),
81 user_current_handles_(-1), 84 user_current_handles_(-1),
82 user_peak_handles_(-1), 85 user_peak_handles_(-1),
(...skipping 17 matching lines...) Expand all
100 weak_ptr_factory_.GetWeakPtr()), 103 weak_ptr_factory_.GetWeakPtr()),
101 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, 104 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone,
102 weak_ptr_factory_.GetWeakPtr()), 105 weak_ptr_factory_.GetWeakPtr()),
103 #if defined(OS_LINUX) 106 #if defined(OS_LINUX)
104 base::Bind(&TaskGroup::OnOpenFdCountRefreshDone, 107 base::Bind(&TaskGroup::OnOpenFdCountRefreshDone,
105 weak_ptr_factory_.GetWeakPtr()), 108 weak_ptr_factory_.GetWeakPtr()),
106 #endif // defined(OS_LINUX) 109 #endif // defined(OS_LINUX)
107 base::Bind(&TaskGroup::OnProcessPriorityDone, 110 base::Bind(&TaskGroup::OnProcessPriorityDone,
108 weak_ptr_factory_.GetWeakPtr()))); 111 weak_ptr_factory_.GetWeakPtr())));
109 worker_thread_sampler_.swap(sampler); 112 worker_thread_sampler_.swap(sampler);
113
114 shared_sampler_->RegisterCallbacks(
115 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone,
116 weak_ptr_factory_.GetWeakPtr()));
110 } 117 }
111 118
112 TaskGroup::~TaskGroup() { 119 TaskGroup::~TaskGroup() {
120 shared_sampler_->UnregisterCallbacks(process_id_);
113 } 121 }
114 122
115 void TaskGroup::AddTask(Task* task) { 123 void TaskGroup::AddTask(Task* task) {
116 DCHECK(task); 124 DCHECK(task);
117 tasks_.push_back(task); 125 tasks_.push_back(task);
118 } 126 }
119 127
120 void TaskGroup::RemoveTask(Task* task) { 128 void TaskGroup::RemoveTask(Task* task) {
121 DCHECK(task); 129 DCHECK(task);
122 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); 130 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 168
161 // 4- Refresh the NACL debug stub port (if enabled). 169 // 4- Refresh the NACL debug stub port (if enabled).
162 #if !defined(DISABLE_NACL) 170 #if !defined(DISABLE_NACL)
163 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, 171 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL,
164 refresh_flags) && 172 refresh_flags) &&
165 !tasks_.empty()) { 173 !tasks_.empty()) {
166 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); 174 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID());
167 } 175 }
168 #endif // !defined(DISABLE_NACL) 176 #endif // !defined(DISABLE_NACL)
169 177
178 int64_t shared_refresh_flags =
179 refresh_flags & shared_sampler_->GetSupportedFlags();
180
181 // 5- Refresh resources via SharedSampler if the current platform
182 // implementation supports that. The actual work is done on the worker thread.
183 // At the moment this is supported only on OS_WIN.
184 if (shared_refresh_flags != 0) {
185 shared_sampler_->Refresh(process_id_, shared_refresh_flags);
186 refresh_flags &= ~shared_refresh_flags;
187 }
188
170 // The remaining resource refreshes are time consuming and cannot be done on 189 // The remaining resource refreshes are time consuming and cannot be done on
171 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. 190 // the UI thread. Do them all on the worker thread using the TaskGroupSampler.
172 // 5- CPU usage. 191 // 6- CPU usage.
173 // 6- Memory usage. 192 // 7- Memory usage.
174 // 7- Idle Wakeups per second. 193 // 8- Idle Wakeups per second.
175 // 8- (Linux and ChromeOS only) The number of file descriptors current open. 194 // 9- (Linux and ChromeOS only) The number of file descriptors current open.
176 // 9- Process priority (foreground vs. background). 195 // 10- Process priority (foreground vs. background).
177 worker_thread_sampler_->Refresh(refresh_flags); 196 worker_thread_sampler_->Refresh(refresh_flags);
178 } 197 }
179 198
180 Task* TaskGroup::GetTaskById(TaskId task_id) const { 199 Task* TaskGroup::GetTaskById(TaskId task_id) const {
181 for (Task* task : tasks_) { 200 for (Task* task : tasks_) {
182 if (task->task_id() == task_id) 201 if (task->task_id() == task_id)
183 return task; 202 return task;
184 } 203 }
185 NOTREACHED(); 204 NOTREACHED();
186 return nullptr; 205 return nullptr;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 283
265 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { 284 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
266 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 285 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
267 286
268 current_on_bg_done_flags_ |= finished_refresh_type; 287 current_on_bg_done_flags_ |= finished_refresh_type;
269 if (AreBackgroundCalculationsDone()) 288 if (AreBackgroundCalculationsDone())
270 on_background_calculations_done_.Run(); 289 on_background_calculations_done_.Run();
271 } 290 }
272 291
273 } // namespace task_management 292 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/task_management/sampling/task_group.h ('k') | chrome/browser/task_management/sampling/task_group_sampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698