| Index: base/process_util_linux.cc
|
| ===================================================================
|
| --- base/process_util_linux.cc (revision 54340)
|
| +++ base/process_util_linux.cc (working copy)
|
| @@ -17,6 +17,7 @@
|
|
|
| #include "base/file_util.h"
|
| #include "base/logging.h"
|
| +#include "base/string_number_conversions.h"
|
| #include "base/string_tokenizer.h"
|
| #include "base/string_util.h"
|
| #include "base/sys_info.h"
|
| @@ -32,7 +33,7 @@
|
| // spaces.
|
| void GetProcStats(pid_t pid, std::vector<std::string>* proc_stats) {
|
| FilePath stat_file("/proc");
|
| - stat_file = stat_file.Append(IntToString(pid));
|
| + stat_file = stat_file.Append(base::IntToString(pid));
|
| stat_file = stat_file.Append("stat");
|
| std::string mem_stats;
|
| if (!file_util::ReadFileToString(stat_file, &mem_stats))
|
| @@ -46,7 +47,7 @@
|
|
|
| ProcessId GetParentProcessId(ProcessHandle process) {
|
| FilePath stat_file("/proc");
|
| - stat_file = stat_file.Append(IntToString(process));
|
| + stat_file = stat_file.Append(base::IntToString(process));
|
| stat_file = stat_file.Append("status");
|
| std::string status;
|
| if (!file_util::ReadFileToString(stat_file, &status))
|
| @@ -64,7 +65,8 @@
|
| case KEY_VALUE:
|
| DCHECK(!last_key_name.empty());
|
| if (last_key_name == "PPid") {
|
| - pid_t ppid = StringToInt(tokenizer.token());
|
| + int ppid;
|
| + base::StringToInt(tokenizer.token(), &ppid);
|
| return ppid;
|
| }
|
| state = KEY_NAME;
|
| @@ -77,7 +79,7 @@
|
|
|
| FilePath GetProcessExecutablePath(ProcessHandle process) {
|
| FilePath stat_file("/proc");
|
| - stat_file = stat_file.Append(IntToString(process));
|
| + stat_file = stat_file.Append(base::IntToString(process));
|
| stat_file = stat_file.Append("exe");
|
| char exename[2048];
|
| ssize_t len = readlink(stat_file.value().c_str(), exename, sizeof(exename));
|
| @@ -205,8 +207,11 @@
|
| std::vector<std::string> proc_stats;
|
| GetProcStats(process_, &proc_stats);
|
| const size_t kVmSize = 22;
|
| - if (proc_stats.size() > kVmSize)
|
| - return static_cast<size_t>(StringToInt(proc_stats[kVmSize]));
|
| + if (proc_stats.size() > kVmSize) {
|
| + int vm_size;
|
| + base::StringToInt(proc_stats[kVmSize], &vm_size);
|
| + return static_cast<size_t>(vm_size);
|
| + }
|
| return 0;
|
| }
|
|
|
| @@ -215,8 +220,11 @@
|
| std::vector<std::string> proc_stats;
|
| GetProcStats(process_, &proc_stats);
|
| const size_t kVmPeak = 21;
|
| - if (proc_stats.size() > kVmPeak)
|
| - return static_cast<size_t>(StringToInt(proc_stats[kVmPeak]));
|
| + if (proc_stats.size() > kVmPeak) {
|
| + int vm_peak;
|
| + if (base::StringToInt(proc_stats[kVmPeak], &vm_peak))
|
| + return vm_peak;
|
| + }
|
| return 0;
|
| }
|
|
|
| @@ -226,8 +234,9 @@
|
| GetProcStats(process_, &proc_stats);
|
| const size_t kVmRss = 23;
|
| if (proc_stats.size() > kVmRss) {
|
| - size_t num_pages = static_cast<size_t>(StringToInt(proc_stats[kVmRss]));
|
| - return num_pages * getpagesize();
|
| + int num_pages;
|
| + if (base::StringToInt(proc_stats[kVmRss], &num_pages))
|
| + return static_cast<size_t>(num_pages) * getpagesize();
|
| }
|
| return 0;
|
| }
|
| @@ -238,8 +247,9 @@
|
| GetProcStats(process_, &proc_stats);
|
| const size_t kVmHwm = 23;
|
| if (proc_stats.size() > kVmHwm) {
|
| - size_t num_pages = static_cast<size_t>(StringToInt(proc_stats[kVmHwm]));
|
| - return num_pages * getpagesize();
|
| + int num_pages;
|
| + base::StringToInt(proc_stats[kVmHwm], &num_pages);
|
| + return static_cast<size_t>(num_pages) * getpagesize();
|
| }
|
| return 0;
|
| }
|
| @@ -265,7 +275,7 @@
|
| // See http://www.pixelbeat.org/scripts/ps_mem.py
|
| bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
|
| FilePath stat_file =
|
| - FilePath("/proc").Append(IntToString(process_)).Append("smaps");
|
| + FilePath("/proc").Append(base::IntToString(process_)).Append("smaps");
|
| std::string smaps;
|
| int private_kb = 0;
|
| int pss_kb = 0;
|
| @@ -288,10 +298,14 @@
|
| return false;
|
| }
|
| if (last_key_name.starts_with(private_prefix)) {
|
| - private_kb += StringToInt(tokenizer.token());
|
| + int cur;
|
| + base::StringToInt(tokenizer.token(), &cur);
|
| + private_kb += cur;
|
| } else if (last_key_name.starts_with(pss_prefix)) {
|
| have_pss = true;
|
| - pss_kb += StringToInt(tokenizer.token());
|
| + int cur;
|
| + base::StringToInt(tokenizer.token(), &cur);
|
| + pss_kb += cur;
|
| }
|
| state = KEY_NAME;
|
| break;
|
| @@ -305,7 +319,7 @@
|
| return false;
|
|
|
| stat_file =
|
| - FilePath("/proc").Append(IntToString(process_)).Append("statm");
|
| + FilePath("/proc").Append(base::IntToString(process_)).Append("statm");
|
| std::string statm;
|
| if (!file_util::ReadFileToString(stat_file, &statm) || statm.length() == 0)
|
| return false;
|
| @@ -314,8 +328,11 @@
|
| SplitString(statm, ' ', &statm_vec);
|
| if (statm_vec.size() != 7)
|
| return false; // Not the format we expect.
|
| - private_kb = StringToInt(statm_vec[1]) - StringToInt(statm_vec[2]);
|
| - private_kb *= page_size_kb;
|
| +
|
| + int statm1, statm2;
|
| + base::StringToInt(statm_vec[1], &statm1);
|
| + base::StringToInt(statm_vec[2], &statm2);
|
| + private_kb = (statm1 - statm2) * page_size_kb;
|
| }
|
| ws_usage->priv = private_kb;
|
| // Sharable is not calculated, as it does not provide interesting data.
|
| @@ -332,7 +349,7 @@
|
| bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
|
| std::string proc_io_contents;
|
| FilePath io_file("/proc");
|
| - io_file = io_file.Append(IntToString(process_));
|
| + io_file = io_file.Append(base::IntToString(process_));
|
| io_file = io_file.Append("io");
|
| if (!file_util::ReadFileToString(io_file, &proc_io_contents))
|
| return false;
|
| @@ -352,13 +369,17 @@
|
| case KEY_VALUE:
|
| DCHECK(!last_key_name.empty());
|
| if (last_key_name == "syscr") {
|
| - (*io_counters).ReadOperationCount = StringToInt64(tokenizer.token());
|
| + base::StringToInt64(tokenizer.token(),
|
| + reinterpret_cast<int64*>(&(*io_counters).ReadOperationCount));
|
| } else if (last_key_name == "syscw") {
|
| - (*io_counters).WriteOperationCount = StringToInt64(tokenizer.token());
|
| + base::StringToInt64(tokenizer.token(),
|
| + reinterpret_cast<int64*>(&(*io_counters).WriteOperationCount));
|
| } else if (last_key_name == "rchar") {
|
| - (*io_counters).ReadTransferCount = StringToInt64(tokenizer.token());
|
| + base::StringToInt64(tokenizer.token(),
|
| + reinterpret_cast<int64*>(&(*io_counters).ReadTransferCount));
|
| } else if (last_key_name == "wchar") {
|
| - (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token());
|
| + base::StringToInt64(tokenizer.token(),
|
| + reinterpret_cast<int64*>(&(*io_counters).WriteTransferCount));
|
| }
|
| state = KEY_NAME;
|
| break;
|
| @@ -384,7 +405,10 @@
|
| if (fields.size() < 13)
|
| return -1; // Output not in the format we expect.
|
|
|
| - return StringToInt(fields[11]) + StringToInt(fields[12]);
|
| + int fields11, fields12;
|
| + base::StringToInt(fields[11], &fields11);
|
| + base::StringToInt(fields[12], &fields12);
|
| + return fields11 + fields12;
|
| }
|
|
|
| // Get the total CPU of a single process. Return value is number of jiffies
|
| @@ -498,13 +522,13 @@
|
| DCHECK_EQ(meminfo_fields[kMemBuffersIndex-1], "Buffers:");
|
| DCHECK_EQ(meminfo_fields[kMemCacheIndex-1], "Cached:");
|
|
|
| - size_t result_in_kb;
|
| - result_in_kb = StringToInt(meminfo_fields[kMemTotalIndex]);
|
| - result_in_kb -= StringToInt(meminfo_fields[kMemFreeIndex]);
|
| - result_in_kb -= StringToInt(meminfo_fields[kMemBuffersIndex]);
|
| - result_in_kb -= StringToInt(meminfo_fields[kMemCacheIndex]);
|
| + int mem_total, mem_free, mem_buffers, mem_cache;
|
| + base::StringToInt(meminfo_fields[kMemTotalIndex], &mem_total);
|
| + base::StringToInt(meminfo_fields[kMemFreeIndex], &mem_free);
|
| + base::StringToInt(meminfo_fields[kMemBuffersIndex], &mem_buffers);
|
| + base::StringToInt(meminfo_fields[kMemCacheIndex], &mem_cache);
|
|
|
| - return result_in_kb;
|
| + return mem_total - mem_free - mem_buffers - mem_cache;
|
| }
|
|
|
| namespace {
|
| @@ -613,13 +637,13 @@
|
| return false;
|
|
|
| FilePath oom_adj("/proc");
|
| - oom_adj = oom_adj.Append(Int64ToString(process));
|
| + oom_adj = oom_adj.Append(base::Int64ToString(process));
|
| oom_adj = oom_adj.AppendASCII("oom_adj");
|
|
|
| if (!file_util::PathExists(oom_adj))
|
| return false;
|
|
|
| - std::string score_str = IntToString(score);
|
| + std::string score_str = base::IntToString(score);
|
| return (static_cast<int>(score_str.length()) ==
|
| file_util::WriteFile(oom_adj, score_str.c_str(), score_str.length()));
|
| }
|
|
|