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> |
| 9 |
8 #include <deque> | 10 #include <deque> |
9 #include <map> | 11 #include <map> |
10 #include <string> | 12 #include <string> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/basictypes.h" | 15 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
17 | 19 |
18 namespace chromeos { | 20 namespace chromeos { |
19 | 21 |
20 // A class to sample CPU idle state occupancy and freq state occupancy. | 22 // 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 | 23 // 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 | 24 // 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 | 25 // other times, it is best for the consumer of this data to calculate percentage |
24 // occupancy information using suspend time data from | 26 // occupancy information using suspend time data from |
25 // PowerDataCollector::system_resumed_data. | 27 // PowerDataCollector::system_resumed_data. |
26 class CpuDataCollector { | 28 class CpuDataCollector { |
27 public: | 29 public: |
28 struct StateOccupancySample { | 30 struct StateOccupancySample { |
29 StateOccupancySample(); | 31 StateOccupancySample(); |
30 ~StateOccupancySample(); | 32 ~StateOccupancySample(); |
31 | 33 |
32 // The time when the data was sampled. | 34 // The time when the data was sampled. |
33 base::Time time; | 35 base::Time time; |
34 | 36 |
35 // Indicates whether the CPU is online. | 37 // Indicates whether the CPU is online. |
36 bool cpu_online; | 38 bool cpu_online; |
37 | 39 |
38 // A mapping from a CPU state to time spent in that state in milliseconds. | 40 // A mapping from a CPU state to time spent in that state in milliseconds. |
39 // For idle state samples, the name of the state at index i in this vector | 41 // For idle state samples, the name of the state at index i in this vector |
40 // is the name at index i in the vector returned by cpu_idle_state_names(). | 42 // is the name at index i in the vector returned by cpu_idle_state_names(). |
41 // Similarly, for freq state occupancy, similar information is in the vector | 43 // Similarly, for freq state occupancy, similar information is in the vector |
42 // returned by cpu_freq_state_names(). | 44 // returned by cpu_freq_state_names(). |
43 std::vector<int64> time_in_state; | 45 std::vector<int64_t> time_in_state; |
44 }; | 46 }; |
45 | 47 |
46 typedef std::deque<StateOccupancySample> StateOccupancySampleDeque; | 48 typedef std::deque<StateOccupancySample> StateOccupancySampleDeque; |
47 | 49 |
48 const std::vector<std::string>& cpu_idle_state_names() const { | 50 const std::vector<std::string>& cpu_idle_state_names() const { |
49 return cpu_idle_state_names_; | 51 return cpu_idle_state_names_; |
50 } | 52 } |
51 | 53 |
52 const std::vector<StateOccupancySampleDeque>& cpu_idle_state_data() const { | 54 const std::vector<StateOccupancySampleDeque>& cpu_idle_state_data() const { |
53 return cpu_idle_state_data_; | 55 return cpu_idle_state_data_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // hence should be read/written to only from the blocking pool. | 106 // hence should be read/written to only from the blocking pool. |
105 int cpu_count_; | 107 int cpu_count_; |
106 | 108 |
107 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_; | 109 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_; |
108 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector); | 110 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector); |
109 }; | 111 }; |
110 | 112 |
111 } // namespace chromeos | 113 } // namespace chromeos |
112 | 114 |
113 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ | 115 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ |
OLD | NEW |