OLD | NEW |
1 // Copyright (c) 2009 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 <errno.h> | 9 #include <errno.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 // Private and Shared working set sizes are obtained from /proc/<pid>/smaps, | 256 // Private and Shared working set sizes are obtained from /proc/<pid>/smaps, |
257 // as in http://www.pixelbeat.org/scripts/ps_mem.py | 257 // as in http://www.pixelbeat.org/scripts/ps_mem.py |
258 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { | 258 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { |
259 FilePath stat_file = | 259 FilePath stat_file = |
260 FilePath("/proc").Append(IntToString(process_)).Append("smaps"); | 260 FilePath("/proc").Append(IntToString(process_)).Append("smaps"); |
261 std::string smaps; | 261 std::string smaps; |
262 int private_kb = 0; | 262 int private_kb = 0; |
263 int pss_kb = 0; | 263 int pss_kb = 0; |
264 bool have_pss = false; | 264 bool have_pss = false; |
265 if (!file_util::ReadFileToString(stat_file, &smaps)) | 265 if (!file_util::ReadFileToString(stat_file, &smaps) || smaps.length() == 0) |
266 return false; | 266 return false; |
267 | 267 |
268 StringTokenizer tokenizer(smaps, ":\n"); | 268 StringTokenizer tokenizer(smaps, ":\n"); |
269 ParsingState state = KEY_NAME; | 269 ParsingState state = KEY_NAME; |
270 std::string last_key_name; | 270 std::string last_key_name; |
271 while (tokenizer.GetNext()) { | 271 while (tokenizer.GetNext()) { |
272 switch (state) { | 272 switch (state) { |
273 case KEY_NAME: | 273 case KEY_NAME: |
274 last_key_name = tokenizer.token(); | 274 last_key_name = tokenizer.token(); |
275 state = KEY_VALUE; | 275 state = KEY_VALUE; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 int percentage = 100 * (cpu - last_cpu_) / | 426 int percentage = 100 * (cpu - last_cpu_) / |
427 (kHertz * TimeDelta::FromMicroseconds(time_delta).InSecondsF()); | 427 (kHertz * TimeDelta::FromMicroseconds(time_delta).InSecondsF()); |
428 | 428 |
429 last_time_ = time; | 429 last_time_ = time; |
430 last_cpu_ = cpu; | 430 last_cpu_ = cpu; |
431 | 431 |
432 return percentage; | 432 return percentage; |
433 } | 433 } |
434 | 434 |
435 } // namespace base | 435 } // namespace base |
OLD | NEW |