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 "chrome/browser/task_management/task_manager_observer.h" | 9 #include "chrome/browser/task_management/task_manager_observer.h" |
10 #include "content/public/browser/browser_child_process_host.h" | 10 #include "content/public/browser/browser_child_process_host.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 inline bool IsResourceRefreshEnabled(RefreshType refresh_type, | 26 inline bool IsResourceRefreshEnabled(RefreshType refresh_type, |
27 int refresh_flags) { | 27 int refresh_flags) { |
28 return (refresh_flags & refresh_type) != 0; | 28 return (refresh_flags & refresh_type) != 0; |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 TaskGroupSampler::TaskGroupSampler( | 33 TaskGroupSampler::TaskGroupSampler( |
34 base::ProcessHandle proc_handle, | 34 base::Process process, |
35 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, | 35 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, |
36 const OnCpuRefreshCallback& on_cpu_refresh, | 36 const OnCpuRefreshCallback& on_cpu_refresh, |
37 const OnMemoryRefreshCallback& on_memory_refresh, | 37 const OnMemoryRefreshCallback& on_memory_refresh, |
38 const OnIdleWakeupsCallback& on_idle_wakeups) | 38 const OnIdleWakeupsCallback& on_idle_wakeups, |
39 : process_metrics_(CreateProcessMetrics(proc_handle)), | 39 const OnProcessPriorityCallback& on_process_priority) |
| 40 : process_(process.Pass()), |
| 41 process_metrics_(CreateProcessMetrics(process_.Handle())), |
40 blocking_pool_runner_(blocking_pool_runner), | 42 blocking_pool_runner_(blocking_pool_runner), |
41 on_cpu_refresh_callback_(on_cpu_refresh), | 43 on_cpu_refresh_callback_(on_cpu_refresh), |
42 on_memory_refresh_callback_(on_memory_refresh), | 44 on_memory_refresh_callback_(on_memory_refresh), |
43 on_idle_wakeups_callback_(on_idle_wakeups) { | 45 on_idle_wakeups_callback_(on_idle_wakeups), |
| 46 on_process_priority_callback_(on_process_priority) { |
44 DCHECK(blocking_pool_runner.get()); | 47 DCHECK(blocking_pool_runner.get()); |
45 | 48 |
46 // This object will be created on the UI thread, however the sequenced checker | 49 // This object will be created on the UI thread, however the sequenced checker |
47 // will be used to assert we're running the expensive operations on one of the | 50 // will be used to assert we're running the expensive operations on one of the |
48 // blocking pool threads. | 51 // blocking pool threads. |
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
50 worker_pool_sequenced_checker_.DetachFromSequence(); | 53 worker_pool_sequenced_checker_.DetachFromSequence(); |
51 } | 54 } |
52 | 55 |
53 void TaskGroupSampler::Refresh(int64 refresh_flags) { | 56 void TaskGroupSampler::Refresh(int64 refresh_flags) { |
(...skipping 17 matching lines...) Expand all Loading... |
71 | 74 |
72 #if defined(OS_MACOSX) || defined(OS_LINUX) | 75 #if defined(OS_MACOSX) || defined(OS_LINUX) |
73 if (IsResourceRefreshEnabled(REFRESH_TYPE_IDLE_WAKEUPS, refresh_flags)) { | 76 if (IsResourceRefreshEnabled(REFRESH_TYPE_IDLE_WAKEUPS, refresh_flags)) { |
74 base::PostTaskAndReplyWithResult( | 77 base::PostTaskAndReplyWithResult( |
75 blocking_pool_runner_.get(), | 78 blocking_pool_runner_.get(), |
76 FROM_HERE, | 79 FROM_HERE, |
77 base::Bind(&TaskGroupSampler::RefreshIdleWakeupsPerSecond, this), | 80 base::Bind(&TaskGroupSampler::RefreshIdleWakeupsPerSecond, this), |
78 on_idle_wakeups_callback_); | 81 on_idle_wakeups_callback_); |
79 } | 82 } |
80 #endif // defined(OS_MACOSX) || defined(OS_LINUX) | 83 #endif // defined(OS_MACOSX) || defined(OS_LINUX) |
| 84 |
| 85 if (IsResourceRefreshEnabled(REFRESH_TYPE_PRIORITY, refresh_flags)) { |
| 86 base::PostTaskAndReplyWithResult( |
| 87 blocking_pool_runner_.get(), |
| 88 FROM_HERE, |
| 89 base::Bind(&TaskGroupSampler::RefreshProcessPriority, this), |
| 90 on_process_priority_callback_); |
| 91 } |
81 } | 92 } |
82 | 93 |
83 TaskGroupSampler::~TaskGroupSampler() { | 94 TaskGroupSampler::~TaskGroupSampler() { |
84 } | 95 } |
85 | 96 |
86 double TaskGroupSampler::RefreshCpuUsage() { | 97 double TaskGroupSampler::RefreshCpuUsage() { |
87 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); | 98 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
88 | 99 |
89 return process_metrics_->GetCPUUsage(); | 100 return process_metrics_->GetCPUUsage(); |
90 } | 101 } |
(...skipping 28 matching lines...) Expand all Loading... |
119 | 130 |
120 return memory_usage; | 131 return memory_usage; |
121 } | 132 } |
122 | 133 |
123 int TaskGroupSampler::RefreshIdleWakeupsPerSecond() { | 134 int TaskGroupSampler::RefreshIdleWakeupsPerSecond() { |
124 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); | 135 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
125 | 136 |
126 return process_metrics_->GetIdleWakeupsPerSecond(); | 137 return process_metrics_->GetIdleWakeupsPerSecond(); |
127 } | 138 } |
128 | 139 |
| 140 bool TaskGroupSampler::RefreshProcessPriority() { |
| 141 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); |
| 142 |
| 143 return process_.IsProcessBackgrounded(); |
| 144 } |
| 145 |
129 } // namespace task_management | 146 } // namespace task_management |
OLD | NEW |