From 267264f1ecd00730a26b0aee6f7b502cdf4de03f Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Fri, 13 May 2016 17:15:05 -0700 Subject: [PATCH] Add a bunch more systrace logging Reviewed By: tadeuzagallo Differential Revision: D3234831 fbshipit-source-id: 177f9b987e938c59d50fc07bce01fb5c912652e7 --- React/Base/RCTModuleData.m | 18 +++++++++++++++++- React/Modules/RCTUIManager.m | 2 ++ React/Profiler/RCTProfile.m | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTModuleData.m b/React/Base/RCTModuleData.m index 6ef07ae07..62f9232df 100644 --- a/React/Base/RCTModuleData.m +++ b/React/Base/RCTModuleData.m @@ -81,13 +81,16 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); - (void)setUpInstanceAndBridge { + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setUpInstanceAndBridge] [_instanceLock lock]", nil); [_instanceLock lock]; if (!_setupComplete && _bridge.valid) { if (!_instance) { if (RCT_DEBUG && _requiresMainThreadSetup) { RCTAssertMainThread(); } + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setUpInstanceAndBridge] [_moduleClass new]", nil); _instance = [_moduleClass new]; + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); if (!_instance) { // Module init returned nil, probably because automatic instantatiation // 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]; } [_instanceLock unlock]; + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); // This is called outside of the lock in order to prevent deadlock issues // because the logic in `setUpMethodQueue` can cause `moduleData.instance` @@ -126,6 +130,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); - (void)setBridgeForInstance { if ([_instance respondsToSelector:@selector(bridge)] && _instance.bridge != _bridge) { + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setBridgeForInstance]", nil); @try { [(id)_instance setValue:_bridge forKey:@"bridge"]; } @@ -134,29 +139,32 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); "permitted. You must either @synthesize the bridge property, " "or provide your own setter method.", self.name); } + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); } } - (void)finishSetupForInstance { if (!_setupComplete && _instance) { + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData finishSetupForInstance]", nil); _setupComplete = YES; [_bridge registerModuleForFrameUpdates:_instance withModuleData:self]; [[NSNotificationCenter defaultCenter] postNotificationName:RCTDidInitializeModuleNotification object:_bridge userInfo:@{@"module": _instance}]; + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); } } - (void)setUpMethodQueue { if (_instance && !_methodQueue && _bridge.valid) { + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData setUpMethodQueue]", nil); BOOL implementsMethodQueue = [_instance respondsToSelector:@selector(methodQueue)]; if (implementsMethodQueue && _bridge.valid) { _methodQueue = _instance.methodQueue; } if (!_methodQueue && _bridge.valid) { - // Create new queue (store queueName, as it isn't retained by dispatch_queue) _queueName = [NSString stringWithFormat:@"com.facebook.react.%@Queue", self.name]; _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 // 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. + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTModuleData instance] main thread setup", nil); RCTExecuteOnMainThread(^{ [self setUpInstanceAndBridge]; }, YES); + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); } else { [self setUpInstanceAndBridge]; } @@ -252,11 +263,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); - (void)gatherConstants { if (_hasConstantsToExport && !_constantsToExport) { + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData gatherConstants] %@", _moduleClass], nil); (void)[self instance]; RCTExecuteOnMainThread(^{ _constantsToExport = [_instance constantsToExport] ?: @{}; }, YES); } + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); } - (NSArray *)config @@ -269,6 +282,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); return (id)kCFNull; // Nothing to export } + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass], nil); + NSMutableArray *methods = self.methods.count ? [NSMutableArray new] : nil; NSMutableArray *asyncMethods = nil; for (id method in self.methods) { @@ -292,6 +307,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); [config addObject:asyncMethods]; } } + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData config] %@", _moduleClass], nil); return config; } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 4b33bb91d..c3af919ec 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -272,6 +272,7 @@ RCT_EXPORT_MODULE() _pendingUIBlocks = nil; dispatch_async(dispatch_get_main_queue(), ^{ + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"UIManager invalidate", nil); for (NSNumber *rootViewTag in _rootViewTags) { [(id)_viewRegistry[rootViewTag] invalidate]; } @@ -283,6 +284,7 @@ RCT_EXPORT_MODULE() _bridge = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); }); } diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index 067949b4b..a2aa37cae 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -322,6 +322,7 @@ void RCTProfileHookModules(RCTBridge *bridge) } #pragma clang diagnostic pop + RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"RCTProfileHookModules", nil); for (RCTModuleData *moduleData in [bridge valueForKey:@"moduleDataByID"]) { // Only hook modules with an instance, to prevent initializing everything if ([moduleData hasInstance]) { @@ -330,6 +331,7 @@ void RCTProfileHookModules(RCTBridge *bridge) } queue:moduleData.methodQueue]; } } + RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil); } static void RCTProfileUnhookInstance(id instance)