| 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 18 matching lines...) Expand all Loading... |
| 29 KEY_NAME, | 29 KEY_NAME, |
| 30 KEY_VALUE | 30 KEY_VALUE |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 #ifdef OS_CHROMEOS | 33 #ifdef OS_CHROMEOS |
| 34 // Read a file with a single number string and return the number as a uint64. | 34 // Read a file with a single number string and return the number as a uint64. |
| 35 static uint64 ReadFileToUint64(const base::FilePath file) { | 35 static uint64 ReadFileToUint64(const base::FilePath file) { |
| 36 std::string file_as_string; | 36 std::string file_as_string; |
| 37 if (!ReadFileToString(file, &file_as_string)) | 37 if (!ReadFileToString(file, &file_as_string)) |
| 38 return 0; | 38 return 0; |
| 39 TrimWhitespaceASCII(file_as_string, TRIM_ALL, &file_as_string); | 39 base::TrimWhitespaceASCII(file_as_string, base::TRIM_ALL, &file_as_string); |
| 40 uint64 file_as_uint64 = 0; | 40 uint64 file_as_uint64 = 0; |
| 41 if (!base::StringToUint64(file_as_string, &file_as_uint64)) | 41 if (!base::StringToUint64(file_as_string, &file_as_uint64)) |
| 42 return 0; | 42 return 0; |
| 43 return file_as_uint64; | 43 return file_as_uint64; |
| 44 } | 44 } |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 // Read /proc/<pid>/status and returns the value for |field|, or 0 on failure. | 47 // Read /proc/<pid>/status and returns the value for |field|, or 0 on failure. |
| 48 // Only works for fields in the form of "Field: value kB". | 48 // Only works for fields in the form of "Field: value kB". |
| 49 size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) { | 49 size_t ReadProcStatusAndGetFieldAsSizeT(pid_t pid, const std::string& field) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 64 case KEY_NAME: | 64 case KEY_NAME: |
| 65 last_key_name = tokenizer.token_piece(); | 65 last_key_name = tokenizer.token_piece(); |
| 66 state = KEY_VALUE; | 66 state = KEY_VALUE; |
| 67 break; | 67 break; |
| 68 case KEY_VALUE: | 68 case KEY_VALUE: |
| 69 DCHECK(!last_key_name.empty()); | 69 DCHECK(!last_key_name.empty()); |
| 70 if (last_key_name == field) { | 70 if (last_key_name == field) { |
| 71 std::string value_str; | 71 std::string value_str; |
| 72 tokenizer.token_piece().CopyToString(&value_str); | 72 tokenizer.token_piece().CopyToString(&value_str); |
| 73 std::string value_str_trimmed; | 73 std::string value_str_trimmed; |
| 74 TrimWhitespaceASCII(value_str, TRIM_ALL, &value_str_trimmed); | 74 base::TrimWhitespaceASCII(value_str, base::TRIM_ALL, |
| 75 &value_str_trimmed); |
| 75 std::vector<std::string> split_value_str; | 76 std::vector<std::string> split_value_str; |
| 76 SplitString(value_str_trimmed, ' ', &split_value_str); | 77 SplitString(value_str_trimmed, ' ', &split_value_str); |
| 77 if (split_value_str.size() != 2 || split_value_str[1] != "kB") { | 78 if (split_value_str.size() != 2 || split_value_str[1] != "kB") { |
| 78 NOTREACHED(); | 79 NOTREACHED(); |
| 79 return 0; | 80 return 0; |
| 80 } | 81 } |
| 81 size_t value; | 82 size_t value; |
| 82 if (!StringToSizeT(split_value_str[0], &value)) { | 83 if (!StringToSizeT(split_value_str[0], &value)) { |
| 83 NOTREACHED(); | 84 NOTREACHED(); |
| 84 return 0; | 85 return 0; |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads")); | 875 swap_info->num_reads = ReadFileToUint64(zram_path.Append("num_reads")); |
| 875 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); | 876 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); |
| 876 swap_info->compr_data_size = | 877 swap_info->compr_data_size = |
| 877 ReadFileToUint64(zram_path.Append("compr_data_size")); | 878 ReadFileToUint64(zram_path.Append("compr_data_size")); |
| 878 swap_info->mem_used_total = | 879 swap_info->mem_used_total = |
| 879 ReadFileToUint64(zram_path.Append("mem_used_total")); | 880 ReadFileToUint64(zram_path.Append("mem_used_total")); |
| 880 } | 881 } |
| 881 #endif // defined(OS_CHROMEOS) | 882 #endif // defined(OS_CHROMEOS) |
| 882 | 883 |
| 883 } // namespace base | 884 } // namespace base |
| OLD | NEW |