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 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ |
6 #define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ | 6 #define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/process/process.h" |
10 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
11 #include "base/process/process_metrics.h" | 12 #include "base/process/process_metrics.h" |
12 #include "base/sequence_checker.h" | 13 #include "base/sequence_checker.h" |
13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
14 | 15 |
15 namespace task_management { | 16 namespace task_management { |
16 | 17 |
17 // Wraps the memory usage stats values together so that it can be sent between | 18 // Wraps the memory usage stats values together so that it can be sent between |
18 // the UI and the worker threads. | 19 // the UI and the worker threads. |
19 struct MemoryUsageStats { | 20 struct MemoryUsageStats { |
(...skipping 12 matching lines...) Expand all Loading... |
32 // resources on the worker thread. Objects of this class are created by the | 33 // resources on the worker thread. Objects of this class are created by the |
33 // TaskGroups on the UI thread, however it will be used mainly on a blocking | 34 // TaskGroups on the UI thread, however it will be used mainly on a blocking |
34 // pool thread. | 35 // pool thread. |
35 class TaskGroupSampler : public base::RefCountedThreadSafe<TaskGroupSampler> { | 36 class TaskGroupSampler : public base::RefCountedThreadSafe<TaskGroupSampler> { |
36 public: | 37 public: |
37 // The below are the types of the callbacks to the UI thread upon their | 38 // The below are the types of the callbacks to the UI thread upon their |
38 // corresponding refresh are done on the worker thread. | 39 // corresponding refresh are done on the worker thread. |
39 using OnCpuRefreshCallback = base::Callback<void(double)>; | 40 using OnCpuRefreshCallback = base::Callback<void(double)>; |
40 using OnMemoryRefreshCallback = base::Callback<void(MemoryUsageStats)>; | 41 using OnMemoryRefreshCallback = base::Callback<void(MemoryUsageStats)>; |
41 using OnIdleWakeupsCallback = base::Callback<void(int)>; | 42 using OnIdleWakeupsCallback = base::Callback<void(int)>; |
| 43 using OnProcessPriorityCallback = base::Callback<void(bool)>; |
42 | 44 |
43 TaskGroupSampler( | 45 TaskGroupSampler( |
44 base::ProcessHandle proc_handle, | 46 base::Process process, |
45 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, | 47 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, |
46 const OnCpuRefreshCallback& on_cpu_refresh, | 48 const OnCpuRefreshCallback& on_cpu_refresh, |
47 const OnMemoryRefreshCallback& on_memory_refresh, | 49 const OnMemoryRefreshCallback& on_memory_refresh, |
48 const OnIdleWakeupsCallback& on_idle_wakeups); | 50 const OnIdleWakeupsCallback& on_idle_wakeups, |
| 51 const OnProcessPriorityCallback& on_process_priority); |
49 | 52 |
50 // Refreshes the expensive process' stats (CPU usage, memory usage, and idle | 53 // Refreshes the expensive process' stats (CPU usage, memory usage, and idle |
51 // wakeups per second) on the worker thread. | 54 // wakeups per second) on the worker thread. |
52 void Refresh(int64 refresh_flags); | 55 void Refresh(int64 refresh_flags); |
53 | 56 |
54 private: | 57 private: |
55 friend class base::RefCountedThreadSafe<TaskGroupSampler>; | 58 friend class base::RefCountedThreadSafe<TaskGroupSampler>; |
56 ~TaskGroupSampler(); | 59 ~TaskGroupSampler(); |
57 | 60 |
58 // The refresh calls that will be done on the worker thread. | 61 // The refresh calls that will be done on the worker thread. |
59 double RefreshCpuUsage(); | 62 double RefreshCpuUsage(); |
60 MemoryUsageStats RefreshMemoryUsage(); | 63 MemoryUsageStats RefreshMemoryUsage(); |
61 int RefreshIdleWakeupsPerSecond(); | 64 int RefreshIdleWakeupsPerSecond(); |
| 65 bool RefreshProcessPriority(); |
| 66 |
| 67 // The process that holds the handle that we own so that we can use it for |
| 68 // creating the ProcessMetrics. |
| 69 base::Process process_; |
62 | 70 |
63 scoped_ptr<base::ProcessMetrics> process_metrics_; | 71 scoped_ptr<base::ProcessMetrics> process_metrics_; |
64 | 72 |
65 // The specific blocking pool SequencedTaskRunner that will be used to post | 73 // The specific blocking pool SequencedTaskRunner that will be used to post |
66 // the refresh tasks onto serially. | 74 // the refresh tasks onto serially. |
67 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; | 75 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; |
68 | 76 |
69 // The UI-thread callbacks in TaskGroup to be called when their corresponding | 77 // The UI-thread callbacks in TaskGroup to be called when their corresponding |
70 // refreshes on the worker thread are done. | 78 // refreshes on the worker thread are done. |
71 const OnCpuRefreshCallback on_cpu_refresh_callback_; | 79 const OnCpuRefreshCallback on_cpu_refresh_callback_; |
72 const OnMemoryRefreshCallback on_memory_refresh_callback_; | 80 const OnMemoryRefreshCallback on_memory_refresh_callback_; |
73 const OnIdleWakeupsCallback on_idle_wakeups_callback_; | 81 const OnIdleWakeupsCallback on_idle_wakeups_callback_; |
| 82 const OnProcessPriorityCallback on_process_priority_callback_; |
74 | 83 |
75 // To assert we're running on the correct thread. | 84 // To assert we're running on the correct thread. |
76 base::SequenceChecker worker_pool_sequenced_checker_; | 85 base::SequenceChecker worker_pool_sequenced_checker_; |
77 | 86 |
78 DISALLOW_COPY_AND_ASSIGN(TaskGroupSampler); | 87 DISALLOW_COPY_AND_ASSIGN(TaskGroupSampler); |
79 }; | 88 }; |
80 | 89 |
81 } // namespace task_management | 90 } // namespace task_management |
82 | 91 |
83 | 92 |
84 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ | 93 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ |
OLD | NEW |