OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <dirent.h> | 8 #include <dirent.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <sys/wait.h> | 11 #include <sys/wait.h> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // Private and Shared working set sizes are obtained from /proc/<pid>/smaps, | 252 // Private and Shared working set sizes are obtained from /proc/<pid>/smaps, |
253 // as in http://www.pixelbeat.org/scripts/ps_mem.py | 253 // as in http://www.pixelbeat.org/scripts/ps_mem.py |
254 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { | 254 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { |
255 FilePath stat_file = | 255 FilePath stat_file = |
256 FilePath("/proc").Append(IntToString(process_)).Append("smaps"); | 256 FilePath("/proc").Append(IntToString(process_)).Append("smaps"); |
257 std::string smaps; | 257 std::string smaps; |
258 int shared_kb = 0; | 258 int shared_kb = 0; |
259 int private_kb = 0; | 259 int private_kb = 0; |
260 int pss_kb = 0; | 260 int pss_kb = 0; |
261 bool have_pss = false; | 261 bool have_pss = false; |
262 const int kPssAdjust = 0.5; | |
263 if (!file_util::ReadFileToString(stat_file, &smaps)) | 262 if (!file_util::ReadFileToString(stat_file, &smaps)) |
264 return false; | 263 return false; |
265 | 264 |
266 StringTokenizer tokenizer(smaps, ":\n"); | 265 StringTokenizer tokenizer(smaps, ":\n"); |
267 ParsingState state = KEY_NAME; | 266 ParsingState state = KEY_NAME; |
268 std::string last_key_name; | 267 std::string last_key_name; |
269 while (tokenizer.GetNext()) { | 268 while (tokenizer.GetNext()) { |
270 switch (state) { | 269 switch (state) { |
271 case KEY_NAME: | 270 case KEY_NAME: |
272 last_key_name = tokenizer.token(); | 271 last_key_name = tokenizer.token(); |
273 state = KEY_VALUE; | 272 state = KEY_VALUE; |
274 break; | 273 break; |
275 case KEY_VALUE: | 274 case KEY_VALUE: |
276 if (last_key_name.empty()) { | 275 if (last_key_name.empty()) { |
277 NOTREACHED(); | 276 NOTREACHED(); |
278 return false; | 277 return false; |
279 } | 278 } |
280 if (StartsWithASCII(last_key_name, "Shared_", 1)) { | 279 if (StartsWithASCII(last_key_name, "Shared_", 1)) { |
281 shared_kb += StringToInt(tokenizer.token()); | 280 shared_kb += StringToInt(tokenizer.token()); |
282 } else if (StartsWithASCII(last_key_name, "Private_", 1)) { | 281 } else if (StartsWithASCII(last_key_name, "Private_", 1)) { |
283 private_kb += StringToInt(tokenizer.token()); | 282 private_kb += StringToInt(tokenizer.token()); |
284 } else if (StartsWithASCII(last_key_name, "Pss", 1)) { | 283 } else if (StartsWithASCII(last_key_name, "Pss", 1)) { |
285 have_pss = true; | 284 have_pss = true; |
286 pss_kb += StringToInt(tokenizer.token()) + kPssAdjust; | 285 pss_kb += StringToInt(tokenizer.token()); |
287 } | 286 } |
288 state = KEY_NAME; | 287 state = KEY_NAME; |
289 break; | 288 break; |
290 } | 289 } |
291 } | 290 } |
292 ws_usage->priv = private_kb; | 291 ws_usage->priv = private_kb; |
293 // Sharable is not calculated, as it does not provide interesting data. | 292 // Sharable is not calculated, as it does not provide interesting data. |
294 ws_usage->shareable = 0; | 293 ws_usage->shareable = 0; |
295 | 294 |
296 ws_usage->shared = 0; | 295 ws_usage->shared = 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); | 332 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); |
334 } | 333 } |
335 state = KEY_NAME; | 334 state = KEY_NAME; |
336 break; | 335 break; |
337 } | 336 } |
338 } | 337 } |
339 return true; | 338 return true; |
340 } | 339 } |
341 | 340 |
342 } // namespace base | 341 } // namespace base |
OLD | NEW |