Add a bunch more systrace logging

Reviewed By: tadeuzagallo

Differential Revision: D3234831

fbshipit-source-id: 177f9b987e938c59d50fc07bce01fb5c912652e7
This commit is contained in:
Marc Horowitz 2016-05-13 17:15:05 -07:00 committed by Facebook Github Bot 8
parent 86f2eb18e5
commit 267264f1ec
3 changed files with 21 additions and 1 deletions

View File

@ -81,13 +81,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
- (void)setUpInstanceAndBridge - (void)setUpInstanceAndBridge
{ {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setUpInstanceAndBridge] [_instanceLock lock]", nil);
[_instanceLock lock]; [_instanceLock lock];
if (!_setupComplete && _bridge.valid) { if (!_setupComplete && _bridge.valid) {
if (!_instance) { if (!_instance) {
if (RCT_DEBUG && _requiresMainThreadSetup) { if (RCT_DEBUG && _requiresMainThreadSetup) {
RCTAssertMainThread(); RCTAssertMainThread();
} }
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setUpInstanceAndBridge] [_moduleClass new]", nil);
_instance = [_moduleClass new]; _instance = [_moduleClass new];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
if (!_instance) { if (!_instance) {
// Module init returned nil, probably because automatic instantatiation // Module init returned nil, probably because automatic instantatiation
// of the module is not supported, and it is supposed to be passed in to // of the module is not supported, and it is supposed to be passed in to
@ -109,6 +112,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
[self setBridgeForInstance]; [self setBridgeForInstance];
} }
[_instanceLock unlock]; [_instanceLock unlock];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
// This is called outside of the lock in order to prevent deadlock issues // This is called outside of the lock in order to prevent deadlock issues
// because the logic in `setUpMethodQueue` can cause `moduleData.instance` // because the logic in `setUpMethodQueue` can cause `moduleData.instance`
@ -126,6 +130,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
- (void)setBridgeForInstance - (void)setBridgeForInstance
{ {
if ([_instance respondsToSelector:@selector(bridge)] && _instance.bridge != _bridge) { if ([_instance respondsToSelector:@selector(bridge)] && _instance.bridge != _bridge) {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setBridgeForInstance]", nil);
@try { @try {
[(id)_instance setValue:_bridge forKey:@"bridge"]; [(id)_instance setValue:_bridge forKey:@"bridge"];
} }
@ -134,29 +139,32 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
"permitted. You must either @synthesize the bridge property, " "permitted. You must either @synthesize the bridge property, "
"or provide your own setter method.", self.name); "or provide your own setter method.", self.name);
} }
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
} }
} }
- (void)finishSetupForInstance - (void)finishSetupForInstance
{ {
if (!_setupComplete && _instance) { if (!_setupComplete && _instance) {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData finishSetupForInstance]", nil);
_setupComplete = YES; _setupComplete = YES;
[_bridge registerModuleForFrameUpdates:_instance withModuleData:self]; [_bridge registerModuleForFrameUpdates:_instance withModuleData:self];
[[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification [[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification
object:_bridge object:_bridge
userInfo:@{@"module": _instance}]; userInfo:@{@"module": _instance}];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
} }
} }
- (void)setUpMethodQueue - (void)setUpMethodQueue
{ {
if (_instance && !_methodQueue && _bridge.valid) { if (_instance && !_methodQueue && _bridge.valid) {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setUpMethodQueue]", nil);
BOOL implementsMethodQueue = [_instance respondsToSelector:@selector(methodQueue)]; BOOL implementsMethodQueue = [_instance respondsToSelector:@selector(methodQueue)];
if (implementsMethodQueue && _bridge.valid) { if (implementsMethodQueue && _bridge.valid) {
_methodQueue = _instance.methodQueue; _methodQueue = _instance.methodQueue;
} }
if (!_methodQueue && _bridge.valid) { if (!_methodQueue && _bridge.valid) {
// Create new queue (store queueName, as it isn't retained by dispatch_queue) // Create new queue (store queueName, as it isn't retained by dispatch_queue)
_queueName = [NSString stringWithFormat:@"com.facebook.react.%@Queue", self.name]; _queueName = [NSString stringWithFormat:@"com.facebook.react.%@Queue", self.name];
_methodQueue = dispatch_queue_create(_queueName.UTF8String, DISPATCH_QUEUE_SERIAL); _methodQueue = dispatch_queue_create(_queueName.UTF8String, DISPATCH_QUEUE_SERIAL);
@ -174,6 +182,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
} }
} }
} }
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
} }
} }
@ -193,9 +202,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
// calls out to other threads, however we can't control when a module might // calls out to other threads, however we can't control when a module might
// get accessed by client code during bridge setup, and a very low risk of // get accessed by client code during bridge setup, and a very low risk of
// deadlock is better than a fairly high risk of an assertion being thrown. // deadlock is better than a fairly high risk of an assertion being thrown.
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData instance] main thread setup", nil);
RCTExecuteOnMainThread(^{ RCTExecuteOnMainThread(^{
[self setUpInstanceAndBridge]; [self setUpInstanceAndBridge];
}, YES); }, YES);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
} else { } else {
[self setUpInstanceAndBridge]; [self setUpInstanceAndBridge];
} }
@ -252,11 +263,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
- (void)gatherConstants - (void)gatherConstants
{ {
if (_hasConstantsToExport && !_constantsToExport) { if (_hasConstantsToExport && !_constantsToExport) {
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData gatherConstants] %@", _moduleClass], nil);
(void)[self instance]; (void)[self instance];
RCTExecuteOnMainThread(^{ RCTExecuteOnMainThread(^{
_constantsToExport = [_instance constantsToExport] ?: @{}; _constantsToExport = [_instance constantsToExport] ?: @{};
}, YES); }, YES);
} }
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
} }
- (NSArray *)config - (NSArray *)config
@ -269,6 +282,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
return (id)kCFNull; // Nothing to export return (id)kCFNull; // Nothing to export
} }
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass], nil);
NSMutableArray<NSString *> *methods = self.methods.count ? [NSMutableArray new] : nil; NSMutableArray<NSString *> *methods = self.methods.count ? [NSMutableArray new] : nil;
NSMutableArray<NSNumber *> *asyncMethods = nil; NSMutableArray<NSNumber *> *asyncMethods = nil;
for (id<RCTBridgeMethod> method in self.methods) { for (id<RCTBridgeMethod> method in self.methods) {
@ -292,6 +307,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
[config addObject:asyncMethods]; [config addObject:asyncMethods];
} }
} }
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass], nil);
return config; return config;
} }

