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

Unified Diff: base/process_util_linux.cc

Issue 1689012: Move common code into process_util.cc (Closed)
Patch Set: More fixes Created 10 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util.cc ('k') | base/process_util_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « base/process_util.cc ('k') | base/process_util_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698