OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | |
7 | |
8 #include <deque> | |
9 #include <map> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/basictypes.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/time/time.h" | |
16 #include "base/timer/timer.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 // A class to sample CPU idle state occupancy and freq state occupancy. | |
21 // Collects raw data from sysfs and does not convert it to percentage | |
22 // occupancy. As CPUs can be offline at times, or the system can be suspended at | |
23 // other times, it is best for the consumer of this data to calculate percentage | |
24 // occupancy information using suspend time data from | |
25 // PowerDataCollector::system_resumed_data. | |
26 class CpuDataCollector { | |
27 public: | |
28 struct StateOccupancySample { | |
29 StateOccupancySample(); | |
Daniel Erat
2014/03/07 00:49:18
also declare a d'tor and define it in the .cc file
Siva Chandra
2014/03/07 22:20:01
Done.
| |
30 | |
31 // The time when the data was sampled. | |
32 base::Time time; | |
33 | |
34 // Indicates whether the CPU is online. | |
35 bool cpu_online; | |
36 | |
37 // A mapping from a CPU state to time spent in that state in milliseconds. | |
38 // For idle state samples, the name of the state at index i in this vector | |
39 // is the name at index i in the vector returned by cpu_idle_state_names(). | |
40 // Similarly, for freq state occupancy, similar information is in the vector | |
41 // returned by cpu_freq_state_names(). | |
42 std::vector<int64> time_in_state; | |
43 }; | |
44 | |
45 typedef std::deque<StateOccupancySample> StateOccupancySampleDeque; | |
46 | |
47 const std::vector<std::string>& cpu_idle_state_names() const { | |
48 return cpu_idle_state_names_; | |
49 } | |
50 | |
51 const std::vector<StateOccupancySampleDeque>& cpu_idle_state_data() const { | |
52 return cpu_idle_state_data_; | |
53 } | |
54 | |
55 const std::vector<std::string>& cpu_freq_state_names() const { | |
56 return cpu_freq_state_names_; | |
57 } | |
58 | |
59 const std::vector<StateOccupancySampleDeque>& cpu_freq_state_data() const { | |
60 return cpu_freq_state_data_; | |
61 } | |
62 | |
63 CpuDataCollector(); | |
Daniel Erat
2014/03/07 00:49:18
declare a d'tor for this too
Siva Chandra
2014/03/07 22:20:01
Done.
| |
64 | |
65 void Start(); | |
Daniel Erat
2014/03/07 00:49:18
add a brief comment documenting that this starts t
Siva Chandra
2014/03/07 22:20:01
Done.
| |
66 | |
67 private: | |
68 void PostSampleCpuState(); | |
Daniel Erat
2014/03/07 00:49:18
add a brief comment documenting what this method d
Siva Chandra
2014/03/07 22:20:01
Done.
| |
69 | |
70 // Samples CPU idle and CPU freq data from sysfs. This function should run on | |
71 // the blocking pool as reading from sysfs is a blocking task. Elements at | |
72 // index i in |idle_samples| and |freq_samples| correspond to the idle and | |
73 // freq samples of CPU i. | |
74 void SampleCpuStateOnBlockingPool( | |
75 std::vector<std::string>* cpu_idle_state_names, | |
76 std::vector<StateOccupancySample>* idle_samples, | |
77 std::vector<std::string>* cpu_freq_state_names, | |
78 std::vector<StateOccupancySample>* freq_samples); | |
79 | |
80 // This function commits the samples read by SampleCpuStateOnBlockingPool to | |
81 // |cpu_idle_state_data_| and |cpu_freq_state_data_|. Since UI is the consumer | |
82 // of CPU idle and freq data, this function should run on the UI thread. | |
83 void SaveCpuStateSamplesOnUIThread( | |
84 const std::vector<std::string>* cpu_idle_state_names, | |
85 const std::vector<StateOccupancySample>* idle_samples, | |
86 const std::vector<std::string>* cpu_freq_state_names, | |
87 const std::vector<StateOccupancySample>* freq_samples); | |
88 | |
89 base::RepeatingTimer<CpuDataCollector> timer_; | |
90 | |
91 // Names of the idle states. | |
92 std::vector<std::string> cpu_idle_state_names_; | |
93 | |
94 // The deque at index <i> in the vector corresponds to the idle state | |
95 // occupancy data of CPU<i>. | |
96 std::vector<StateOccupancySampleDeque> cpu_idle_state_data_; | |
97 | |
98 // Names of the freq states. | |
99 std::vector<std::string> cpu_freq_state_names_; | |
100 | |
101 // The deque at index <i> in the vector corresponds to the frequency state | |
102 // occupancy data of CPU<i>. | |
103 std::vector<StateOccupancySampleDeque> cpu_freq_state_data_; | |
104 | |
105 // The number of CPUs on the system. | |
106 int cpu_count_; | |
107 | |
108 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_; | |
109 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector); | |
110 }; | |
111 | |
112 } // namespace chromeos | |
113 | |
114 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | |
OLD | NEW |