| Index: base/process_util_linux.cc
|
| diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
|
| index 45e719c5a1fcda70621fcff0b7c8a0bccb2263c3..61ad97ec583146234e2933bff1be186b206f41dc 100644
|
| --- a/base/process_util_linux.cc
|
| +++ b/base/process_util_linux.cc
|
| @@ -19,6 +19,7 @@
|
| #include "base/logging.h"
|
| #include "base/string_tokenizer.h"
|
| #include "base/string_util.h"
|
| +#include "base/sys_info.h"
|
|
|
| namespace {
|
|
|
| @@ -87,32 +88,19 @@ FilePath GetProcessExecutablePath(ProcessHandle process) {
|
| return FilePath(std::string(exename, len));
|
| }
|
|
|
| -NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name,
|
| - const ProcessFilter* filter)
|
| - : executable_name_(executable_name), filter_(filter) {
|
| +ProcessIterator::ProcessIterator(const ProcessFilter* filter)
|
| + : filter_(filter) {
|
| procfs_dir_ = opendir("/proc");
|
| }
|
|
|
| -NamedProcessIterator::~NamedProcessIterator() {
|
| +ProcessIterator::~ProcessIterator() {
|
| if (procfs_dir_) {
|
| closedir(procfs_dir_);
|
| procfs_dir_ = NULL;
|
| }
|
| }
|
|
|
| -const ProcessEntry* NamedProcessIterator::NextProcessEntry() {
|
| - bool result = false;
|
| - do {
|
| - result = CheckForNextProcess();
|
| - } while (result && !IncludeEntry());
|
| -
|
| - if (result)
|
| - return &entry_;
|
| -
|
| - return NULL;
|
| -}
|
| -
|
| -bool NamedProcessIterator::CheckForNextProcess() {
|
| +bool ProcessIterator::CheckForNextProcess() {
|
| // TODO(port): skip processes owned by different UID
|
|
|
| dirent* slot = 0;
|
| @@ -155,8 +143,8 @@ bool NamedProcessIterator::CheckForNextProcess() {
|
| return false;
|
|
|
| // Parse the status. It is formatted like this:
|
| - // %d (%s) %c %d ...
|
| - // pid (name) runstate ppid
|
| + // %d (%s) %c %d %d ...
|
| + // pid (name) runstate ppid gid
|
| // To avoid being fooled by names containing a closing paren, scan
|
| // backwards.
|
| openparen = strchr(buf, '(');
|
| @@ -179,27 +167,37 @@ bool NamedProcessIterator::CheckForNextProcess() {
|
| return false;
|
| }
|
|
|
| - entry_.pid = atoi(slot->d_name);
|
| - entry_.ppid = atoi(closeparen + 3);
|
| + // This seems fragile.
|
| + entry_.pid_ = atoi(slot->d_name);
|
| + entry_.ppid_ = atoi(closeparen + 3);
|
| + entry_.gid_ = atoi(strchr(closeparen + 4, ' '));
|
|
|
| // TODO(port): read pid's commandline's $0, like killall does. Using the
|
| // short name between openparen and closeparen won't work for long names!
|
| int len = closeparen - openparen - 1;
|
| - if (len > NAME_MAX)
|
| - len = NAME_MAX;
|
| - memcpy(entry_.szExeFile, openparen + 1, len);
|
| - entry_.szExeFile[len] = 0;
|
| -
|
| + entry_.exe_file_.assign(openparen + 1, len);
|
| return true;
|
| }
|
|
|
| bool NamedProcessIterator::IncludeEntry() {
|
| // TODO(port): make this also work for non-ASCII filenames
|
| - if (WideToASCII(executable_name_) != entry_.szExeFile)
|
| + if (WideToASCII(executable_name_) != entry().exe_file())
|
| return false;
|
| - if (!filter_)
|
| - return true;
|
| - return filter_->Includes(entry_.pid, entry_.ppid);
|
| + return ProcessIterator::IncludeEntry();
|
| +}
|
| +
|
| +
|
| +ProcessMetrics::ProcessMetrics(ProcessHandle process)
|
| + : process_(process),
|
| + last_time_(0),
|
| + last_system_time_(0),
|
| + last_cpu_(0) {
|
| + processor_count_ = base::SysInfo::NumberOfProcessors();
|
| +}
|
| +
|
| +// static
|
| +ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
|
| + return new ProcessMetrics(process);
|
| }
|
|
|
| // On linux, we return vsize.
|
|
|