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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 if (!base::ReadFileToString(base::FilePath(time_in_state_path), | 225 if (!base::ReadFileToString(base::FilePath(time_in_state_path), |
226 &time_in_state_string)) { | 226 &time_in_state_string)) { |
227 LOG(ERROR) << "Error reading " << time_in_state_path << ". " | 227 LOG(ERROR) << "Error reading " << time_in_state_path << ". " |
228 << "Dropping sample."; | 228 << "Dropping sample."; |
229 freq_samples->clear(); | 229 freq_samples->clear(); |
230 return; | 230 return; |
231 } | 231 } |
232 | 232 |
233 freq_sample.time = now; | 233 freq_sample.time = now; |
234 | 234 |
235 std::vector<std::string> lines; | 235 std::vector<base::StringPiece> lines = |
236 base::SplitString(time_in_state_string, '\n', &lines); | 236 base::SplitStringPiece(time_in_state_string, "\n", |
| 237 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
237 // The last line could end with '\n'. Ignore the last empty string in | 238 // The last line could end with '\n'. Ignore the last empty string in |
238 // such cases. | 239 // such cases. |
239 size_t state_count = lines.size(); | 240 size_t state_count = lines.size(); |
240 if (state_count > 0 && lines.back().empty()) | 241 if (state_count > 0 && lines.back().empty()) |
241 state_count -= 1; | 242 state_count -= 1; |
242 for (size_t state = 0; state < state_count; ++state) { | 243 for (size_t state = 0; state < state_count; ++state) { |
243 std::vector<std::string> pair; | |
244 int freq_in_khz; | 244 int freq_in_khz; |
245 int64 occupancy_time_centisecond; | 245 int64 occupancy_time_centisecond; |
246 | 246 |
247 // Occupancy of each state is in the format "<state> <time>" | 247 // Occupancy of each state is in the format "<state> <time>" |
248 base::SplitString(lines[state], ' ', &pair); | 248 std::vector<base::StringPiece> pair = base::SplitStringPiece( |
249 for (size_t s = 0; s < pair.size(); ++s) | 249 lines[state], " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
250 base::TrimWhitespace(pair[s], base::TRIM_ALL, &pair[s]); | |
251 if (pair.size() == 2 && | 250 if (pair.size() == 2 && |
252 base::StringToInt(pair[0], &freq_in_khz) && | 251 base::StringToInt(pair[0], &freq_in_khz) && |
253 base::StringToInt64(pair[1], &occupancy_time_centisecond)) { | 252 base::StringToInt64(pair[1], &occupancy_time_centisecond)) { |
254 const std::string state_name = base::IntToString(freq_in_khz / 1000); | 253 const std::string state_name = base::IntToString(freq_in_khz / 1000); |
255 size_t index = IndexInVector(state_name, cpu_freq_state_names); | 254 size_t index = IndexInVector(state_name, cpu_freq_state_names); |
256 if (index >= freq_sample.time_in_state.size()) | 255 if (index >= freq_sample.time_in_state.size()) |
257 freq_sample.time_in_state.resize(index + 1); | 256 freq_sample.time_in_state.resize(index + 1); |
258 // The occupancy time is in units of centiseconds. | 257 // The occupancy time is in units of centiseconds. |
259 freq_sample.time_in_state[index] = occupancy_time_centisecond * 10; | 258 freq_sample.time_in_state[index] = occupancy_time_centisecond * 10; |
260 } else { | 259 } else { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 420 } |
422 | 421 |
423 CpuDataCollector::StateOccupancySample::StateOccupancySample() | 422 CpuDataCollector::StateOccupancySample::StateOccupancySample() |
424 : cpu_online(false) { | 423 : cpu_online(false) { |
425 } | 424 } |
426 | 425 |
427 CpuDataCollector::StateOccupancySample::~StateOccupancySample() { | 426 CpuDataCollector::StateOccupancySample::~StateOccupancySample() { |
428 } | 427 } |
429 | 428 |
430 } // namespace chromeos | 429 } // namespace chromeos |
OLD | NEW |