Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 base::Time time; | 36 base::Time time; |
| 37 | 37 |
| 38 // Indicates whether the CPU is online. | 38 // Indicates whether the CPU is online. |
| 39 bool cpu_online; | 39 bool cpu_online; |
| 40 | 40 |
| 41 // A mapping from a CPU state to time spent in that state in milliseconds. | 41 // A mapping from a CPU state to time spent in that state in milliseconds. |
| 42 // For idle state samples, the name of the state at index i in this vector | 42 // For idle state samples, the name of the state at index i in this vector |
| 43 // is the name at index i in the vector returned by cpu_idle_state_names(). | 43 // is the name at index i in the vector returned by cpu_idle_state_names(). |
| 44 // Similarly, for freq state occupancy, similar information is in the vector | 44 // Similarly, for freq state occupancy, similar information is in the vector |
| 45 // returned by cpu_freq_state_names(). | 45 // returned by cpu_freq_state_names(). |
| 46 std::vector<int64_t> time_in_state; | 46 std::vector<int64_t> time_in_state; |
|
Daniel Erat
2017/05/02 23:41:10
if you're up for changing this, it should be eithe
weidongg
2017/05/03 21:32:31
time_in_state here may try to be consistent with t
Daniel Erat
2017/05/03 22:08:21
time_in_state_ms would be okay, but using base::Ti
| |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 typedef std::deque<StateOccupancySample> StateOccupancySampleDeque; | 49 typedef std::deque<StateOccupancySample> StateOccupancySampleDeque; |
| 50 | 50 |
| 51 const std::vector<std::string>& cpu_idle_state_names() const { | 51 const std::vector<std::string>& cpu_idle_state_names() const { |
| 52 return cpu_idle_state_names_; | 52 return cpu_idle_state_names_; |
| 53 } | 53 } |
| 54 | 54 |
| 55 const std::vector<StateOccupancySampleDeque>& cpu_idle_state_data() const { | 55 const std::vector<StateOccupancySampleDeque>& cpu_idle_state_data() const { |
| 56 return cpu_idle_state_data_; | 56 return cpu_idle_state_data_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 const std::vector<std::string>& cpu_freq_state_names() const { | 59 const std::vector<std::string>& cpu_freq_state_names() const { |
| 60 return cpu_freq_state_names_; | 60 return cpu_freq_state_names_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 const std::vector<StateOccupancySampleDeque>& cpu_freq_state_data() const { | 63 const std::vector<StateOccupancySampleDeque>& cpu_freq_state_data() const { |
| 64 return cpu_freq_state_data_; | 64 return cpu_freq_state_data_; |
| 65 } | 65 } |
| 66 | 66 |
| 67 CpuDataCollector(); | 67 CpuDataCollector(); |
| 68 ~CpuDataCollector(); | 68 ~CpuDataCollector(); |
| 69 | 69 |
| 70 // Starts a repeating timer which periodically runs a callback to collect | 70 // Starts a repeating timer which periodically runs a callback to collect |
| 71 // CPU state occupancy samples. | 71 // CPU state occupancy samples. |
| 72 void Start(); | 72 void Start(); |
| 73 | 73 |
| 74 // Samples the CPU idle state information from sysfs. |cpu_count| is the | |
| 75 // number of possible CPUs on the system. Sample at index i in |idle_samples| | |
| 76 // corresponds to the idle state information of the i-th CPU. | |
| 77 static void SampleCpuIdleData( | |
|
Daniel Erat
2017/05/02 23:41:10
only the methods that you're actually calling from
weidongg
2017/05/03 21:32:31
Done.
| |
| 78 int cpu_count, | |
| 79 std::vector<std::string>* cpu_idle_state_names, | |
| 80 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples); | |
| 81 | |
| 82 // Read CPU frequency data of a specific CPU from the file in |path| and fill | |
| 83 // |cpu_freq_state_names| and |freq_sample| with the data. | |
| 84 // Sample file looks like: | |
| 85 // 126000 223344 | |
| 86 // 216000 93495 | |
| 87 // ... | |
| 88 // 1800000 321907 | |
| 89 static bool ReadCpuFreqTimeInState( | |
| 90 const std::string& path, | |
| 91 std::vector<std::string>* cpu_freq_state_names, | |
| 92 CpuDataCollector::StateOccupancySample* freq_sample); | |
| 93 | |
| 94 // Read CPU frequency data of all CPUs from the file in |path| and fill | |
| 95 // |cpu_freq_state_names| and |freq_samples| with the data. |cpu_count| is the | |
| 96 // number of possible CPUs on the system. Note that |freq_samples| is not | |
| 97 // empty and sample at index i in |freq_samples| corresponds to the freq state | |
| 98 // information of the i-th CPU. |cpu_online| of each sample must be set before | |
| 99 // calling this function. | |
| 100 // Sample file looks like: | |
| 101 // freq cpu0 cpu1 | |
| 102 // 126000 223344 223311 | |
| 103 // 216000 93495 93450 | |
| 104 // ... | |
| 105 // 1800000 321907 331897 | |
| 106 static bool ReadCpuFreqAllTimeInState( | |
| 107 int cpu_count, | |
| 108 const std::string& path, | |
| 109 std::vector<std::string>* cpu_freq_state_names, | |
| 110 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples); | |
| 111 | |
| 112 // Samples the CPU freq state information from sysfs. |cpu_count| is the | |
| 113 // number of possible CPUs on the system. Sample at index i in |freq_samples| | |
| 114 // corresponds to the freq state information of the i-th CPU. | |
| 115 static void SampleCpuFreqData( | |
|
Daniel Erat
2017/05/02 23:41:10
see above
weidongg
2017/05/03 21:32:31
Done.
| |
| 116 int cpu_count, | |
| 117 std::vector<std::string>* cpu_freq_state_names, | |
| 118 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples); | |
| 119 | |
| 120 // Samples CPU idle and CPU freq data from sysfs. This function should run on | |
| 121 // the blocking pool as reading from sysfs is a blocking task. Elements at | |
| 122 // index i in |idle_samples| and |freq_samples| correspond to the idle and | |
| 123 // freq samples of CPU i. This also function reads the number of CPUs from | |
| 124 // sysfs if *|cpu_count| < 0. | |
| 125 static void SampleCpuStateAsync( | |
|
Daniel Erat
2017/05/02 23:41:10
see above
weidongg
2017/05/03 21:32:31
Done.
| |
| 126 int* cpu_count, | |
| 127 std::vector<std::string>* cpu_idle_state_names, | |
| 128 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples, | |
| 129 std::vector<std::string>* cpu_freq_state_names, | |
| 130 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples); | |
| 131 | |
| 74 private: | 132 private: |
| 75 // Posts callbacks to the blocking pool which collect CPU state occupancy | 133 // Posts callbacks to the blocking pool which collect CPU state occupancy |
| 76 // samples from the sysfs. | 134 // samples from the sysfs. |
| 77 void PostSampleCpuState(); | 135 void PostSampleCpuState(); |
| 78 | 136 |
| 79 // This function commits the CPU count and samples read by | 137 // This function commits the CPU count and samples read by |
| 80 // SampleCpuStateAsync to |cpu_idle_state_data_| and | 138 // SampleCpuStateAsync to |cpu_idle_state_data_| and |
| 81 // |cpu_freq_state_data_|. Since UI is the consumer of CPU idle and freq data, | 139 // |cpu_freq_state_data_|. Since UI is the consumer of CPU idle and freq data, |
| 82 // this function should run on the UI thread. | 140 // this function should run on the UI thread. |
| 83 void SaveCpuStateSamplesOnUIThread( | 141 void SaveCpuStateSamplesOnUIThread( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 107 // hence should be read/written to only from the blocking pool. | 165 // hence should be read/written to only from the blocking pool. |
| 108 int cpu_count_; | 166 int cpu_count_; |
| 109 | 167 |
| 110 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_; | 168 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_; |
| 111 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector); | 169 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector); |
| 112 }; | 170 }; |
| 113 | 171 |
| 114 } // namespace chromeos | 172 } // namespace chromeos |
| 115 | 173 |
| 116 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | 174 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ |
| OLD | NEW |