| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 return 0; | 60 return 0; |
| 61 } | 61 } |
| 62 | 62 |
| 63 StringPairs pairs; | 63 StringPairs pairs; |
| 64 SplitStringIntoKeyValuePairs(status, ':', '\n', &pairs); | 64 SplitStringIntoKeyValuePairs(status, ':', '\n', &pairs); |
| 65 TrimKeyValuePairs(&pairs); | 65 TrimKeyValuePairs(&pairs); |
| 66 for (size_t i = 0; i < pairs.size(); ++i) { | 66 for (size_t i = 0; i < pairs.size(); ++i) { |
| 67 const std::string& key = pairs[i].first; | 67 const std::string& key = pairs[i].first; |
| 68 const std::string& value_str = pairs[i].second; | 68 const std::string& value_str = pairs[i].second; |
| 69 if (key == field) { | 69 if (key == field) { |
| 70 std::vector<std::string> split_value_str; | 70 std::vector<StringPiece> split_value_str = SplitStringPiece( |
| 71 SplitString(value_str, ' ', &split_value_str); | 71 value_str, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 72 if (split_value_str.size() != 2 || split_value_str[1] != "kB") { | 72 if (split_value_str.size() != 2 || split_value_str[1] != "kB") { |
| 73 NOTREACHED(); | 73 NOTREACHED(); |
| 74 return 0; | 74 return 0; |
| 75 } | 75 } |
| 76 size_t value; | 76 size_t value; |
| 77 if (!StringToSizeT(split_value_str[0], &value)) { | 77 if (!StringToSizeT(split_value_str[0], &value)) { |
| 78 NOTREACHED(); | 78 NOTREACHED(); |
| 79 return 0; | 79 return 0; |
| 80 } | 80 } |
| 81 return value; | 81 return value; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 std::string statm; | 361 std::string statm; |
| 362 { | 362 { |
| 363 FilePath statm_file = internal::GetProcPidDir(process_).Append("statm"); | 363 FilePath statm_file = internal::GetProcPidDir(process_).Append("statm"); |
| 364 // Synchronously reading files in /proc does not hit the disk. | 364 // Synchronously reading files in /proc does not hit the disk. |
| 365 ThreadRestrictions::ScopedAllowIO allow_io; | 365 ThreadRestrictions::ScopedAllowIO allow_io; |
| 366 bool ret = ReadFileToString(statm_file, &statm); | 366 bool ret = ReadFileToString(statm_file, &statm); |
| 367 if (!ret || statm.length() == 0) | 367 if (!ret || statm.length() == 0) |
| 368 return false; | 368 return false; |
| 369 } | 369 } |
| 370 | 370 |
| 371 std::vector<std::string> statm_vec; | 371 std::vector<StringPiece> statm_vec = SplitStringPiece( |
| 372 SplitString(statm, ' ', &statm_vec); | 372 statm, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 373 if (statm_vec.size() != 7) | 373 if (statm_vec.size() != 7) |
| 374 return false; // Not the format we expect. | 374 return false; // Not the format we expect. |
| 375 | 375 |
| 376 int statm_rss, statm_shared; | 376 int statm_rss, statm_shared; |
| 377 bool ret = true; | 377 bool ret = true; |
| 378 ret &= StringToInt(statm_vec[1], &statm_rss); | 378 ret &= StringToInt(statm_vec[1], &statm_rss); |
| 379 ret &= StringToInt(statm_vec[2], &statm_shared); | 379 ret &= StringToInt(statm_vec[2], &statm_shared); |
| 380 | 380 |
| 381 ws_usage->priv = (statm_rss - statm_shared) * page_size_kb; | 381 ws_usage->priv = (statm_rss - statm_shared) * page_size_kb; |
| 382 ws_usage->shared = statm_shared * page_size_kb; | 382 ws_usage->shared = statm_shared * page_size_kb; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 #if defined(OS_LINUX) | 903 #if defined(OS_LINUX) |
| 904 int ProcessMetrics::GetIdleWakeupsPerSecond() { | 904 int ProcessMetrics::GetIdleWakeupsPerSecond() { |
| 905 uint64 wake_ups; | 905 uint64 wake_ups; |
| 906 const char kWakeupStat[] = "se.statistics.nr_wakeups"; | 906 const char kWakeupStat[] = "se.statistics.nr_wakeups"; |
| 907 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? | 907 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? |
| 908 CalculateIdleWakeupsPerSecond(wake_ups) : 0; | 908 CalculateIdleWakeupsPerSecond(wake_ups) : 0; |
| 909 } | 909 } |
| 910 #endif // defined(OS_LINUX) | 910 #endif // defined(OS_LINUX) |
| 911 | 911 |
| 912 } // namespace base | 912 } // namespace base |
| OLD | NEW |