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

Side by Side Diff: base/process_util_ios.mm

Issue 10698149: Add minimal support for process_utils on iOS (Closed) Base URL: http://git.chromium.org/chromium/src.git@all-ios-tweak
Patch Set: Tweak include in gyp; eliminate patch bleed Created 8 years, 5 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 unified diff | Download patch
« no previous file with comments | « base/process_util.h ('k') | base/process_util_unittest_ios.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/process_util.h"
6
7 #import <Foundation/Foundation.h>
8 #include <mach/task.h>
9 #include <stdio.h>
10
11 #include "base/logging.h"
12
13 // This is just enough of a shim to let the support needed by test_support
14 // link. In general, process_util isn't valid on iOS.
15
16 namespace base {
17
18 namespace {
19
20 void StackDumpSignalHandler(int signal) {
21 LOG(ERROR) << "Received signal " << signal;
22 NSArray *stack_symbols = [NSThread callStackSymbols];
23 for (NSString* stack_symbol in stack_symbols) {
24 fprintf(stderr, "\t%s\n", [stack_symbol UTF8String]);
25 }
26 _exit(1);
27 }
28
29 bool GetTaskInfo(task_basic_info_64* task_info_data) {
30 mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT;
31 kern_return_t kr = task_info(mach_task_self(),
32 TASK_BASIC_INFO_64,
33 reinterpret_cast<task_info_t>(task_info_data),
34 &count);
35 return kr == KERN_SUCCESS;
36 }
37
38 } // namespace
39
40 ProcessId GetCurrentProcId() {
41 return getpid();
42 }
43
44 ProcessHandle GetCurrentProcessHandle() {
45 return GetCurrentProcId();
46 }
47
48 void EnableTerminationOnHeapCorruption() {
49 // On iOS, there nothing to do AFAIK.
50 }
51
52 void EnableTerminationOnOutOfMemory() {
53 // iOS provides this for free!
54 }
55
56 bool EnableInProcessStackDumping() {
57 // When running in an application, our code typically expects SIGPIPE
58 // to be ignored. Therefore, when testing that same code, it should run
59 // with SIGPIPE ignored as well.
60 struct sigaction action;
61 action.sa_handler = SIG_IGN;
62 action.sa_flags = 0;
63 sigemptyset(&action.sa_mask);
64 bool success = (sigaction(SIGPIPE, &action, NULL) == 0);
65
66 success &= (signal(SIGILL, &StackDumpSignalHandler) != SIG_ERR);
67 success &= (signal(SIGABRT, &StackDumpSignalHandler) != SIG_ERR);
68 success &= (signal(SIGFPE, &StackDumpSignalHandler) != SIG_ERR);
69 success &= (signal(SIGBUS, &StackDumpSignalHandler) != SIG_ERR);
70 success &= (signal(SIGSEGV, &StackDumpSignalHandler) != SIG_ERR);
71 success &= (signal(SIGSYS, &StackDumpSignalHandler) != SIG_ERR);
72
73 return success;
74 }
75
76 void RaiseProcessToHighPriority() {
77 // Impossible on iOS. Do nothing.
78 }
79
80 ProcessMetrics::ProcessMetrics(ProcessHandle process) {}
81
82 ProcessMetrics::~ProcessMetrics() {}
83
84 // static
85 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(ProcessHandle process) {
86 return new ProcessMetrics(process);
87 }
88
89 size_t ProcessMetrics::GetWorkingSetSize() const {
90 task_basic_info_64 task_info_data;
91 if (!GetTaskInfo(&task_info_data))
92 return 0;
93 return task_info_data.resident_size;
94 }
95
96 } // namespace base
OLDNEW
« no previous file with comments | « base/process_util.h ('k') | base/process_util_unittest_ios.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698