Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: chrome/browser/chromeos/power/cpu_data_collector.h

Issue 2853863002: Add parser for new cpu freq file (Closed)
Patch Set: Add parser for new cpu freq file Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/files/file_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
19 20
20 namespace chromeos { 21 namespace chromeos {
21 22
22 // A class to sample CPU idle state occupancy and freq state occupancy. 23 // A class to sample CPU idle state occupancy and freq state occupancy.
23 // Collects raw data from sysfs and does not convert it to percentage 24 // Collects raw data from sysfs and does not convert it to percentage
24 // occupancy. As CPUs can be offline at times, or the system can be suspended at 25 // occupancy. As CPUs can be offline at times, or the system can be suspended at
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return cpu_freq_state_data_; 65 return cpu_freq_state_data_;
65 } 66 }
66 67
67 CpuDataCollector(); 68 CpuDataCollector();
68 ~CpuDataCollector(); 69 ~CpuDataCollector();
69 70
70 // Starts a repeating timer which periodically runs a callback to collect 71 // Starts a repeating timer which periodically runs a callback to collect
71 // CPU state occupancy samples. 72 // CPU state occupancy samples.
72 void Start(); 73 void Start();
73 74
75 // Read CPU frequency data of a specific CPU from the file in |path| and fill
76 // |cpu_freq_state_names| and |freq_sample| with the data.
77 // Sample file looks like:
78 // 126000 223344
79 // 216000 93495
80 // ...
81 // 1800000 321907
82 static bool ReadCpuFreqTimeInState(
83 const base::FilePath& path,
84 std::vector<std::string>* cpu_freq_state_names,
85 CpuDataCollector::StateOccupancySample* freq_sample);
86
87 // Read CPU frequency data of all CPUs from the file in |path| and fill
88 // |cpu_freq_state_names| and |freq_samples| with the data. |cpu_count| is the
89 // number of possible CPUs on the system. Note that |freq_samples| is not
90 // empty and sample at index i in |freq_samples| corresponds to the freq state
91 // information of the i-th CPU. |cpu_online| of each sample must be set before
92 // calling this function.
93 // Sample file looks like:
94 // freq cpu0 cpu1
95 // 126000 223344 223311
96 // 216000 93495 93450
97 // ...
98 // 1800000 321907 331897
99 static bool ReadCpuFreqAllTimeInState(
100 int cpu_count,
101 const base::FilePath& path,
102 std::vector<std::string>* cpu_freq_state_names,
103 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples);
104
74 private: 105 private:
75 // Posts callbacks to the blocking pool which collect CPU state occupancy 106 // Posts callbacks to the blocking pool which collect CPU state occupancy
76 // samples from the sysfs. 107 // samples from the sysfs.
77 void PostSampleCpuState(); 108 void PostSampleCpuState();
78 109
79 // This function commits the CPU count and samples read by 110 // This function commits the CPU count and samples read by
80 // SampleCpuStateAsync to |cpu_idle_state_data_| and 111 // SampleCpuStateAsync to |cpu_idle_state_data_| and
81 // |cpu_freq_state_data_|. Since UI is the consumer of CPU idle and freq data, 112 // |cpu_freq_state_data_|. Since UI is the consumer of CPU idle and freq data,
82 // this function should run on the UI thread. 113 // this function should run on the UI thread.
83 void SaveCpuStateSamplesOnUIThread( 114 void SaveCpuStateSamplesOnUIThread(
(...skipping 23 matching lines...) Expand all
107 // hence should be read/written to only from the blocking pool. 138 // hence should be read/written to only from the blocking pool.
108 int cpu_count_; 139 int cpu_count_;
109 140
110 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_; 141 base::WeakPtrFactory<CpuDataCollector> weak_ptr_factory_;
111 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector); 142 DISALLOW_COPY_AND_ASSIGN(CpuDataCollector);
112 }; 143 };
113 144
114 } // namespace chromeos 145 } // namespace chromeos
115 146
116 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_ 147 #endif // CHROME_BROWSER_CHROMEOS_POWER_CPU_DATA_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698