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

Side by Side Diff: base/process_util_linux.cc

Issue 339012: Report "N/A" for memory columns in Linux Task Manager. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Also fix minor bug in linux PorcessMetrics Created 11 years, 1 month 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 | « no previous file | chrome/browser/task_manager.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) 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
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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/task_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698