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

Side by Side Diff: base/process_util_linux.cc

Issue 3750001: base: Move SplitString functions into the base namespace and update the callers. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: brett review, reverted changes in o3d due to it's using an old base revision Created 10 years, 2 months 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
« no previous file with comments | « base/command_line.cc ('k') | base/string_split.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 <dlfcn.h> 9 #include <dlfcn.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 21 matching lines...) Expand all
32 32
33 // Reads /proc/<pid>/stat and populates |proc_stats| with the values split by 33 // Reads /proc/<pid>/stat and populates |proc_stats| with the values split by
34 // spaces. Returns true if successful. 34 // spaces. Returns true if successful.
35 bool GetProcStats(pid_t pid, std::vector<std::string>* proc_stats) { 35 bool GetProcStats(pid_t pid, std::vector<std::string>* proc_stats) {
36 FilePath stat_file("/proc"); 36 FilePath stat_file("/proc");
37 stat_file = stat_file.Append(base::IntToString(pid)); 37 stat_file = stat_file.Append(base::IntToString(pid));
38 stat_file = stat_file.Append("stat"); 38 stat_file = stat_file.Append("stat");
39 std::string mem_stats; 39 std::string mem_stats;
40 if (!file_util::ReadFileToString(stat_file, &mem_stats)) 40 if (!file_util::ReadFileToString(stat_file, &mem_stats))
41 return false; 41 return false;
42 SplitString(mem_stats, ' ', proc_stats); 42 base::SplitString(mem_stats, ' ', proc_stats);
43 return true; 43 return true;
44 } 44 }
45 45
46 // Reads /proc/<pid>/cmdline and populates |proc_cmd_line_args| with the command 46 // Reads /proc/<pid>/cmdline and populates |proc_cmd_line_args| with the command
47 // line arguments. Returns true if successful. 47 // line arguments. Returns true if successful.
48 // Note: /proc/<pid>/cmdline contains command line arguments separated by single 48 // Note: /proc/<pid>/cmdline contains command line arguments separated by single
49 // null characters. We tokenize it into a vector of strings using '\0' as a 49 // null characters. We tokenize it into a vector of strings using '\0' as a
50 // delimiter. 50 // delimiter.
51 bool GetProcCmdline(pid_t pid, std::vector<std::string>* proc_cmd_line_args) { 51 bool GetProcCmdline(pid_t pid, std::vector<std::string>* proc_cmd_line_args) {
52 FilePath cmd_line_file("/proc"); 52 FilePath cmd_line_file("/proc");
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if (page_size_kb <= 0) 351 if (page_size_kb <= 0)
352 return false; 352 return false;
353 353
354 stat_file = 354 stat_file =
355 FilePath("/proc").Append(base::IntToString(process_)).Append("statm"); 355 FilePath("/proc").Append(base::IntToString(process_)).Append("statm");
356 std::string statm; 356 std::string statm;
357 if (!file_util::ReadFileToString(stat_file, &statm) || statm.length() == 0) 357 if (!file_util::ReadFileToString(stat_file, &statm) || statm.length() == 0)
358 return false; 358 return false;
359 359
360 std::vector<std::string> statm_vec; 360 std::vector<std::string> statm_vec;
361 SplitString(statm, ' ', &statm_vec); 361 base::SplitString(statm, ' ', &statm_vec);
362 if (statm_vec.size() != 7) 362 if (statm_vec.size() != 7)
363 return false; // Not the format we expect. 363 return false; // Not the format we expect.
364 364
365 int statm1, statm2; 365 int statm1, statm2;
366 base::StringToInt(statm_vec[1], &statm1); 366 base::StringToInt(statm_vec[1], &statm1);
367 base::StringToInt(statm_vec[2], &statm2); 367 base::StringToInt(statm_vec[2], &statm2);
368 private_kb = (statm1 - statm2) * page_size_kb; 368 private_kb = (statm1 - statm2) * page_size_kb;
369 } 369 }
370 ws_usage->priv = private_kb; 370 ws_usage->priv = private_kb;
371 // Sharable is not calculated, as it does not provide interesting data. 371 // Sharable is not calculated, as it does not provide interesting data.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // /proc/<pid>/stat contains the process name in parens. In case the 427 // /proc/<pid>/stat contains the process name in parens. In case the
428 // process name itself contains parens, skip past them. 428 // process name itself contains parens, skip past them.
429 std::string::size_type rparen = input.rfind(')'); 429 std::string::size_type rparen = input.rfind(')');
430 if (rparen == std::string::npos) 430 if (rparen == std::string::npos)
431 return -1; 431 return -1;
432 432
433 // From here, we expect a bunch of space-separated fields, where the 433 // From here, we expect a bunch of space-separated fields, where the
434 // 0-indexed 11th and 12th are utime and stime. On two different machines 434 // 0-indexed 11th and 12th are utime and stime. On two different machines
435 // I found 42 and 39 fields, so let's just expect the ones we need. 435 // I found 42 and 39 fields, so let's just expect the ones we need.
436 std::vector<std::string> fields; 436 std::vector<std::string> fields;
437 SplitString(input.substr(rparen + 2), ' ', &fields); 437 base::SplitString(input.substr(rparen + 2), ' ', &fields);
438 if (fields.size() < 13) 438 if (fields.size() < 13)
439 return -1; // Output not in the format we expect. 439 return -1; // Output not in the format we expect.
440 440
441 int fields11, fields12; 441 int fields11, fields12;
442 base::StringToInt(fields[11], &fields11); 442 base::StringToInt(fields[11], &fields11);
443 base::StringToInt(fields[12], &fields12); 443 base::StringToInt(fields[12], &fields12);
444 return fields11 + fields12; 444 return fields11 + fields12;
445 } 445 }
446 446
447 // Get the total CPU of a single process. Return value is number of jiffies 447 // Get the total CPU of a single process. Return value is number of jiffies
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 675
676 if (!file_util::PathExists(oom_adj)) 676 if (!file_util::PathExists(oom_adj))
677 return false; 677 return false;
678 678
679 std::string score_str = base::IntToString(score); 679 std::string score_str = base::IntToString(score);
680 return (static_cast<int>(score_str.length()) == 680 return (static_cast<int>(score_str.length()) ==
681 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length())); 681 file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length()));
682 } 682 }
683 683
684 } // namespace base 684 } // namespace base
OLDNEW
« no previous file with comments | « base/command_line.cc ('k') | base/string_split.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698