diff options
author | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-14 20:49:16 +0000 |
---|---|---|
committer | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-14 20:49:16 +0000 |
commit | 0b100bc8b653af9c1a12794a7508d1269fafc156 (patch) | |
tree | d78f750536d7f60cdf460fdbc5bb39f74e9af29c /base | |
parent | 36b147bd8298c28e8ba4e7ab529b199aa3cce680 (diff) | |
download | chromium_src-0b100bc8b653af9c1a12794a7508d1269fafc156.zip chromium_src-0b100bc8b653af9c1a12794a7508d1269fafc156.tar.gz chromium_src-0b100bc8b653af9c1a12794a7508d1269fafc156.tar.bz2 |
Port parts of base/process_util to Linux.
Review URL: http://codereview.chromium.org/6492
Patch from Paweł Hajdan jr <phajdan.jr@gmail.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/SConscript | 5 | ||||
-rw-r--r-- | base/build/base.vcproj | 2 | ||||
-rw-r--r-- | base/process_posix.cc | 48 | ||||
-rw-r--r-- | base/process_util.h | 9 | ||||
-rw-r--r-- | base/process_util_linux.cc | 62 | ||||
-rw-r--r-- | base/process_util_posix.cc | 14 | ||||
-rw-r--r-- | base/process_win.cc (renamed from base/process.cc) | 0 |
7 files changed, 136 insertions, 4 deletions
diff --git a/base/SConscript b/base/SConscript index 3b5c8f9..252fab2f 100644 --- a/base/SConscript +++ b/base/SConscript @@ -91,8 +91,6 @@ if env['PLATFORM'] == 'win32': 'shared_event.cc', # Is this used? 'watchdog.cc', - 'process.cc', - 'resource_util.cc', # Uses HMODULE, but may be abstractable. ]) @@ -115,6 +113,7 @@ if env['PLATFORM'] == 'win32': 'pe_image.cc', 'platform_thread_win.cc', 'process_util_win.cc', + 'process_win.cc', 'rand_util_win.cc', 'registry.cc', 'shared_memory_win.cc', @@ -171,6 +170,8 @@ if env['PLATFORM'] == 'posix': 'hmac_nss.cc', 'message_pump_glib.cc', 'nss_init.cc', + 'process_posix.cc', + 'process_util_linux.cc', 'sys_string_conversions_linux.cc', 'worker_pool.cc', ]) diff --git a/base/build/base.vcproj b/base/build/base.vcproj index bbcfffc..69de369 100644 --- a/base/build/base.vcproj +++ b/base/build/base.vcproj @@ -530,7 +530,7 @@ > </File> <File - RelativePath="..\process.cc" + RelativePath="..\process_win.cc" > </File> <File diff --git a/base/process_posix.cc b/base/process_posix.cc new file mode 100644 index 0000000..2bc6b0c --- /dev/null +++ b/base/process_posix.cc @@ -0,0 +1,48 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/process.h" +#include "base/logging.h" +#include "base/process_util.h" + +bool Process::IsProcessBackgrounded() { + return false; +} + +bool Process::SetProcessBackgrounded(bool value) { + NOTIMPLEMENTED(); + return false; +} + +bool Process::ReduceWorkingSet() { + NOTIMPLEMENTED(); + return false; +} + +bool Process::UnReduceWorkingSet() { + NOTIMPLEMENTED(); + return false; +} + +bool Process::EmptyWorkingSet() { + NOTIMPLEMENTED(); + return false; +} + +int32 Process::pid() const { + if (process_ == 0) + return 0; + + return process_util::GetProcId(process_); +} + +bool Process::is_current() const { + return process_ == process_util::GetCurrentProcessHandle(); +} + +// static +Process Process::Current() { + return Process(process_util::GetCurrentProcessHandle()); +} + diff --git a/base/process_util.h b/base/process_util.h index e5e3e92..4f33bb0 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -24,7 +24,14 @@ typedef PROCESSENTRY32 ProcessEntry; typedef IO_COUNTERS IoCounters; #elif defined(OS_POSIX) typedef int ProcessEntry; -typedef int IoCounters; //TODO(awalker): replace with struct when available +struct IoCounters { + unsigned long long ReadOperationCount; + unsigned long long WriteOperationCount; + unsigned long long OtherOperationCount; + unsigned long long ReadTransferCount; + unsigned long long WriteTransferCount; + unsigned long long OtherTransferCount; +}; #endif namespace process_util { diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc new file mode 100644 index 0000000..e5bc5db --- /dev/null +++ b/base/process_util_linux.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/process_util.h" + +#include <string> + +#include "base/file_util.h" +#include "base/logging.h" +#include "base/string_tokenizer.h" +#include "base/string_util.h" + +namespace { + +enum ParsingState { + KEY_NAME, + KEY_VALUE +}; + +} // namespace + +namespace process_util { + +// To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING +// in your kernel configuration. +bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) { + std::string proc_io_contents; + if (!file_util::ReadFileToString(L"/proc/self/io", &proc_io_contents)) + return false; + + (*io_counters).OtherOperationCount = 0; + (*io_counters).OtherTransferCount = 0; + + StringTokenizer tokenizer(proc_io_contents, ": \n"); + ParsingState state = KEY_NAME; + std::string last_key_name; + while (tokenizer.GetNext()) { + switch (state) { + case KEY_NAME: + last_key_name = tokenizer.token(); + state = KEY_VALUE; + break; + case KEY_VALUE: + DCHECK(!last_key_name.empty()); + if (last_key_name == "syscr") { + (*io_counters).ReadOperationCount = StringToInt64(tokenizer.token()); + } else if (last_key_name == "syscw") { + (*io_counters).WriteOperationCount = StringToInt64(tokenizer.token()); + } else if (last_key_name == "rchar") { + (*io_counters).ReadTransferCount = StringToInt64(tokenizer.token()); + } else if (last_key_name == "wchar") { + (*io_counters).WriteTransferCount = StringToInt64(tokenizer.token()); + } + state = KEY_NAME; + break; + } + } + return true; +} + +} // namespace process_util diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 4d2f1e5..7439979 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -8,6 +8,7 @@ #include <unistd.h> #include "base/basictypes.h" +#include "base/sys_info.h" namespace process_util { @@ -23,6 +24,19 @@ int GetProcId(ProcessHandle process) { return process; } +ProcessMetrics::ProcessMetrics(ProcessHandle process) : process_(process), + last_time_(0), + last_system_time_(0) { + processor_count_ = base::SysInfo::NumberOfProcessors(); +} + +// static +ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) { + return new ProcessMetrics(process); +} + +ProcessMetrics::~ProcessMetrics() { } + void EnableTerminationOnHeapCorruption() { // On POSIX, there nothing to do AFAIK. } diff --git a/base/process.cc b/base/process_win.cc index 38fe63c..38fe63c 100644 --- a/base/process.cc +++ b/base/process_win.cc |