Add minimal support for process_utils on iOS

Much of process_utils isn't meaningful on iOS, but this provides enough to support unit tests and minimal metrics.

BUG=None
TEST=None


Review URL: https://chromiumcodereview.appspot.com/10698149

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146123 0039d316-1c4b-4281-b951-d872f2087c98
parent 10b691f4
......@@ -434,6 +434,7 @@
'platform_file_unittest.cc',
'pr_time_unittest.cc',
'process_util_unittest.cc',
'process_util_unittest_ios.cc',
'process_util_unittest_mac.h',
'process_util_unittest_mac.mm',
'profiler/tracked_time_unittest.cc',
......
......@@ -272,6 +272,7 @@
'process_util.cc',
'process_util.h',
'process_util_freebsd.cc',
'process_util_ios.mm',
'process_util_linux.cc',
'process_util_mac.mm',
'process_util_openbsd.cc',
......@@ -572,11 +573,12 @@
['include', '^sys_string_conversions_mac\\.'],
['include', '^time_mac\\.'],
['include', '^worker_pool_mac\\.'],
# TODO(ios): Remove these as base/ is unforked.
# For now, exclude everything that doesn't build as-is, just to
# get something building on a bot.
['exclude', '^message_pump'],
# Exclude all process_util except the minimal implementation
# needed on iOS (mostly for unit tests).
['exclude', '^process_util'],
['include', '^process_util_ios\\.mm$'],
# TODO(ios): Add message_pump support.
['exclude', '^message_pump'],
],
}],
['OS != "mac" or >(nacl_untrusted_build)==1', {
......
......@@ -699,7 +699,7 @@ class BASE_EXPORT ProcessMetrics {
// Creates a ProcessMetrics for the specified process.
// The caller owns the returned object.
#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) || defined(OS_IOS)
static ProcessMetrics* CreateProcessMetrics(ProcessHandle process);
#else
class PortProvider {
......@@ -716,7 +716,7 @@ class BASE_EXPORT ProcessMetrics {
// only returns valid metrics if |process| is the current process.
static ProcessMetrics* CreateProcessMetrics(ProcessHandle process,
PortProvider* port_provider);
#endif // !defined(OS_MACOSX)
#endif // !defined(OS_MACOSX) || defined(OS_IOS)
// Returns the current space allocated for the pagefile, in bytes (these pages
// may or may not be in memory). On Linux, this returns the total virtual
......@@ -764,11 +764,11 @@ class BASE_EXPORT ProcessMetrics {
bool GetIOCounters(IoCounters* io_counters) const;
private:
#if !defined(OS_MACOSX)
#if !defined(OS_MACOSX) || defined(OS_IOS)
explicit ProcessMetrics(ProcessHandle process);
#else
ProcessMetrics(ProcessHandle process, PortProvider* port_provider);
#endif // defined(OS_MACOSX)
#endif // !defined(OS_MACOSX) || defined(OS_IOS)
ProcessHandle process_;
......@@ -779,6 +779,7 @@ class BASE_EXPORT ProcessMetrics {
int64 last_time_;
int64 last_system_time_;
#if !defined(OS_IOS)
#if defined(OS_MACOSX)
// Queries the port provider if it's set.
mach_port_t TaskForPid(ProcessHandle process) const;
......@@ -788,6 +789,7 @@ class BASE_EXPORT ProcessMetrics {
// Jiffie count at the last_time_ we updated.
int last_cpu_;
#endif // defined(OS_POSIX)
#endif // !defined(OS_IOS)
DISALLOW_COPY_AND_ASSIGN(ProcessMetrics);
};
......
// Copyright (c) 2012 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"
#import <Foundation/Foundation.h>
#include <mach/task.h>
#include <stdio.h>
#include "base/logging.h"
// This is just enough of a shim to let the support needed by test_support
// link. In general, process_util isn't valid on iOS.
namespace base {
namespace {
void StackDumpSignalHandler(int signal) {
LOG(ERROR) << "Received signal " << signal;
NSArray *stack_symbols = [NSThread callStackSymbols];
for (NSString* stack_symbol in stack_symbols) {
fprintf(stderr, "\t%s\n", [stack_symbol UTF8String]);
}
_exit(1);
}
bool GetTaskInfo(task_basic_info_64* task_info_data) {
mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
kern_return_t kr = task_info(mach_task_self(),
TASK_BASIC_INFO_64,
reinterpret_cast<task_info_t>(task_info_data),
&count);
return kr == KERN_SUCCESS;
}
} // namespace
ProcessId GetCurrentProcId() {
return getpid();
}
ProcessHandle GetCurrentProcessHandle() {
return GetCurrentProcId();
}
void EnableTerminationOnHeapCorruption() {
// On iOS, there nothing to do AFAIK.
}
void EnableTerminationOnOutOfMemory() {
// iOS provides this for free!
}
bool EnableInProcessStackDumping() {
// When running in an application, our code typically expects SIGPIPE
// to be ignored. Therefore, when testing that same code, it should run
// with SIGPIPE ignored as well.
struct sigaction action;
action.sa_handler = SIG_IGN;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
bool success = (sigaction(SIGPIPE, &action, NULL) == 0);
success &= (signal(SIGILL, &StackDumpSignalHandler) != SIG_ERR);
success &= (signal(SIGABRT, &StackDumpSignalHandler) != SIG_ERR);
success &= (signal(SIGFPE, &StackDumpSignalHandler) != SIG_ERR);
success &= (signal(SIGBUS, &StackDumpSignalHandler) != SIG_ERR);
success &= (signal(SIGSEGV, &StackDumpSignalHandler) != SIG_ERR);
success &= (signal(SIGSYS, &StackDumpSignalHandler) != SIG_ERR);
return success;
}
void RaiseProcessToHighPriority() {
// Impossible on iOS. Do nothing.
}
ProcessMetrics::ProcessMetrics(ProcessHandle process) {}
ProcessMetrics::~ProcessMetrics() {}
// static
ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
return new ProcessMetrics(process);
}
size_t ProcessMetrics::GetWorkingSetSize() const {
task_basic_info_64 task_info_data;
if (!GetTaskInfo(&task_info_data))
return 0;
return task_info_data.resident_size;
}
} // namespace base
// Copyright (c) 2012 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/memory/scoped_ptr.h"
#include "base/process_util.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(ProcessUtilTestIos, Memory) {
scoped_ptr<base::ProcessMetrics> process_metrics(
base::ProcessMetrics::CreateProcessMetrics(
base::GetCurrentProcessHandle()));
ASSERT_NE(0u, process_metrics->GetWorkingSetSize());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment