Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: base/process/process_metrics_linux.cc

Issue 183853011: Move TrimWhitespace to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/nix/mime_util_xdg.cc ('k') | base/strings/string_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « base/nix/mime_util_xdg.cc ('k') | base/strings/string_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698