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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file_util.h" | |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
18 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
19 #include "base/task_scheduler/post_task.h" | 18 #include "base/task_scheduler/post_task.h" |
20 #include "chrome/browser/chromeos/power/power_data_collector.h" | 19 #include "chrome/browser/chromeos/power/power_data_collector.h" |
21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
22 | 21 |
(...skipping 18 matching lines...) Expand all Loading... | |
41 // Suffix of the path to the file listing the range of possible CPUs on the | 40 // Suffix of the path to the file listing the range of possible CPUs on the |
42 // system. | 41 // system. |
43 const char kPossibleCpuPathSuffix[] = "/possible"; | 42 const char kPossibleCpuPathSuffix[] = "/possible"; |
44 | 43 |
45 // Format of the suffix of the path to the file which contains information | 44 // Format of the suffix of the path to the file which contains information |
46 // about a particular CPU being online or offline. | 45 // about a particular CPU being online or offline. |
47 const char kCpuOnlinePathSuffixFormat[] = "/cpu%d/online"; | 46 const char kCpuOnlinePathSuffixFormat[] = "/cpu%d/online"; |
48 | 47 |
49 // Format of the suffix of the path to the file which contains freq state | 48 // Format of the suffix of the path to the file which contains freq state |
50 // information of a CPU. | 49 // information of a CPU. |
51 const char kCpuFreqTimeInStatePathSuffixOldFormat[] = | 50 const char kCpuFreqTimeInStatePathSuffixFormat[] = |
52 "/cpu%d/cpufreq/stats/time_in_state"; | 51 "/cpu%d/cpufreq/stats/time_in_state"; |
53 | 52 |
54 // The path to the file which contains cpu freq state informatino of a CPU | 53 // The path to the file which contains cpu freq state information of a CPU |
55 // in newer kernel. | 54 // in some kernels such as 3.14.0. |
Daniel Erat
2017/05/03 22:35:43
nit: would "in 3.14.0 or newer kernels" be more ac
weidongg
2017/05/03 23:16:09
Done.
| |
56 const char kCpuFreqTimeInStateNewPath[] = | 55 const char kCpuFreqAllTimeInStatePath[] = |
57 "/sys/devices/system/cpu/cpufreq/all_time_in_state"; | 56 "/sys/devices/system/cpu/cpufreq/all_time_in_state"; |
58 | 57 |
59 // Format of the suffix of the path to the directory which contains information | 58 // Format of the suffix of the path to the directory which contains information |
60 // about an idle state of a CPU on the system. | 59 // about an idle state of a CPU on the system. |
61 const char kCpuIdleStateDirPathSuffixFormat[] = "/cpu%d/cpuidle/state%d"; | 60 const char kCpuIdleStateDirPathSuffixFormat[] = "/cpu%d/cpuidle/state%d"; |
62 | 61 |
63 // Format of the suffix of the path to the file which contains the name of an | 62 // Format of the suffix of the path to the file which contains the name of an |
64 // idle state of a CPU. | 63 // idle state of a CPU. |
65 const char kCpuIdleStateNamePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/name"; | 64 const char kCpuIdleStateNamePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/name"; |
66 | 65 |
67 // Format of the suffix of the path which contains information about time spent | 66 // Format of the suffix of the path which contains information about time spent |
68 // in an idle state on a CPU. | 67 // in an idle state on a CPU. |
69 const char kCpuIdleStateTimePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/time"; | 68 const char kCpuIdleStateTimePathSuffixFormat[] = "/cpu%d/cpuidle/state%d/time"; |
70 | 69 |
71 // Returns the index at which |str| is in |vector|. If |str| is not present in | 70 // 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. | 71 // |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) { | 72 size_t EnsureInVector(const std::string& str, |
73 std::vector<std::string>* vector) { | |
74 for (size_t i = 0; i < vector->size(); ++i) { | 74 for (size_t i = 0; i < vector->size(); ++i) { |
75 if (str == (*vector)[i]) | 75 if (str == (*vector)[i]) |
76 return i; | 76 return i; |
77 } | 77 } |
78 | 78 |
79 // If this is reached, then it means |str| is not present in vector. Add it. | 79 // If this is reached, then it means |str| is not present in vector. Add it. |
80 vector->push_back(str); | 80 vector->push_back(str); |
81 return vector->size() - 1; | 81 return vector->size() - 1; |
82 } | 82 } |
83 | 83 |
(...skipping 17 matching lines...) Expand all Loading... | |
101 &cpu_online_string); | 101 &cpu_online_string); |
102 if (base::StringToInt(cpu_online_string, &online)) | 102 if (base::StringToInt(cpu_online_string, &online)) |
103 return online == kCpuOnlineStatus; | 103 return online == kCpuOnlineStatus; |
104 } | 104 } |
105 | 105 |
106 LOG(ERROR) << "Bad format or error reading " << cpu_online_file << ". " | 106 LOG(ERROR) << "Bad format or error reading " << cpu_online_file << ". " |
107 << "Assuming offline."; | 107 << "Assuming offline."; |
108 return false; | 108 return false; |
109 } | 109 } |
110 | 110 |
111 // Samples the CPU idle state information from sysfs. |cpu_count| is the number | 111 } // namespace |
112 // of possible CPUs on the system. Sample at index i in |idle_samples| | 112 |
113 // Samples the CPU idle state information from sysfs. |cpu_count| is the | |
114 // number of possible CPUs on the system. Sample at index i in |idle_samples| | |
113 // corresponds to the idle state information of the i-th CPU. | 115 // corresponds to the idle state information of the i-th CPU. |
114 void SampleCpuIdleData( | 116 void SampleCpuIdleData( |
115 int cpu_count, | 117 int cpu_count, |
116 std::vector<std::string>* cpu_idle_state_names, | 118 std::vector<std::string>* cpu_idle_state_names, |
117 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples) { | 119 std::vector<CpuDataCollector::StateOccupancySample>* idle_samples) { |
118 base::Time start_time = base::Time::Now(); | 120 base::Time start_time = base::Time::Now(); |
119 for (int cpu = 0; cpu < cpu_count; ++cpu) { | 121 for (int cpu = 0; cpu < cpu_count; ++cpu) { |
120 CpuDataCollector::StateOccupancySample idle_sample; | 122 CpuDataCollector::StateOccupancySample idle_sample; |
121 idle_sample.time = base::Time::Now(); | 123 idle_sample.time = base::Time::Now(); |
122 idle_sample.time_in_state.reserve(cpu_idle_state_names->size()); | 124 idle_sample.time_in_state.reserve(cpu_idle_state_names->size()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 idle_samples->clear(); | 164 idle_samples->clear(); |
163 return; | 165 return; |
164 } | 166 } |
165 | 167 |
166 base::TrimWhitespaceASCII(state_name, base::TRIM_ALL, &state_name); | 168 base::TrimWhitespaceASCII(state_name, base::TRIM_ALL, &state_name); |
167 base::TrimWhitespaceASCII(occupancy_time_string, base::TRIM_ALL, | 169 base::TrimWhitespaceASCII(occupancy_time_string, base::TRIM_ALL, |
168 &occupancy_time_string); | 170 &occupancy_time_string); |
169 if (base::StringToInt64(occupancy_time_string, &occupancy_time_usec)) { | 171 if (base::StringToInt64(occupancy_time_string, &occupancy_time_usec)) { |
170 // idle state occupancy time in sysfs is recorded in microseconds. | 172 // idle state occupancy time in sysfs is recorded in microseconds. |
171 int64_t time_in_state_ms = occupancy_time_usec / 1000; | 173 int64_t time_in_state_ms = occupancy_time_usec / 1000; |
172 size_t index = IndexInVector(state_name, cpu_idle_state_names); | 174 size_t index = EnsureInVector(state_name, cpu_idle_state_names); |
173 if (index >= idle_sample.time_in_state.size()) | 175 if (index >= idle_sample.time_in_state.size()) |
174 idle_sample.time_in_state.resize(index + 1); | 176 idle_sample.time_in_state.resize(index + 1); |
175 idle_sample.time_in_state[index] = time_in_state_ms; | 177 idle_sample.time_in_state[index] = time_in_state_ms; |
176 } else { | 178 } else { |
177 LOG(ERROR) << "Bad format in " << time_file_path << ". " | 179 LOG(ERROR) << "Bad format in " << time_file_path << ". " |
178 << "Dropping sample."; | 180 << "Dropping sample."; |
179 idle_samples->clear(); | 181 idle_samples->clear(); |
180 return; | 182 return; |
181 } | 183 } |
182 } | 184 } |
183 } | 185 } |
184 | 186 |
185 idle_samples->push_back(idle_sample); | 187 idle_samples->push_back(idle_sample); |
186 } | 188 } |
187 | 189 |
188 // If there was an interruption in sampling (like system suspended), | 190 // If there was an interruption in sampling (like system suspended), |
189 // discard the samples! | 191 // discard the samples! |
190 int64_t delay = | 192 int64_t delay = |
191 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); | 193 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); |
192 if (delay > kSamplingDurationLimitMs) { | 194 if (delay > kSamplingDurationLimitMs) { |
193 idle_samples->clear(); | 195 idle_samples->clear(); |
194 LOG(WARNING) << "Dropped an idle state sample due to excessive time delay: " | 196 LOG(WARNING) << "Dropped an idle state sample due to excessive time delay: " |
195 << delay << "milliseconds."; | 197 << delay << "milliseconds."; |
196 } | 198 } |
197 } | 199 } |
198 | 200 |
199 bool ReadCpuFreqFromOldFile( | 201 bool CpuDataCollector::ReadCpuFreqTimeInState( |
200 const std::string& path, | 202 const base::FilePath& path, |
201 std::vector<std::string>* cpu_freq_state_names, | 203 std::vector<std::string>* cpu_freq_state_names, |
202 CpuDataCollector::StateOccupancySample* freq_sample) { | 204 CpuDataCollector::StateOccupancySample* freq_sample) { |
203 std::string time_in_state_string; | 205 std::string time_in_state_string; |
204 // Note time as close to reading the file as possible. This is | 206 // Note time as close to reading the file as possible. This is |
205 // not possible for idle state samples as the information for | 207 // not possible for idle state samples as the information for |
206 // each state there is recorded in different files. | 208 // each state there is recorded in different files. |
207 if (!base::ReadFileToString(base::FilePath(path), &time_in_state_string)) { | 209 if (!base::ReadFileToString(path, &time_in_state_string)) { |
208 LOG(ERROR) << "Error reading " << path << ". " | 210 LOG(ERROR) << "Error reading " << path.value() << "; Dropping sample."; |
209 << "Dropping sample."; | |
210 return false; | 211 return false; |
211 } | 212 } |
213 // Remove trailing newlines. | |
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(); |
Daniel Erat
2017/05/03 22:35:43
remove this variable and just use lines.size() in
weidongg
2017/05/03 23:16:09
Done.
| |
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 LOG(ERROR) << "Bad format at \"" << lines[state] << "\" in " |
230 size_t index = IndexInVector(state_name, cpu_freq_state_names); | 231 << path.value() << ". Dropping sample."; |
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 << ". " | |
237 << "Dropping sample."; | |
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 freq_sample->time_in_state[index] = occupancy_time_centisecond * 10; | |
240 } | |
241 return true; | |
242 } | |
243 | |
244 bool CpuDataCollector::ReadCpuFreqAllTimeInState( | |
245 int cpu_count, | |
246 const base::FilePath& path, | |
247 std::vector<std::string>* cpu_freq_state_names, | |
248 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { | |
249 std::string all_time_in_state_string; | |
250 // Note time as close to reading the file as possible. This is | |
251 // not possible for idle state samples as the information for | |
252 // each state there is recorded in different files. | |
253 if (!base::ReadFileToString(path, &all_time_in_state_string)) { | |
254 LOG(ERROR) << "Error reading " << path.value() << "; Dropping sample."; | |
255 return false; | |
256 } | |
257 // Remove trailing newlines. | |
258 base::TrimWhitespaceASCII(all_time_in_state_string, | |
259 base::TrimPositions::TRIM_TRAILING, | |
260 &all_time_in_state_string); | |
261 | |
262 std::vector<base::StringPiece> lines = | |
263 base::SplitStringPiece(all_time_in_state_string, "\n", | |
264 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
265 size_t state_count = lines.size(); | |
Daniel Erat
2017/05/03 22:35:43
remove this variable and just use lines.size() in
weidongg
2017/05/03 23:16:09
Done.
| |
266 // The first line is descriptions in the format "freq\t\tcpu0\t\tcpu1...". | |
267 // Skip the first line, which contains column names. | |
268 for (size_t state = 1; state < state_count; ++state) { | |
Daniel Erat
2017/05/03 22:35:43
nit: line_num instead of state?
weidongg
2017/05/03 23:16:09
Done.
| |
269 // Occupancy of each state is in the format "<state>\t\t<time>\t\t<time> | |
270 // ..." | |
271 std::vector<base::StringPiece> array = base::SplitStringPiece( | |
272 lines[state], "\t", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
273 int freq_in_khz; | |
274 if (array.size() != static_cast<size_t>(cpu_count) + 1 || | |
275 !base::StringToInt(array[0], &freq_in_khz)) { | |
276 LOG(ERROR) << "Bad format at \"" << lines[state] << "\" in " | |
277 << path.value() << ". Dropping sample."; | |
278 return false; | |
279 } | |
280 | |
281 const std::string state_name = base::IntToString(freq_in_khz / 1000); | |
282 size_t index = EnsureInVector(state_name, cpu_freq_state_names); | |
283 for (int cpu = 0; cpu < cpu_count; ++cpu) { | |
284 if (!(*freq_samples)[cpu].cpu_online) { | |
285 continue; | |
286 } | |
287 if (index >= (*freq_samples)[cpu].time_in_state.size()) | |
288 (*freq_samples)[cpu].time_in_state.resize(index + 1); | |
289 int64_t occupancy_time_centisecond; | |
290 if (!base::StringToInt64(array[cpu + 1], &occupancy_time_centisecond)) { | |
291 LOG(ERROR) << "Bad format at \"" << lines[state] << "\" in " | |
292 << path.value() << ". Dropping sample."; | |
293 return false; | |
294 } | |
295 (*freq_samples)[cpu].time_in_state[index] = | |
296 occupancy_time_centisecond * 10; | |
297 } | |
240 } | 298 } |
241 return true; | 299 return true; |
242 } | 300 } |
243 | 301 |
244 // Samples the CPU freq state information from sysfs. |cpu_count| is the number | 302 // Samples the CPU freq state information from sysfs. |cpu_count| is the |
245 // of possible CPUs on the system. Sample at index i in |freq_samples| | 303 // number 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. | 304 // corresponds to the freq state information of the i-th CPU. |
247 void SampleCpuFreqData( | 305 void SampleCpuFreqData( |
Daniel Erat
2017/05/03 22:35:43
this should still be up in the anonymous namespace
weidongg
2017/05/03 23:16:09
Yes, I forgot to put them in the namespace.
| |
248 int cpu_count, | 306 int cpu_count, |
249 std::vector<std::string>* cpu_freq_state_names, | 307 std::vector<std::string>* cpu_freq_state_names, |
250 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { | 308 std::vector<CpuDataCollector::StateOccupancySample>* freq_samples) { |
251 base::Time start_time = base::Time::Now(); | 309 base::Time start_time = base::Time::Now(); |
252 for (int cpu = 0; cpu < cpu_count; ++cpu) { | 310 for (int cpu = 0; cpu < cpu_count; ++cpu) { |
253 CpuDataCollector::StateOccupancySample freq_sample; | 311 CpuDataCollector::StateOccupancySample freq_sample; |
254 freq_sample.time_in_state.reserve(cpu_freq_state_names->size()); | 312 freq_sample.time_in_state.reserve(cpu_freq_state_names->size()); |
313 freq_sample.time = base::Time::Now(); | |
314 freq_sample.cpu_online = CpuIsOnline(cpu); | |
315 freq_samples->push_back(freq_sample); | |
316 } | |
255 | 317 |
256 freq_sample.time = base::Time::Now(); | 318 if (base::PathExists(base::FilePath(kCpuFreqAllTimeInStatePath))) { |
257 if (!CpuIsOnline(cpu)) { | 319 if (!CpuDataCollector::ReadCpuFreqAllTimeInState( |
258 freq_sample.cpu_online = false; | 320 cpu_count, base::FilePath(kCpuFreqAllTimeInStatePath), |
259 } else { | 321 cpu_freq_state_names, freq_samples)) { |
260 freq_sample.cpu_online = true; | 322 freq_samples->clear(); |
261 | 323 return; |
262 const std::string time_in_state_path_old_format = base::StringPrintf( | 324 } |
263 "%s%s", kCpuDataPathBase, kCpuFreqTimeInStatePathSuffixOldFormat); | 325 } else { |
264 const std::string time_in_state_path = | 326 for (int cpu = 0; cpu < cpu_count; ++cpu) { |
265 base::StringPrintf(time_in_state_path_old_format.c_str(), cpu); | 327 if ((*freq_samples)[cpu].cpu_online) { |
266 if (base::PathExists(base::FilePath(time_in_state_path))) { | 328 const std::string time_in_state_path_old_format = base::StringPrintf( |
267 if (!ReadCpuFreqFromOldFile(time_in_state_path, cpu_freq_state_names, | 329 "%s%s", kCpuDataPathBase, kCpuFreqTimeInStatePathSuffixFormat); |
268 &freq_sample)) { | 330 const std::string time_in_state_path = |
Daniel Erat
2017/05/03 22:35:43
switch this to base::FilePath so that you aren't c
weidongg
2017/05/03 23:16:09
Done.
| |
331 base::StringPrintf(time_in_state_path_old_format.c_str(), cpu); | |
332 if (base::PathExists(base::FilePath(time_in_state_path))) { | |
333 if (!CpuDataCollector::ReadCpuFreqTimeInState( | |
334 base::FilePath(time_in_state_path), cpu_freq_state_names, | |
335 &(*freq_samples)[cpu])) { | |
336 freq_samples->clear(); | |
337 return; | |
338 } | |
339 } else { | |
340 // If the path to the 'time_in_state' for a single CPU is missing, | |
341 // then 'time_in_state' for all CPUs is missing. This could happen | |
342 // on a VM where the 'cpufreq_stats' kernel module is not loaded. | |
343 LOG_IF(ERROR, base::SysInfo::IsRunningOnChromeOS()) | |
344 << "CPU freq stats not available in sysfs."; | |
269 freq_samples->clear(); | 345 freq_samples->clear(); |
270 return; | 346 return; |
271 } | 347 } |
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 } | 348 } |
285 } | 349 } |
286 | |
287 freq_samples->push_back(freq_sample); | |
288 } | 350 } |
289 | |
290 // If there was an interruption in sampling (like system suspended), | 351 // If there was an interruption in sampling (like system suspended), |
291 // discard the samples! | 352 // discard the samples! |
292 int64_t delay = | 353 int64_t delay = |
293 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); | 354 base::TimeDelta(base::Time::Now() - start_time).InMilliseconds(); |
294 if (delay > kSamplingDurationLimitMs) { | 355 if (delay > kSamplingDurationLimitMs) { |
295 freq_samples->clear(); | 356 freq_samples->clear(); |
296 LOG(WARNING) << "Dropped a freq state sample due to excessive time delay: " | 357 LOG(WARNING) << "Dropped a freq state sample due to excessive time delay: " |
297 << delay << "milliseconds."; | 358 << delay << "milliseconds."; |
298 } | 359 } |
299 } | 360 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |