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
This commit is contained in:
@ -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',
|
||||
])
|
||||
|
@ -530,7 +530,7 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\process.cc"
|
||||
RelativePath="..\process_win.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
48
base/process_posix.cc
Normal file
48
base/process_posix.cc
Normal file
@ -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());
|
||||
}
|
||||
|
@ -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 {
|
||||
|
62
base/process_util_linux.cc
Normal file
62
base/process_util_linux.cc
Normal file
@ -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
|
@ -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.
|
||||
}
|
||||
|
Reference in New Issue
Block a user