From d1fb26d457fd6628b9a92769d03bd1576a3e1730 Mon Sep 17 00:00:00 2001 From: tkchin Date: Wed, 3 Feb 2016 01:51:18 -0800 Subject: [PATCH] Add iOS tracing. BUG= Review URL: https://codereview.webrtc.org/1650993004 Cr-Commit-Position: refs/heads/master@{#11469} --- webrtc/base/BUILD.gn | 3 ++ webrtc/base/base.gyp | 3 ++ webrtc/base/objc/RTCMacros.h | 15 ++++++++++ webrtc/base/objc/RTCTracing.h | 21 ++++++++++++++ webrtc/base/objc/RTCTracing.mm | 29 +++++++++++++++++++ .../examples/objc/AppRTCDemo/ARDAppClient.m | 21 ++++++++++++++ .../objc/AppRTCDemo/ios/ARDAppDelegate.m | 3 ++ 7 files changed, 95 insertions(+) create mode 100644 webrtc/base/objc/RTCMacros.h create mode 100644 webrtc/base/objc/RTCTracing.h create mode 100644 webrtc/base/objc/RTCTracing.mm diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index fa8ddff751..c3a3f0ddbb 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -635,8 +635,11 @@ if (is_ios) { "objc/RTCDispatcher.m", "objc/RTCLogging.h", "objc/RTCLogging.mm", + "objc/RTCMacros.h", "objc/RTCSSLAdapter.h", "objc/RTCSSLAdapter.mm", + "objc/RTCTracing.h", + "objc/RTCTracing.mm", ] } } diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index f862eae311..b5ee37e396 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -39,8 +39,11 @@ 'objc/RTCDispatcher.m', 'objc/RTCLogging.h', 'objc/RTCLogging.mm', + 'objc/RTCMacros.h', 'objc/RTCSSLAdapter.h', 'objc/RTCSSLAdapter.mm', + 'objc/RTCTracing.h', + 'objc/RTCTracing.mm', ], 'conditions': [ ['OS=="ios"', { diff --git a/webrtc/base/objc/RTCMacros.h b/webrtc/base/objc/RTCMacros.h new file mode 100644 index 0000000000..9d4646bd21 --- /dev/null +++ b/webrtc/base/objc/RTCMacros.h @@ -0,0 +1,15 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#if defined(__cplusplus) + #define RTC_EXPORT extern "C" +#else + #define RTC_EXPORT extern +#endif diff --git a/webrtc/base/objc/RTCTracing.h b/webrtc/base/objc/RTCTracing.h new file mode 100644 index 0000000000..5b8e2f6ac3 --- /dev/null +++ b/webrtc/base/objc/RTCTracing.h @@ -0,0 +1,21 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import + +#import "webrtc/base/objc/RTCMacros.h" + +RTC_EXPORT void RTCSetupInternalTracer(); +/** Starts capture to specified file. Must be a valid writable path. + * Returns YES if capture starts. + */ +RTC_EXPORT BOOL RTCStartInternalCapture(NSString *filePath); +RTC_EXPORT void RTCStopInternalCapture(); +RTC_EXPORT void RTCShutdownInternalTracer(); diff --git a/webrtc/base/objc/RTCTracing.mm b/webrtc/base/objc/RTCTracing.mm new file mode 100644 index 0000000000..a51c703340 --- /dev/null +++ b/webrtc/base/objc/RTCTracing.mm @@ -0,0 +1,29 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#import "webrtc/base/objc/RTCTracing.h" + +#include "webrtc/base/event_tracer.h" + +void RTCSetupInternalTracer() { + rtc::tracing::SetupInternalTracer(); +} + +BOOL RTCStartInternalCapture(NSString *filePath) { + return rtc::tracing::StartInternalCapture(filePath.UTF8String); +} + +void RTCStopInternalCapture() { + rtc::tracing::StopInternalCapture(); +} + +void RTCShutdownInternalTracer() { + rtc::tracing::ShutdownInternalTracer(); +} diff --git a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m index 33e00ed443..47252bef1d 100644 --- a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m +++ b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m @@ -11,6 +11,7 @@ #import "ARDAppClient+Internal.h" #if defined(WEBRTC_IOS) +#import "webrtc/base/objc/RTCTracing.h" #import "RTCAVFoundationVideoSource.h" #endif #import "RTCFileLogger.h" @@ -48,6 +49,12 @@ static NSInteger const kARDAppClientErrorSetSDP = -4; static NSInteger const kARDAppClientErrorInvalidClient = -5; static NSInteger const kARDAppClientErrorInvalidRoom = -6; +// TODO(tkchin): Remove guard once rtc_base_objc compiles on Mac. +#if defined(WEBRTC_IOS) +// TODO(tkchin): Add this as a UI option. +static BOOL const kARDAppClientEnableTracing = NO; +#endif + // We need a proxy to NSTimer because it causes a strong retain cycle. When // using the proxy, |invalidate| must be called before it properly deallocs. @interface ARDTimerProxy : NSObject @@ -209,6 +216,17 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6; _isAudioOnly = isAudioOnly; self.state = kARDAppClientStateConnecting; +#if defined(WEBRTC_IOS) + if (kARDAppClientEnableTracing) { + NSArray *paths = NSSearchPathForDirectoriesInDomains( + NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirPath = paths.firstObject; + NSString *filePath = + [documentsDirPath stringByAppendingPathComponent:@"webrtc-trace.txt"]; + RTCStartInternalCapture(filePath); + } +#endif + // Request TURN. __weak ARDAppClient *weakSelf = self; [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, @@ -285,6 +303,9 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6; _messageQueue = [NSMutableArray array]; _peerConnection = nil; self.state = kARDAppClientStateDisconnected; +#if defined(WEBRTC_IOS) + RTCStopInternalCapture(); +#endif } #pragma mark - ARDSignalingChannelDelegate diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m b/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m index 9568b94e77..d815008cae 100644 --- a/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m +++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m @@ -10,6 +10,7 @@ #import "ARDAppDelegate.h" +#import "webrtc/base/objc/RTCTracing.h" #import "RTCLogging.h" #import "RTCPeerConnectionFactory.h" @@ -24,6 +25,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [RTCPeerConnectionFactory initializeSSL]; + RTCSetupInternalTracer(); _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [_window makeKeyAndVisible]; ARDMainViewController *viewController = [[ARDMainViewController alloc] init]; @@ -46,6 +48,7 @@ } - (void)applicationWillTerminate:(UIApplication *)application { + RTCShutdownInternalTracer(); [RTCPeerConnectionFactory deinitializeSSL]; }