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 #include "chrome/browser/chromeos/power/cpu_data_collector.h" | 5 #include "chrome/browser/chromeos/power/cpu_data_collector.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... | |
41 // Suffix of the path to the file listing the range of possible CPUs on the | 41 // Suffix of the path to the file listing the range of possible CPUs on the |
42 // system. | 42 // system. |
43 const char kPossibleCpuPathSuffix[] = "/possible"; | 43 const char kPossibleCpuPathSuffix[] = "/possible"; |
44 | 44 |
45 // Format of the suffix of the path to the file which contains information | 45 // Format of the suffix of the path to the file which contains information |
46 // about a particular CPU being online or offline. | 46 // about a particular CPU being online or offline. |
47 const char kCpuOnlinePathSuffixFormat[] = "/cpu%d/online"; | 47 const char kCpuOnlinePathSuffixFormat[] = "/cpu%d/online"; |
48 | 48 |
49 // Format of the suffix of the path to the file which contains freq state | 49 // Format of the suffix of the path to the file which contains freq state |
50 // information of a CPU. | 50 // information of a CPU. |
51 const char kCpuFreqTimeInStatePathSuffixOldFormat[] = | 51 const char kCpuFreqTimeInStatePathSuffixFormat[] = |
52 "/cpu%d/cpufreq/stats/time_in_state"; | 52 "/cpu%d/cpufreq/stats/time_in_state"; |
53 | 53 |
54 // The path to the file which contains cpu freq state informatino of a CPU | 54 // The path to the file which contains cpu freq state information of a CPU |
55 // in newer kernel. | 55 // in some kernels such as 3.14.0. |
56 const char kCpuFreqTimeInStateNewPath[] = | 56 const char kCpuFreqAllTimeInStatePath[] = |
57 "/sys/devices/system/cpu/cpufreq/all_time_in_state"; | 57 "/sys/devices/system/cpu/cpufreq/all_time_in_state"; |
58 | 58 |
59 // Format of the suffix of the path to the directory which contains information | 59 // Format of the suffix of the path to the directory which contains information |
60 // about an idle state of a CPU on the system. | 60 // about an idle state of a CPU on the system. |
61 const char kCpuIdleStateDirPathSuffixFormat[] = "/cpu%d/cpuidle/state%d"; | 61 const char kCpuIdleStateDirPathSuffixFormat[] = "/cpu%d/cpuidle/state%d"; |
62 | 62 |
63 // Format of the suffix of the path to the file which contains the name of an | 63 // Format of the suffix of the path to the file which contains the name of an |
64 // idle state of a CPU. | 64 // idle state of a CPU. |
65 const char kCpuIdleStateNamePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/name"; | 65 const char kCpuIdleStateNamePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/name"; |
66 | 66 |
67 // Format of the suffix of the path which contains information about time spent | 67 // Format of the suffix of the path which contains information about time spent |
68 // in an idle state on a CPU. | 68 // in an idle state on a CPU. |
69 const char kCpuIdleStateTimePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/time"; | 69 const char kCpuIdleStateTimePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/time"; |
70 | 70 |
71 // Returns the index at which |str| is in |vector|. If |str| is not present in | 71 // Returns the index at which |str| is in |vector|. If |str| is not present in |
72 // |vector|, then it is added to it before its index is returned. | 72 // |vector|, then it is added to it before its index is returned. |
73 size_t IndexInVector(const std::string& str, std::vector<std::string>* vector) { | 73 size_t EnsureInVector(const std::string& str, |
74 std::vector<std::string>* vector) { | |
74 for (size_t i = 0; i < vector->size(); ++i) { | 75 for (size_t i = 0; i < vector->size(); ++i) { |
75 if (str == (*vector)[i]) | 76 if (str == (*vector)[i]) |
76 return i; | 77 return i; |
77 } | 78 } |
78 | 79 |
79 // If this is reached, then it means |str| is not present in vector. Add it. | 80 // If this is reached, then it means |str| is not present in vector. Add it. |
80 vector->push_back(str); | 81 vector->push_back(str); |
81 return vector->size() - 1; | 82 return vector->size() - 1; |
82 } | 83 } |
83 | 84 |
(...skipping 17 matching lines...) Expand all Loading... | |
101 &cpu_online_string); | 102 &cpu_online_string); |
102 if (base::StringToInt(cpu_online_string, &online)) | 103 if (base::StringToInt(cpu_online_string, &online)) |
103 return online == kCpuOnlineStatus; | 104 return online == kCpuOnlineStatus; |
104 } | 105 } |
105 | 106 |
106 LOG(ERROR) << "Bad format or error reading " << cpu_online_file << ". " | 107 LOG(ERROR) << "Bad format or error reading " << cpu_online_file << ". " |
107 << "Assuming offline."; | 108 << "Assuming offline."; |
108 return false; | 109 return false; |
109 } | 110 } |
110 | 111 |
111 // Samples the CPU idle state information from sysfs. |cpu_count| is the number | 112 } // namespace |
112 // of possible CPUs on the system. Sample at index i in |idle_samples| | 113 |
113 // corresponds to the idle state information of the i-th CPU. | 114 void CpuDataCollector::SampleCpuIdleData( |
114 void SampleCpuIdleData( | |
115 int cpu_count, | 115 int cpu_count, |
116 std::vector<std::string>* cpu_idle_state_names, | 116 std::vector<std::string>* cpu_idle_state_names, |
117 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples) { | 117 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples) { |
118 base::Time start_time = base::Time::Now(); | 118 base::Time start_time = base::Time::Now(); |
119 for (int cpu = 0; cpu < cpu_count; ++cpu) { | 119 for (int cpu = 0; cpu < cpu_count; ++cpu) { |
120 CpuDataCollector::StateOccupancySample idle_sample; | 120 CpuDataCollector::StateOccupancySample idle_sample; |
121 idle_sample.time = base::Time::Now(); | 121 idle_sample.time = base::Time::Now(); |
122 idle_sample.time_in_state.reserve(cpu_idle_state_names->size()); | 122 idle_sample.time_in_state.reserve(cpu_idle_state_names->size()); |
123 | 123 |
124 if (!CpuIsOnline(cpu)) { | 124 if (!CpuIsOnline(cpu)) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 idle_samples->clear(); | 162 idle_samples->clear(); |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 base::TrimWhitespaceASCII(state_name, base::TRIM_ALL, &state_name); | 166 base::TrimWhitespaceASCII(state_name, base::TRIM_ALL, &state_name); |
167 base::TrimWhitespaceASCII(occupancy_time_string, base::TRIM_ALL, | 167 base::TrimWhitespaceASCII(occupancy_time_string, base::TRIM_ALL, |
168 &occupancy_time_string); | 168 &occupancy_time_string); |
169 if (base::StringToInt64(occupancy_time_string, &occupancy_time_usec)) { | 169 if (base::StringToInt64(occupancy_time_string, &occupancy_time_usec)) { |
170 // idle state occupancy time in sysfs is recorded in microseconds. | 170 // idle state occupancy time in sysfs is recorded in microseconds. |
171 int64_t time_in_state_ms = occupancy_time_usec / 1000; | 171 int64_t time_in_state_ms = occupancy_time_usec / 1000; |
172 size_t index = IndexInVector(state_name, cpu_idle_state_names); | 172 size_t index = EnsureInVector(state_name, cpu_idle_state_names); |
173 if (index >= idle_sample.time_in_state.size()) | 173 if (index >= idle_sample.time_in_state.size()) |
174 idle_sample.time_in_state.resize(index + 1); | 174 idle_sample.time_in_state.resize(index + 1); |
175 idle_sample.time_in_state[index] = time_in_state_ms; | 175 idle_sample.time_in_state[index] = time_in_state_ms; |
176 } else { | 176 } else { |
177 LOG(ERROR) << "Bad format in " << time_file_path << ". " | 177 LOG(ERROR) << "Bad format in " << time_file_path << ". " |
178 << "Dropping sample."; | 178 << "Dropping sample."; |
179 idle_samples->clear(); | 179 idle_samples->clear(); |
180 return; | 180 return; |
181 } | 181 } |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 idle_samples->push_back(idle_sample); | 185 idle_samples->push_back(idle_sample); |
186 } | 186 } |
187 | 187 |
188 // If there was an interruption in sampling (like system suspended), | 188 // If there was an interruption in sampling (like system suspended), |
189 // discard the samples! | 189 // discard the samples! |
190 int64_t delay = | 190 int64_t delay = |
191 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); | 191 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); |
192 if (delay > kSamplingDurationLimitMs) { | 192 if (delay > kSamplingDurationLimitMs) { |
193 idle_samples->clear(); | 193 idle_samples->clear(); |
194 LOG(WARNING) << "Dropped an idle state sample due to excessive time delay: " | 194 LOG(WARNING) << "Dropped an idle state sample due to excessive time delay: " |
195 << delay << "milliseconds."; | 195 << delay << "milliseconds."; |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
199 bool ReadCpuFreqFromOldFile( | 199 bool CpuDataCollector::ReadCpuFreqTimeInState( |
200 const std::string& path, | 200 const std::string& path, |
201 std::vector<std::string>* cpu_freq_state_names, | 201 std::vector<std::string>* cpu_freq_state_names, |
202 CpuDataCollector::StateOccupancySample* freq_sample) { | 202 CpuDataCollector::StateOccupancySample* freq_sample) { |
203 std::string time_in_state_string; | 203 std::string time_in_state_string; |
204 // Note time as close to reading the file as possible. This is | 204 // Note time as close to reading the file as possible. This is |
205 // not possible for idle state samples as the information for | 205 // not possible for idle state samples as the information for |
206 // each state there is recorded in different files. | 206 // each state there is recorded in different files. |
207 if (!base::ReadFileToString(base::FilePath(path), &time_in_state_string)) { | 207 if (!base::ReadFileToString(base::FilePath(path), &time_in_state_string)) { |
208 LOG(ERROR) << "Error reading " << path << ". " | 208 LOG(ERROR) << "Error reading " << path << ". " |
209 << "Dropping sample."; | 209 << "Dropping sample."; |
210 return false; | 210 return false; |
211 } | 211 } |
212 // The last line could end with '\n'. Ignore the last empty string in | |
Daniel Erat
2017/05/02 23:41:10
shorter: "// Remove trailing newlines."
weidongg
2017/05/03 21:32:31
Done.
| |
213 // such cases. | |
214 base::TrimWhitespaceASCII(time_in_state_string, | |
215 base::TrimPositions::TRIM_TRAILING, | |
216 &time_in_state_string); | |
212 | 217 |
213 std::vector<base::StringPiece> lines = base::SplitStringPiece( | 218 std::vector<base::StringPiece> lines = base::SplitStringPiece( |
214 time_in_state_string, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 219 time_in_state_string, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
215 // The last line could end with '\n'. Ignore the last empty string in | |
216 // such cases. | |
217 size_t state_count = lines.size(); | 220 size_t state_count = lines.size(); |
218 if (state_count > 0 && lines.back().empty()) | |
219 state_count -= 1; | |
220 for (size_t state = 0; state < state_count; ++state) { | 221 for (size_t state = 0; state < state_count; ++state) { |
221 int freq_in_khz; | 222 int freq_in_khz; |
222 int64_t occupancy_time_centisecond; | 223 int64_t occupancy_time_centisecond; |
223 | 224 |
224 // Occupancy of each state is in the format "<state> <time>" | 225 // Occupancy of each state is in the format "<state> <time>" |
225 std::vector<base::StringPiece> pair = base::SplitStringPiece( | 226 std::vector<base::StringPiece> pair = base::SplitStringPiece( |
226 lines[state], " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 227 lines[state], " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
227 if (pair.size() == 2 && base::StringToInt(pair[0], &freq_in_khz) && | 228 if (pair.size() != 2 || !base::StringToInt(pair[0], &freq_in_khz) || |
228 base::StringToInt64(pair[1], &occupancy_time_centisecond)) { | 229 !base::StringToInt64(pair[1], &occupancy_time_centisecond)) { |
229 const std::string state_name = base::IntToString(freq_in_khz / 1000); | |
230 size_t index = IndexInVector(state_name, cpu_freq_state_names); | |
231 if (index >= freq_sample->time_in_state.size()) | |
232 freq_sample->time_in_state.resize(index + 1); | |
233 // The occupancy time is in units of centiseconds. | |
234 freq_sample->time_in_state[index] = occupancy_time_centisecond * 10; | |
235 } else { | |
236 LOG(ERROR) << "Bad format in " << path << ". " | 230 LOG(ERROR) << "Bad format in " << path << ". " |
237 << "Dropping sample."; | 231 << "Dropping sample."; |
Daniel Erat
2017/05/02 23:41:09
include the bad line in the error message so this
weidongg
2017/05/03 21:32:31
Done.
| |
238 return false; | 232 return false; |
239 } | 233 } |
234 | |
235 const std::string state_name = base::IntToString(freq_in_khz / 1000); | |
236 size_t index = EnsureInVector(state_name, cpu_freq_state_names); | |
237 if (index >= freq_sample->time_in_state.size()) | |
238 freq_sample->time_in_state.resize(index + 1); | |
239 // The occupancy time is in units of centiseconds. | |
Daniel Erat
2017/05/02 23:41:10
nit: remove this comment; the variable name occupa
weidongg
2017/05/03 21:32:31
Done.
| |
240 freq_sample->time_in_state[index] = occupancy_time_centisecond * 10; | |
241 } | |
242 return true; | |
243 } | |
244 | |
245 bool CpuDataCollector::ReadCpuFreqAllTimeInState( | |
246 int cpu_count, | |
247 const std::string& path, | |
Daniel Erat
2017/05/02 23:41:09
pass paths as const base::FilePath&, not std::stri
weidongg
2017/05/03 21:32:31
Done.
| |
248 std::vector<std::string>* cpu_freq_state_names, | |
249 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { | |
250 std::string all_time_in_state_string; | |
251 // Note time as close to reading the file as possible. This is | |
252 // not possible for idle state samples as the information for | |
253 // each state there is recorded in different files. | |
254 if (!base::ReadFileToString(base::FilePath(path), | |
255 &all_time_in_state_string)) { | |
256 LOG(ERROR) << "Error reading " << path << ". " | |
Daniel Erat
2017/05/02 23:41:10
LOG(ERROR) << "Error reading " << path << "; dropp
weidongg
2017/05/03 21:32:31
Done.
| |
257 << "Dropping sample."; | |
258 return false; | |
259 } | |
260 // The last line could end with '\n'. Ignore the last empty string in | |
261 // such cases. | |
Daniel Erat
2017/05/02 23:41:10
nit: shorten this comment too
weidongg
2017/05/03 21:32:31
Done.
| |
262 base::TrimWhitespaceASCII(all_time_in_state_string, | |
263 base::TrimPositions::TRIM_TRAILING, | |
264 &all_time_in_state_string); | |
265 | |
266 std::vector<base::StringPiece> lines = | |
267 base::SplitStringPiece(all_time_in_state_string, "\n", | |
268 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
269 size_t state_count = lines.size(); | |
Daniel Erat
2017/05/02 23:41:10
why not just do this instead of resizing, maintain
weidongg
2017/05/03 21:32:31
Yes, this is better.
| |
270 // The first line is descriptions in the format "freq\t\tcpu0\t\tcpu1...". | |
271 if (state_count > 0) { | |
272 state_count -= 1; | |
273 lines.erase(lines.begin()); | |
274 } else { | |
275 // No content exists in the file. | |
276 return false; | |
277 } | |
278 for (size_t state = 0; state < state_count; ++state) { | |
279 int freq_in_khz; | |
Daniel Erat
2017/05/02 23:41:10
declare this just before it's used instead of up h
weidongg
2017/05/03 21:32:31
Done.
| |
280 // Occupancy of each state is in the format "<state>\t\t<time>\t\t<time> | |
281 // ..." | |
282 std::vector<base::StringPiece> array = base::SplitStringPiece( | |
283 lines[state], "\t", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
284 if (array.size() != size_t(cpu_count) + 1 || | |
Daniel Erat
2017/05/02 23:41:10
use c++ casts, not c casts: https://google.github.
weidongg
2017/05/03 21:32:31
Done.
| |
285 !base::StringToInt(array[0], &freq_in_khz)) { | |
286 LOG(ERROR) << "Bad format in " << path << ". " | |
287 << "Dropping sample."; | |
Daniel Erat
2017/05/02 23:41:10
include the bad data in the error message
weidongg
2017/05/03 21:32:31
Done.
| |
288 return false; | |
289 } | |
290 | |
291 const std::string state_name = base::IntToString(freq_in_khz / 1000); | |
292 size_t index = EnsureInVector(state_name, cpu_freq_state_names); | |
293 for (int cpu = 0; cpu < cpu_count; ++cpu) { | |
294 if (!(*freq_samples)[cpu].cpu_online) { | |
295 continue; | |
296 } | |
297 if (index >= (*freq_samples)[cpu].time_in_state.size()) | |
298 (*freq_samples)[cpu].time_in_state.resize(index + 1); | |
299 int64_t occupancy_time_centisecond; | |
300 if (!base::StringToInt64(array[cpu + 1], &occupancy_time_centisecond)) { | |
301 LOG(ERROR) << "Bad format in " << path << ". " | |
302 << "Dropping sample."; | |
Daniel Erat
2017/05/02 23:41:10
include bad data
weidongg
2017/05/03 21:32:31
Done.
| |
303 return false; | |
304 } | |
305 (*freq_samples)[cpu].time_in_state[index] = | |
306 occupancy_time_centisecond * 10; | |
307 } | |
240 } | 308 } |
241 return true; | 309 return true; |
242 } | 310 } |
243 | 311 |
244 // Samples the CPU freq state information from sysfs. |cpu_count| is the number | 312 void CpuDataCollector::SampleCpuFreqData( |
245 // of possible CPUs on the system. Sample at index i in |freq_samples| | |
246 // corresponds to the freq state information of the i-th CPU. | |
247 void SampleCpuFreqData( | |
248 int cpu_count, | 313 int cpu_count, |
249 std::vector<std::string>* cpu_freq_state_names, | 314 std::vector<std::string>* cpu_freq_state_names, |
250 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { | 315 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { |
251 base::Time start_time = base::Time::Now(); | 316 base::Time start_time = base::Time::Now(); |
252 for (int cpu = 0; cpu < cpu_count; ++cpu) { | 317 for (int cpu = 0; cpu < cpu_count; ++cpu) { |
253 CpuDataCollector::StateOccupancySample freq_sample; | 318 CpuDataCollector::StateOccupancySample freq_sample; |
254 freq_sample.time_in_state.reserve(cpu_freq_state_names->size()); | 319 freq_sample.time_in_state.reserve(cpu_freq_state_names->size()); |
320 freq_sample.time = base::Time::Now(); | |
321 freq_sample.cpu_online = CpuIsOnline(cpu); | |
322 freq_samples->push_back(freq_sample); | |
323 } | |
255 | 324 |
256 freq_sample.time = base::Time::Now(); | 325 if (base::PathExists(base::FilePath(kCpuFreqAllTimeInStatePath))) { |
257 if (!CpuIsOnline(cpu)) { | 326 if (!ReadCpuFreqAllTimeInState(cpu_count, kCpuFreqAllTimeInStatePath, |
258 freq_sample.cpu_online = false; | 327 cpu_freq_state_names, freq_samples)) { |
259 } else { | 328 freq_samples->clear(); |
260 freq_sample.cpu_online = true; | 329 return; |
261 | 330 } |
262 const std::string time_in_state_path_old_format = base::StringPrintf( | 331 } else { |
263 "%s%s", kCpuDataPathBase, kCpuFreqTimeInStatePathSuffixOldFormat); | 332 for (int cpu = 0; cpu < cpu_count; ++cpu) { |
264 const std::string time_in_state_path = | 333 if ((*freq_samples)[cpu].cpu_online) { |
265 base::StringPrintf(time_in_state_path_old_format.c_str(), cpu); | 334 const std::string time_in_state_path_old_format = base::StringPrintf( |
266 if (base::PathExists(base::FilePath(time_in_state_path))) { | 335 "%s%s", kCpuDataPathBase, kCpuFreqTimeInStatePathSuffixFormat); |
267 if (!ReadCpuFreqFromOldFile(time_in_state_path, cpu_freq_state_names, | 336 const std::string time_in_state_path = |
268 &freq_sample)) { | 337 base::StringPrintf(time_in_state_path_old_format.c_str(), cpu); |
338 if (base::PathExists(base::FilePath(time_in_state_path))) { | |
339 if (!ReadCpuFreqTimeInState(time_in_state_path, cpu_freq_state_names, | |
340 &(*freq_samples)[cpu])) { | |
341 freq_samples->clear(); | |
342 return; | |
343 } | |
344 } else { | |
345 // If the path to the 'time_in_state' for a single CPU is missing, | |
346 // then 'time_in_state' for all CPUs is missing. This could happen | |
347 // on a VM where the 'cpufreq_stats' kernel module is not loaded. | |
348 LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) | |
349 << "CPU freq stats not available in sysfs."; | |
269 freq_samples->clear(); | 350 freq_samples->clear(); |
270 return; | 351 return; |
271 } | 352 } |
272 } else if (base::PathExists(base::FilePath(kCpuFreqTimeInStateNewPath))) { | |
273 // TODO(oshima): Parse the new file. crbug.com/548510. | |
274 freq_samples->clear(); | |
275 return; | |
276 } else { | |
277 // If the path to the 'time_in_state' for a single CPU is missing, | |
278 // then 'time_in_state' for all CPUs is missing. This could happen | |
279 // on a VM where the 'cpufreq_stats' kernel module is not loaded. | |
280 LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) | |
281 << "CPU freq stats not available in sysfs."; | |
282 freq_samples->clear(); | |
283 return; | |
284 } | 353 } |
285 } | 354 } |
286 | |
287 freq_samples->push_back(freq_sample); | |
288 } | 355 } |
289 | |
290 // If there was an interruption in sampling (like system suspended), | 356 // If there was an interruption in sampling (like system suspended), |
291 // discard the samples! | 357 // discard the samples! |
292 int64_t delay = | 358 int64_t delay = |
293 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); | 359 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); |
294 if (delay > kSamplingDurationLimitMs) { | 360 if (delay > kSamplingDurationLimitMs) { |
295 freq_samples->clear(); | 361 freq_samples->clear(); |
296 LOG(WARNING) << "Dropped a freq state sample due to excessive time delay: " | 362 LOG(WARNING) << "Dropped a freq state sample due to excessive time delay: " |
297 << delay << "milliseconds."; | 363 << delay << "milliseconds."; |
298 } | 364 } |
299 } | 365 } |
300 | 366 |
301 // Samples CPU idle and CPU freq data from sysfs. This function should run on | 367 void CpuDataCollector::SampleCpuStateAsync( |
302 // the blocking pool as reading from sysfs is a blocking task. Elements at | |
303 // index i in |idle_samples| and |freq_samples| correspond to the idle and | |
304 // freq samples of CPU i. This also function reads the number of CPUs from | |
305 // sysfs if *|cpu_count| < 0. | |
306 void SampleCpuStateAsync( | |
307 int* cpu_count, | 368 int* cpu_count, |
308 std::vector<std::string>* cpu_idle_state_names, | 369 std::vector<std::string>* cpu_idle_state_names, |
309 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples, | 370 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples, |
310 std::vector<std::string>* cpu_freq_state_names, | 371 std::vector<std::string>* cpu_freq_state_names, |
311 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { | 372 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { |
312 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 373 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
313 | 374 |
314 if (*cpu_count < 0) { | 375 if (*cpu_count < 0) { |
315 // Set |cpu_count_| to 1. If it is something else, it will get corrected | 376 // Set |cpu_count_| to 1. If it is something else, it will get corrected |
316 // later. A system will at least have one CPU. Hence, a value of 1 here | 377 // later. A system will at least have one CPU. Hence, a value of 1 here |
(...skipping 26 matching lines...) Expand all Loading... | |
343 << "Defaulting CPU count to 1."; | 404 << "Defaulting CPU count to 1."; |
344 } | 405 } |
345 } | 406 } |
346 } | 407 } |
347 | 408 |
348 // Initialize the deques in the data vectors. | 409 // Initialize the deques in the data vectors. |
349 SampleCpuIdleData(*cpu_count, cpu_idle_state_names, idle_samples); | 410 SampleCpuIdleData(*cpu_count, cpu_idle_state_names, idle_samples); |
350 SampleCpuFreqData(*cpu_count, cpu_freq_state_names, freq_samples); | 411 SampleCpuFreqData(*cpu_count, cpu_freq_state_names, freq_samples); |
351 } | 412 } |
352 | 413 |
353 } // namespace | |
354 | |
355 // Set |cpu_count_| to -1 and let SampleCpuStateAsync discover the | 414 // Set |cpu_count_| to -1 and let SampleCpuStateAsync discover the |
356 // correct number of CPUs. | 415 // correct number of CPUs. |
357 CpuDataCollector::CpuDataCollector() : cpu_count_(-1), weak_ptr_factory_(this) { | 416 CpuDataCollector::CpuDataCollector() : cpu_count_(-1), weak_ptr_factory_(this) { |
358 } | 417 } |
359 | 418 |
360 CpuDataCollector::~CpuDataCollector() { | 419 CpuDataCollector::~CpuDataCollector() { |
361 } | 420 } |
362 | 421 |
363 void CpuDataCollector::Start() { | 422 void CpuDataCollector::Start() { |
364 timer_.Start(FROM_HERE, | 423 timer_.Start(FROM_HERE, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 : cpu_online(false) { | 499 : cpu_online(false) { |
441 } | 500 } |
442 | 501 |
443 CpuDataCollector::StateOccupancySample::StateOccupancySample( | 502 CpuDataCollector::StateOccupancySample::StateOccupancySample( |
444 const StateOccupancySample& other) = default; | 503 const StateOccupancySample& other) = default; |
445 | 504 |
446 CpuDataCollector::StateOccupancySample::~StateOccupancySample() { | 505 CpuDataCollector::StateOccupancySample::~StateOccupancySample() { |
447 } | 506 } |
448 | 507 |
449 } // namespace chromeos | 508 } // namespace chromeos |
OLD | NEW |