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

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

Issue 1374283003: Reporting top cpu and memory consumers via rappor on chromeos (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed arbitrary given weights Created 5 years, 1 month 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_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
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::ProcessId proc_id,
34 base::ProcessHandle proc_handle, 35 base::ProcessHandle proc_handle,
35 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, 36 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner,
36 const OnCpuRefreshCallback& on_cpu_refresh, 37 const OnCpuRefreshCallback& on_cpu_refresh,
37 const OnMemoryRefreshCallback& on_memory_refresh, 38 const OnMemoryRefreshCallback& on_memory_refresh,
38 const OnIdleWakeupsCallback& on_idle_wakeups) 39 const OnIdleWakeupsCallback& on_idle_wakeups,
40 const OnProcessPriorityCallback& on_process_priority)
39 : process_metrics_(CreateProcessMetrics(proc_handle)), 41 : process_metrics_(CreateProcessMetrics(proc_handle)),
40 blocking_pool_runner_(blocking_pool_runner), 42 blocking_pool_runner_(blocking_pool_runner),
43 process_(base::Process::Open(proc_id)),
ncarter (slow) 2015/11/20 18:44:45 If we're doing base::Process::Open here, that give
afakhry 2015/11/21 01:32:58 Thanks for this suggestion. It matches our decisio
41 on_cpu_refresh_callback_(on_cpu_refresh), 44 on_cpu_refresh_callback_(on_cpu_refresh),
42 on_memory_refresh_callback_(on_memory_refresh), 45 on_memory_refresh_callback_(on_memory_refresh),
43 on_idle_wakeups_callback_(on_idle_wakeups) { 46 on_idle_wakeups_callback_(on_idle_wakeups),
47 on_process_priority_callback_(on_process_priority) {
44 DCHECK(blocking_pool_runner.get()); 48 DCHECK(blocking_pool_runner.get());
45 49
46 // This object will be created on the UI thread, however the sequenced checker 50 // 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 51 // will be used to assert we're running the expensive operations on one of the
48 // blocking pool threads. 52 // blocking pool threads.
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
50 worker_pool_sequenced_checker_.DetachFromSequence(); 54 worker_pool_sequenced_checker_.DetachFromSequence();
51 } 55 }
52 56
53 void TaskGroupSampler::Refresh(int64 refresh_flags) { 57 void TaskGroupSampler::Refresh(int64 refresh_flags) {
(...skipping 17 matching lines...) Expand all
71 75
72 #if defined(OS_MACOSX) || defined(OS_LINUX) 76 #if defined(OS_MACOSX) || defined(OS_LINUX)
73 if (IsResourceRefreshEnabled(REFRESH_TYPE_IDLE_WAKEUPS, refresh_flags)) { 77 if (IsResourceRefreshEnabled(REFRESH_TYPE_IDLE_WAKEUPS, refresh_flags)) {
74 base::PostTaskAndReplyWithResult( 78 base::PostTaskAndReplyWithResult(
75 blocking_pool_runner_.get(), 79 blocking_pool_runner_.get(),
76 FROM_HERE, 80 FROM_HERE,
77 base::Bind(&TaskGroupSampler::RefreshIdleWakeupsPerSecond, this), 81 base::Bind(&TaskGroupSampler::RefreshIdleWakeupsPerSecond, this),
78 on_idle_wakeups_callback_); 82 on_idle_wakeups_callback_);
79 } 83 }
80 #endif // defined(OS_MACOSX) || defined(OS_LINUX) 84 #endif // defined(OS_MACOSX) || defined(OS_LINUX)
85
86 if (IsResourceRefreshEnabled(REFRESH_TYPE_PRIORITY, refresh_flags)) {
87 base::PostTaskAndReplyWithResult(
88 blocking_pool_runner_.get(),
89 FROM_HERE,
90 base::Bind(&TaskGroupSampler::RefreshProcessPriority, this),
91 on_process_priority_callback_);
92 }
81 } 93 }
82 94
83 TaskGroupSampler::~TaskGroupSampler() { 95 TaskGroupSampler::~TaskGroupSampler() {
84 } 96 }
85 97
86 double TaskGroupSampler::RefreshCpuUsage() { 98 double TaskGroupSampler::RefreshCpuUsage() {
87 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); 99 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread());
88 100
89 return process_metrics_->GetCPUUsage(); 101 return process_metrics_->GetCPUUsage();
90 } 102 }
(...skipping 28 matching lines...) Expand all
119 131
120 return memory_usage; 132 return memory_usage;
121 } 133 }
122 134
123 int TaskGroupSampler::RefreshIdleWakeupsPerSecond() { 135 int TaskGroupSampler::RefreshIdleWakeupsPerSecond() {
124 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread()); 136 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread());
125 137
126 return process_metrics_->GetIdleWakeupsPerSecond(); 138 return process_metrics_->GetIdleWakeupsPerSecond();
127 } 139 }
128 140
141 bool TaskGroupSampler::RefreshProcessPriority() {
142 DCHECK(worker_pool_sequenced_checker_.CalledOnValidSequencedThread());
143
144 return process_.IsProcessBackgrounded();
145 }
146
129 } // namespace task_management 147 } // namespace task_management
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698