OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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; |
262 if (!file_util::ReadFileToString(stat_file, &smaps)) | 263 if (!file_util::ReadFileToString(stat_file, &smaps)) |
263 return false; | 264 return false; |
264 | 265 |
265 StringTokenizer tokenizer(smaps, ":\n"); | 266 StringTokenizer tokenizer(smaps, ":\n"); |
266 ParsingState state = KEY_NAME; | 267 ParsingState state = KEY_NAME; |
267 std::string last_key_name; | 268 std::string last_key_name; |
268 while (tokenizer.GetNext()) { | 269 while (tokenizer.GetNext()) { |
269 switch (state) { | 270 switch (state) { |
270 case KEY_NAME: | 271 case KEY_NAME: |
271 last_key_name = tokenizer.token(); | 272 last_key_name = tokenizer.token(); |
272 state = KEY_VALUE; | 273 state = KEY_VALUE; |
273 break; | 274 break; |
274 case KEY_VALUE: | 275 case KEY_VALUE: |
275 if (last_key_name.empty()) { | 276 if (last_key_name.empty()) { |
276 NOTREACHED(); | 277 NOTREACHED(); |
277 return false; | 278 return false; |
278 } | 279 } |
279 if (StartsWithASCII(last_key_name, "Shared_", 1)) { | 280 if (StartsWithASCII(last_key_name, "Shared_", 1)) { |
280 shared_kb += StringToInt(tokenizer.token()); | 281 shared_kb += StringToInt(tokenizer.token()); |
281 } else if (StartsWithASCII(last_key_name, "Private_", 1)) { | 282 } else if (StartsWithASCII(last_key_name, "Private_", 1)) { |
282 private_kb += StringToInt(tokenizer.token()); | 283 private_kb += StringToInt(tokenizer.token()); |
283 } else if (StartsWithASCII(last_key_name, "Pss", 1)) { | 284 } else if (StartsWithASCII(last_key_name, "Pss", 1)) { |
284 have_pss = true; | 285 have_pss = true; |
285 pss_kb += StringToInt(tokenizer.token()); | 286 pss_kb += StringToInt(tokenizer.token()) + kPssAdjust; |
286 } | 287 } |
287 state = KEY_NAME; | 288 state = KEY_NAME; |
288 break; | 289 break; |
289 } | 290 } |
290 } | 291 } |
291 ws_usage->priv = private_kb; | 292 ws_usage->priv = private_kb; |
292 // Sharable is not calculated, as it does not provide interesting data. | 293 // Sharable is not calculated, as it does not provide interesting data. |
293 ws_usage->shareable = 0; | 294 ws_usage->shareable = 0; |
294 if (have_pss) { | 295 if (have_pss) { |
295 ws_usage->shared = pss_kb - private_kb; | 296 ws_usage->shared = pss_kb - private_kb; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); | 334 (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); |
334 } | 335 } |
335 state = KEY_NAME; | 336 state = KEY_NAME; |
336 break; | 337 break; |
337 } | 338 } |
338 } | 339 } |
339 return true; | 340 return true; |
340 } | 341 } |
341 | 342 |
342 } // namespace base | 343 } // namespace base |
OLD | NEW |