View File

@ -272,6 +272,7 @@ RCT_EXPORT_MODULE()
_pendingUIBlocks = nil; _pendingUIBlocks = nil;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"UIManager invalidate", nil);
for (NSNumber *rootViewTag in _rootViewTags) { for (NSNumber *rootViewTag in _rootViewTags) {
[(id<RCTInvalidating>)_viewRegistry[rootViewTag] invalidate]; [(id<RCTInvalidating>)_viewRegistry[rootViewTag] invalidate];
} }
@ -283,6 +284,7 @@ RCT_EXPORT_MODULE()
_bridge = nil; _bridge = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
}); });
} }

View File

@ -322,6 +322,7 @@ void RCTProfileHookModules(RCTBridge *bridge)
} }
#pragma clang diagnostic pop #pragma clang diagnostic pop
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"RCTProfileHookModules", nil);
for (RCTModuleData *moduleData in [bridge valueForKey:@"moduleDataByID"]) { for (RCTModuleData *moduleData in [bridge valueForKey:@"moduleDataByID"]) {
// Only hook modules with an instance, to prevent initializing everything // Only hook modules with an instance, to prevent initializing everything
if ([moduleData hasInstance]) { if ([moduleData hasInstance]) {
@ -330,6 +331,7 @@ void RCTProfileHookModules(RCTBridge *bridge)
} queue:moduleData.methodQueue]; } queue:moduleData.methodQueue];
} }
} }
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
} }
static void RCTProfileUnhookInstance(id instance) static void RCTProfileUnhookInstance(id instance)