Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_MANAGER_SAMPLING_SHARED_SAMPLER_H_ | 5 #ifndef CHROME_BROWSER_TASK_MANAGER_SAMPLING_SHARED_SAMPLER_H_ |
| 6 #define CHROME_BROWSER_TASK_MANAGER_SAMPLING_SHARED_SAMPLER_H_ | 6 #define CHROME_BROWSER_TASK_MANAGER_SAMPLING_SHARED_SAMPLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 class SharedSampler : public base::RefCountedThreadSafe<SharedSampler> { | 34 class SharedSampler : public base::RefCountedThreadSafe<SharedSampler> { |
| 35 public: | 35 public: |
| 36 explicit SharedSampler( | 36 explicit SharedSampler( |
| 37 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner); | 37 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner); |
| 38 | 38 |
| 39 // Below are the types of callbacks that are invoked on the UI thread | 39 // Below are the types of callbacks that are invoked on the UI thread |
| 40 // when the refresh is done on the worker thread. | 40 // when the refresh is done on the worker thread. |
| 41 // These callbacks are passed via RegisterCallbacks. | 41 // These callbacks are passed via RegisterCallbacks. |
| 42 using OnIdleWakeupsCallback = base::Callback<void(int)>; | 42 using OnIdleWakeupsCallback = base::Callback<void(int)>; |
| 43 using OnPhysicalMemoryCallback = base::Callback<void(int64_t)>; | 43 using OnPhysicalMemoryCallback = base::Callback<void(int64_t)>; |
| 44 using OnStartTimeCallback = base::Callback<void(int64_t)>; | |
| 45 using OnCpuTimeCallback = base::Callback<void(int64_t)>; | |
| 44 | 46 |
| 45 // Returns a combination of refresh flags supported by the shared sampler. | 47 // Returns a combination of refresh flags supported by the shared sampler. |
| 46 int64_t GetSupportedFlags() const; | 48 int64_t GetSupportedFlags() const; |
| 47 | 49 |
| 48 // Registers task group specific callbacks. | 50 // Registers task group specific callbacks. |
| 49 void RegisterCallbacks(base::ProcessId process_id, | 51 void RegisterCallbacks(base::ProcessId process_id, |
| 50 const OnIdleWakeupsCallback& on_idle_wakeups, | 52 const OnIdleWakeupsCallback& on_idle_wakeups, |
| 51 const OnPhysicalMemoryCallback& on_physical_memory); | 53 const OnPhysicalMemoryCallback& on_physical_memory, |
| 54 const OnStartTimeCallback& on_start_time, | |
| 55 const OnCpuTimeCallback& on_cpu_time); | |
| 52 | 56 |
| 53 // Unregisters task group specific callbacks. | 57 // Unregisters task group specific callbacks. |
| 54 void UnregisterCallbacks(base::ProcessId process_id); | 58 void UnregisterCallbacks(base::ProcessId process_id); |
| 55 | 59 |
| 56 // Refreshes the expensive process' stats (for now only idle wakeups per | 60 // Refreshes the expensive process' stats (for now only idle wakeups per |
| 57 // second) on the worker thread. | 61 // second) on the worker thread. |
| 58 void Refresh(base::ProcessId process_id, int64_t refresh_flags); | 62 void Refresh(base::ProcessId process_id, int64_t refresh_flags); |
| 59 | 63 |
| 60 private: | 64 private: |
| 61 friend class base::RefCountedThreadSafe<SharedSampler>; | 65 friend class base::RefCountedThreadSafe<SharedSampler>; |
| 62 ~SharedSampler(); | 66 ~SharedSampler(); |
| 63 | 67 |
| 64 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
| 65 // The UI-thread callbacks in TaskGroup registered with RegisterCallbacks and | 69 // The UI-thread callbacks in TaskGroup registered with RegisterCallbacks and |
| 66 // to be called when refresh on the worker thread is done. | 70 // to be called when refresh on the worker thread is done. |
| 67 struct Callbacks { | 71 struct Callbacks { |
| 68 Callbacks(); | 72 Callbacks(); |
| 69 Callbacks(Callbacks&& other); | 73 Callbacks(Callbacks&& other); |
| 70 ~Callbacks(); | 74 ~Callbacks(); |
| 71 | 75 |
| 72 OnIdleWakeupsCallback on_idle_wakeups; | 76 OnIdleWakeupsCallback on_idle_wakeups; |
| 73 OnPhysicalMemoryCallback on_physical_memory; | 77 OnPhysicalMemoryCallback on_physical_memory; |
| 78 OnStartTimeCallback on_start_time; | |
| 79 OnCpuTimeCallback on_cpu_time; | |
| 74 | 80 |
| 75 private: | 81 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(Callbacks); | 82 DISALLOW_COPY_AND_ASSIGN(Callbacks); |
| 77 }; | 83 }; |
| 78 | 84 |
| 79 typedef std::map<base::ProcessId, Callbacks> CallbacksMap; | 85 typedef std::map<base::ProcessId, Callbacks> CallbacksMap; |
| 80 | 86 |
| 81 // Contains all results of refresh for a single process. | 87 // Contains all results of refresh for a single process. |
| 82 struct RefreshResult { | 88 struct RefreshResult { |
| 83 base::ProcessId process_id; | 89 base::ProcessId process_id; |
| 84 int idle_wakeups_per_second; | 90 int idle_wakeups_per_second; |
| 85 int64_t physical_bytes; | 91 int64_t physical_bytes; |
| 92 int64_t start_time; | |
|
brucedawson
2016/12/19 21:51:05
Should these be using a type that includes semanti
chengx
2016/12/20 00:51:12
Done.
| |
| 93 int64_t cpu_time; | |
| 86 }; | 94 }; |
| 87 | 95 |
| 88 typedef std::vector<RefreshResult> RefreshResults; | 96 typedef std::vector<RefreshResult> RefreshResults; |
| 89 | 97 |
| 90 // Posted on the worker thread to do the actual refresh. | 98 // Posted on the worker thread to do the actual refresh. |
| 91 std::unique_ptr<RefreshResults> RefreshOnWorkerThread(); | 99 std::unique_ptr<RefreshResults> RefreshOnWorkerThread(); |
| 92 | 100 |
| 93 // Called on UI thread when the refresh is done. | 101 // Called on UI thread when the refresh is done. |
| 94 void OnRefreshDone(std::unique_ptr<RefreshResults> refresh_results); | 102 void OnRefreshDone(std::unique_ptr<RefreshResults> refresh_results); |
| 95 | 103 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 // To assert we're running on the correct thread. | 147 // To assert we're running on the correct thread. |
| 140 base::SequenceChecker worker_pool_sequenced_checker_; | 148 base::SequenceChecker worker_pool_sequenced_checker_; |
| 141 #endif // defined(OS_WIN) | 149 #endif // defined(OS_WIN) |
| 142 | 150 |
| 143 DISALLOW_COPY_AND_ASSIGN(SharedSampler); | 151 DISALLOW_COPY_AND_ASSIGN(SharedSampler); |
| 144 }; | 152 }; |
| 145 | 153 |
| 146 } // namespace task_manager | 154 } // namespace task_manager |
| 147 | 155 |
| 148 #endif // CHROME_BROWSER_TASK_MANAGER_SAMPLING_SHARED_SAMPLER_H_ | 156 #endif // CHROME_BROWSER_TASK_MANAGER_SAMPLING_SHARED_SAMPLER_H_ |
| OLD | NEW |