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

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: 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
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 <iostream>
Mark Mentovai 2012/07/11 12:36:51 C++ system headers belong in a separate section th
stuartmorgan 2012/07/11 13:56:57 Done.
9 #include <mach/task.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 std::cerr << "\t" << [stack_symbol UTF8String] << "\n";
Mark Mentovai 2012/07/11 12:36:51 When do we ever use C++ streams and cerr as oppose
stuartmorgan 2012/07/11 13:56:57 Done.
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 } // anonymous namespace
Mark Mentovai 2012/07/11 12:36:51 Normally, anonymous namespaces just close with //
stuartmorgan 2012/07/11 13:56:57 Done.
39
40 ProcessId GetCurrentProcId() {
41 return getpid();
42 }
43
44 void EnableTerminationOnHeapCorruption() {
45 // On iOS, there nothing to do AFAIK.
46 }
47
48 void EnableTerminationOnOutOfMemory() {
49 // iOS provides this for free!
50 }
51
52 bool EnableInProcessStackDumping() {
53 // When running in an application, our code typically expects SIGPIPE
54 // to be ignored. Therefore, when testing that same code, it should run
55 // with SIGPIPE ignored as well.
56 struct sigaction action;
57 action.sa_handler = SIG_IGN;
58 action.sa_flags = 0;
59 sigemptyset(&action.sa_mask);
60 bool success = (sigaction(SIGPIPE, &action, NULL) == 0);
61
62 success &= (signal(SIGILL, &StackDumpSignalHandler) != SIG_ERR);
63 success &= (signal(SIGABRT, &StackDumpSignalHandler) != SIG_ERR);
64 success &= (signal(SIGFPE, &StackDumpSignalHandler) != SIG_ERR);
65 success &= (signal(SIGBUS, &StackDumpSignalHandler) != SIG_ERR);
66 success &= (signal(SIGSEGV, &StackDumpSignalHandler) != SIG_ERR);
67 success &= (signal(SIGSYS, &StackDumpSignalHandler) != SIG_ERR);
68
69 return success;
70 }
71
72 void RaiseProcessToHighPriority() {
73 // Impossible on iOS. Do nothing.
74 }
75
76 ProcessMetrics::ProcessMetrics(ProcessHandle process,
77 ProcessMetrics::PortProvider* port_provider) {}
Mark Mentovai 2012/07/11 12:36:51 The port provider interface is nonsense on iOS, wh
stuartmorgan 2012/07/11 13:56:57 Done. (I suspect it was the other way to avoid cha
Mark Mentovai 2012/07/11 14:04:21 stuartmorgan wrote:
stuartmorgan 2012/07/11 14:18:03 Sure, but the same logic applies to the CreateProc
78
79 ProcessMetrics::~ProcessMetrics() {}
80
81 // static
82 ProcessMetrics* ProcessMetrics::CreateProcessMetrics(
83 ProcessHandle process,
84 ProcessMetrics::PortProvider* port_provider) {
85 return new ProcessMetrics(process, port_provider);
86 }
87
88 size_t ProcessMetrics::GetWorkingSetSize() const {
89 task_basic_info_64 task_info_data;
90 if (!GetTaskInfo(&task_info_data))
91 return 0;
92 return task_info_data.resident_size;
93 }
94
95 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698