Add iOS tracing.

BUG=

Review URL: https://codereview.webrtc.org/1650993004

Cr-Commit-Position: refs/heads/master@{#11469}
This commit is contained in:
tkchin 2016-02-03 01:51:18 -08:00 committed by Commit bot
parent 8e85a3f39a
commit d1fb26d457
7 changed files with 95 additions and 0 deletions

View File

@ -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",
]
}
}

View File

@ -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"', {

View File

@ -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

View File

@ -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 <Foundation/Foundation.h>
#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();

View File

@ -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();
}

View File

@ -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

View File

@ -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];
}