summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-11 15:35:02 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-11 15:35:02 +0000
commitb80ffe2725c3d5ca17d21e3743c06689bca46935 (patch)
tree364402d24c482849153c3518708dfeac9bd57983 /base
parent10b691f4261e09a0c824ecec44f37ac74fc4dcec (diff)
downloadchromium_src-b80ffe2725c3d5ca17d21e3743c06689bca46935.zip
chromium_src-b80ffe2725c3d5ca17d21e3743c06689bca46935.tar.gz
chromium_src-b80ffe2725c3d5ca17d21e3743c06689bca46935.tar.bz2
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
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp1
-rw-r--r--base/base.gypi10
-rw-r--r--base/process_util.h10
-rw-r--r--base/process_util_ios.mm96
-rw-r--r--base/process_util_unittest_ios.cc15
5 files changed, 124 insertions, 8 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 40f3ce5..22798dd 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -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',
diff --git a/base/base.gypi b/base/base.gypi
index 612e9c1..b605ae5 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -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', {
diff --git a/base/process_util.h b/base/process_util.h
index ae5c994..eba109b 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -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);
};
diff --git a/base/process_util_ios.mm b/base/process_util_ios.mm
new file mode 100644
index 0000000..6cc4926
--- /dev/null
+++ b/base/process_util_ios.mm
@@ -0,0 +1,96 @@
+// 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
diff --git a/base/process_util_unittest_ios.cc b/base/process_util_unittest_ios.cc
new file mode 100644
index 0000000..c82535d
--- /dev/null
+++ b/base/process_util_unittest_ios.cc
@@ -0,0 +1,15 @@
+// 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());
+}