| 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( |
| 46 base::ProcessId proc_id, |
| 44 base::ProcessHandle proc_handle, | 47 base::ProcessHandle proc_handle, |
| 45 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, | 48 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner, |
| 46 const OnCpuRefreshCallback& on_cpu_refresh, | 49 const OnCpuRefreshCallback& on_cpu_refresh, |
| 47 const OnMemoryRefreshCallback& on_memory_refresh, | 50 const OnMemoryRefreshCallback& on_memory_refresh, |
| 48 const OnIdleWakeupsCallback& on_idle_wakeups); | 51 const OnIdleWakeupsCallback& on_idle_wakeups, |
| 52 const OnProcessPriorityCallback& on_process_priority); |
| 49 | 53 |
| 50 // Refreshes the expensive process' stats (CPU usage, memory usage, and idle | 54 // Refreshes the expensive process' stats (CPU usage, memory usage, and idle |
| 51 // wakeups per second) on the worker thread. | 55 // wakeups per second) on the worker thread. |
| 52 void Refresh(int64 refresh_flags); | 56 void Refresh(int64 refresh_flags); |
| 53 | 57 |
| 54 private: | 58 private: |
| 55 friend class base::RefCountedThreadSafe<TaskGroupSampler>; | 59 friend class base::RefCountedThreadSafe<TaskGroupSampler>; |
| 56 ~TaskGroupSampler(); | 60 ~TaskGroupSampler(); |
| 57 | 61 |
| 58 // The refresh calls that will be done on the worker thread. | 62 // The refresh calls that will be done on the worker thread. |
| 59 double RefreshCpuUsage(); | 63 double RefreshCpuUsage(); |
| 60 MemoryUsageStats RefreshMemoryUsage(); | 64 MemoryUsageStats RefreshMemoryUsage(); |
| 61 int RefreshIdleWakeupsPerSecond(); | 65 int RefreshIdleWakeupsPerSecond(); |
| 66 bool RefreshProcessPriority(); |
| 62 | 67 |
| 63 scoped_ptr<base::ProcessMetrics> process_metrics_; | 68 scoped_ptr<base::ProcessMetrics> process_metrics_; |
| 64 | 69 |
| 65 // The specific blocking pool SequencedTaskRunner that will be used to post | 70 // The specific blocking pool SequencedTaskRunner that will be used to post |
| 66 // the refresh tasks onto serially. | 71 // the refresh tasks onto serially. |
| 67 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; | 72 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_; |
| 68 | 73 |
| 74 base::Process process_; |
| 75 |
| 69 // The UI-thread callbacks in TaskGroup to be called when their corresponding | 76 // The UI-thread callbacks in TaskGroup to be called when their corresponding |
| 70 // refreshes on the worker thread are done. | 77 // refreshes on the worker thread are done. |
| 71 const OnCpuRefreshCallback on_cpu_refresh_callback_; | 78 const OnCpuRefreshCallback on_cpu_refresh_callback_; |
| 72 const OnMemoryRefreshCallback on_memory_refresh_callback_; | 79 const OnMemoryRefreshCallback on_memory_refresh_callback_; |
| 73 const OnIdleWakeupsCallback on_idle_wakeups_callback_; | 80 const OnIdleWakeupsCallback on_idle_wakeups_callback_; |
| 81 const OnProcessPriorityCallback on_process_priority_callback_; |
| 74 | 82 |
| 75 // To assert we're running on the correct thread. | 83 // To assert we're running on the correct thread. |
| 76 base::SequenceChecker worker_pool_sequenced_checker_; | 84 base::SequenceChecker worker_pool_sequenced_checker_; |
| 77 | 85 |
| 78 DISALLOW_COPY_AND_ASSIGN(TaskGroupSampler); | 86 DISALLOW_COPY_AND_ASSIGN(TaskGroupSampler); |
| 79 }; | 87 }; |
| 80 | 88 |
| 81 } // namespace task_management | 89 } // namespace task_management |
| 82 | 90 |
| 83 | 91 |
| 84 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ | 92 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_SAMPLER_H_ |
| OLD | NEW |