OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/internal_linux.h" | 5 #include "base/process/internal_linux.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void ParseProcStat(const std::string& contents, ProcStatMap* output) { | 108 void ParseProcStat(const std::string& contents, ProcStatMap* output) { |
109 typedef std::pair<std::string, std::string> StringPair; | 109 typedef std::pair<std::string, std::string> StringPair; |
110 std::vector<StringPair> key_value_pairs; | 110 std::vector<StringPair> key_value_pairs; |
111 SplitStringIntoKeyValuePairs(contents, ' ', '\n', &key_value_pairs); | 111 SplitStringIntoKeyValuePairs(contents, ' ', '\n', &key_value_pairs); |
112 for (size_t i = 0; i < key_value_pairs.size(); ++i) { | 112 for (size_t i = 0; i < key_value_pairs.size(); ++i) { |
113 const StringPair& key_value_pair = key_value_pairs[i]; | 113 const StringPair& key_value_pair = key_value_pairs[i]; |
114 output->insert(key_value_pair); | 114 output->insert(key_value_pair); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 int GetProcStatsFieldAsInt(const std::vector<std::string>& proc_stats, | 118 int64 GetProcStatsFieldAsInt64(const std::vector<std::string>& proc_stats, |
119 ProcStatsFields field_num) { | 119 ProcStatsFields field_num) { |
120 DCHECK_GE(field_num, VM_PPID); | 120 DCHECK_GE(field_num, VM_PPID); |
121 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); | 121 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); |
122 | 122 |
123 int value; | 123 int64 value; |
124 return StringToInt(proc_stats[field_num], &value) ? value : 0; | 124 return StringToInt64(proc_stats[field_num], &value) ? value : 0; |
125 } | 125 } |
126 | 126 |
127 size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats, | 127 size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats, |
128 ProcStatsFields field_num) { | 128 ProcStatsFields field_num) { |
129 DCHECK_GE(field_num, VM_PPID); | 129 DCHECK_GE(field_num, VM_PPID); |
130 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); | 130 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); |
131 | 131 |
132 size_t value; | 132 size_t value; |
133 return StringToSizeT(proc_stats[field_num], &value) ? value : 0; | 133 return StringToSizeT(proc_stats[field_num], &value) ? value : 0; |
134 } | 134 } |
135 | 135 |
136 int ReadProcStatsAndGetFieldAsInt(pid_t pid, | 136 int64 ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) { |
137 ProcStatsFields field_num) { | |
138 std::string stats_data; | 137 std::string stats_data; |
139 if (!ReadProcStats(pid, &stats_data)) | 138 if (!ReadProcStats(pid, &stats_data)) |
140 return 0; | 139 return 0; |
141 std::vector<std::string> proc_stats; | 140 std::vector<std::string> proc_stats; |
142 if (!ParseProcStats(stats_data, &proc_stats)) | 141 if (!ParseProcStats(stats_data, &proc_stats)) |
143 return 0; | 142 return 0; |
144 return GetProcStatsFieldAsInt(proc_stats, field_num); | 143 return GetProcStatsFieldAsInt64(proc_stats, field_num); |
145 } | 144 } |
146 | 145 |
147 size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid, | 146 size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid, |
148 ProcStatsFields field_num) { | 147 ProcStatsFields field_num) { |
149 std::string stats_data; | 148 std::string stats_data; |
150 if (!ReadProcStats(pid, &stats_data)) | 149 if (!ReadProcStats(pid, &stats_data)) |
151 return 0; | 150 return 0; |
152 std::vector<std::string> proc_stats; | 151 std::vector<std::string> proc_stats; |
153 if (!ParseProcStats(stats_data, &proc_stats)) | 152 if (!ParseProcStats(stats_data, &proc_stats)) |
154 return 0; | 153 return 0; |
(...skipping 26 matching lines...) Expand all Loading... |
181 // which means the answer is 100. | 180 // which means the answer is 100. |
182 // It may be the case that this value is always 100. | 181 // It may be the case that this value is always 100. |
183 static const int kHertz = sysconf(_SC_CLK_TCK); | 182 static const int kHertz = sysconf(_SC_CLK_TCK); |
184 | 183 |
185 return TimeDelta::FromMicroseconds( | 184 return TimeDelta::FromMicroseconds( |
186 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); | 185 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); |
187 } | 186 } |
188 | 187 |
189 } // namespace internal | 188 } // namespace internal |
190 } // namespace base | 189 } // namespace base |
OLD | NEW |