From 41f5a21b56a19c8059595850e0f7782b2ba70fc8 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 3 Feb 2016 07:10:52 -0800 Subject: [PATCH] Improve systrace markers Reviewed By: jspahrsummers Differential Revision: D2851737 fb-gh-sync-id: 4aa0872e7d56d59de2fa42b87a795b2d64e0faa0 --- React/Base/RCTBatchedBridge.m | 12 +++++++----- React/Base/RCTRootView.m | 10 ++++++++-- React/Executors/RCTJSCExecutor.m | 13 +++++++------ React/Profiler/RCTProfile.h | 15 ++++++++------- React/Profiler/RCTProfile.m | 7 +++---- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index 50f6deb93..87e1fb8f7 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -189,7 +189,7 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); (void)cookie; RCTSourceLoadBlock onSourceLoad = ^(NSError *error, NSData *source) { - RCTProfileEndAsyncEvent(0, @"init,download", cookie, @"JavaScript download", nil); + RCTProfileEndAsyncEvent(0, @"native", cookie, @"JavaScript download", @"JS async", nil); RCTPerformanceLoggerEnd(RCTPLScriptDownload); _onSourceLoad(error, source); @@ -629,6 +629,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR * AnyThread */ + RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBatchedBridge enqueueJSCall:]", nil); + NSArray *ids = [moduleDotMethod componentsSeparatedByString:@"."]; NSString *module = ids[0]; @@ -654,6 +656,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR [strongSelf _actuallyInvokeAndProcessModule:module method:method arguments:args ?: @[]]; } }]; + + RCT_PROFILE_END_EVENT(0, @"", nil); } /** @@ -843,8 +847,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR dispatch_block_t block = ^{ RCTProfileEndFlowEvent(); - - RCT_PROFILE_BEGIN_EVENT(0, RCTCurrentThreadName(), nil); + RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBatchedBridge handleBuffer:]", nil); NSOrderedSet *calls = [buckets objectForKey:queue]; @autoreleasepool { @@ -940,14 +943,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR - (void)_jsThreadUpdate:(CADisplayLink *)displayLink { RCTAssertJSThread(); - RCT_PROFILE_BEGIN_EVENT(0, @"DispatchFrameUpdate", nil); + RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBatchedBridge _jsThreadUpdate:]", nil); RCTFrameUpdate *frameUpdate = [[RCTFrameUpdate alloc] initWithDisplayLink:displayLink]; for (RCTModuleData *moduleData in _frameUpdateObservers) { id observer = (id)moduleData.instance; if (!observer.paused) { RCTProfileBeginFlowEvent(); - [self dispatchBlock:^{ RCTProfileEndFlowEvent(); [observer didUpdateFrame:frameUpdate]; diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index c0481e076..d5726a2bc 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -25,6 +25,7 @@ #import "RCTUtils.h" #import "RCTView.h" #import "UIView+React.h" +#import "RCTProfile.h" NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotification"; @@ -60,6 +61,8 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat RCTAssert(bridge, @"A bridge instance is required to create an RCTRootView"); RCTAssert(moduleName, @"A moduleName is required to create an RCTRootView"); + RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTRootView init]", nil); + if ((self = [super initWithFrame:CGRectZero])) { self.backgroundColor = [UIColor whiteColor]; @@ -86,6 +89,9 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat [self showLoadingView]; } + + RCT_PROFILE_END_EVENT(0, @"", nil); + return self; } @@ -174,10 +180,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [_contentView removeFromSuperview]; _contentView = [[RCTRootContentView alloc] initWithFrame:self.bounds bridge:bridge]; + [self runApplication:bridge]; + _contentView.backgroundColor = self.backgroundColor; [self insertSubview:_contentView atIndex:0]; - - [self runApplication:bridge]; } - (void)runApplication:(RCTBridge *)bridge diff --git a/React/Executors/RCTJSCExecutor.m b/React/Executors/RCTJSCExecutor.m index 9e4c6201e..a1489d35e 100644 --- a/React/Executors/RCTJSCExecutor.m +++ b/React/Executors/RCTJSCExecutor.m @@ -261,12 +261,11 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context) return nil; } + RCT_PROFILE_BEGIN_EVENT(0, @"nativeRequireModuleConfig", nil); NSArray *config = [strongSelf->_bridge configForModuleName:moduleName]; - if (config) { - return RCTJSONStringify(config, NULL); - } - - return nil; + NSString *result = config ? RCTJSONStringify(config, NULL) : nil; + RCT_PROFILE_END_EVENT(0, @"js_call,config", @{ @"moduleName": moduleName }); + return result; }]; [self addSynchronousHookWithName:@"nativeFlushQueueImmediate" usingBlock:^(NSArray *calls){ @@ -275,7 +274,9 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context) return; } + RCT_PROFILE_BEGIN_EVENT(0, @"nativeFlushQueueImmediate", nil); [strongSelf->_bridge handleBuffer:calls batchEnded:NO]; + RCT_PROFILE_END_EVENT(0, @"js_call", nil); }]; [self addSynchronousHookWithName:@"nativePerformanceNow" usingBlock:^{ @@ -296,7 +297,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context) [self addSynchronousHookWithName:@"nativeTraceEndAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) { NSUInteger newCookie = (NSUInteger)CFDictionaryGetValue(cookieMap, (const void *)cookie); - RCTProfileEndAsyncEvent(tag, @"js,async", newCookie, name, nil); + RCTProfileEndAsyncEvent(tag, @"js,async", newCookie, name, @"JS async", nil); CFDictionaryRemoveValue(cookieMap, (const void *)cookie); }]; diff --git a/React/Profiler/RCTProfile.h b/React/Profiler/RCTProfile.h index 1cd721ab7..17b3bf27d 100644 --- a/React/Profiler/RCTProfile.h +++ b/React/Profiler/RCTProfile.h @@ -69,10 +69,10 @@ RCT_EXTERN void _RCTProfileBeginEvent(NSThread *calleeThread, #define RCT_PROFILE_BEGIN_EVENT(...) \ do { \ if (RCTProfileIsProfiling()) { \ - NSThread *calleeThread = [NSThread currentThread]; \ - NSTimeInterval time = CACurrentMediaTime(); \ + NSThread *__calleeThread = [NSThread currentThread]; \ + NSTimeInterval __time = CACurrentMediaTime(); \ dispatch_async(RCTProfileGetQueue(), ^{ \ - _RCTProfileBeginEvent(calleeThread, time, __VA_ARGS__); \ + _RCTProfileBeginEvent(__calleeThread, __time, __VA_ARGS__); \ }); \ } \ } while(0) @@ -92,11 +92,11 @@ RCT_EXTERN void _RCTProfileEndEvent(NSThread *calleeThread, #define RCT_PROFILE_END_EVENT(...) \ do { \ if (RCTProfileIsProfiling()) { \ - NSThread *calleeThread = [NSThread currentThread]; \ - NSString *threadName = RCTCurrentThreadName(); \ - NSTimeInterval time = CACurrentMediaTime(); \ + NSThread *__calleeThread = [NSThread currentThread]; \ + NSString *__threadName = RCTCurrentThreadName(); \ + NSTimeInterval __time = CACurrentMediaTime(); \ dispatch_async(RCTProfileGetQueue(), ^{ \ - _RCTProfileEndEvent(calleeThread, threadName, time, __VA_ARGS__); \ + _RCTProfileEndEvent(__calleeThread, __threadName, __time, __VA_ARGS__); \ }); \ } \ } while(0) @@ -117,6 +117,7 @@ RCT_EXTERN void RCTProfileEndAsyncEvent(uint64_t tag, NSString *category, NSUInteger cookie, NSString *name, + NSString *threadName, NSDictionary *args); /** diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index 42cf74c63..32f63e916 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -472,7 +472,6 @@ void _RCTProfileBeginEvent( NSMutableArray *events = RCTProfileGetThreadEvents(calleeThread); [events addObject:@[ RCTProfileTimestamp(time), - @(tag), name, RCTNullIfNil(args), ]]; @@ -507,12 +506,12 @@ void _RCTProfileEndEvent( RCTProfileAddEvent(RCTProfileTraceEvents, @"tid": threadName, - @"name": event[2], + @"name": event[1], @"cat": category, @"ph": @"X", @"ts": start, @"dur": @(RCTProfileTimestamp(time).doubleValue - start.doubleValue), - @"args": RCTProfileMergeArgs(event[3], args), + @"args": RCTProfileMergeArgs(event[2], args), ); } @@ -548,6 +547,7 @@ void RCTProfileEndAsyncEvent( NSString *category, NSUInteger cookie, NSString *name, + NSString *threadName, NSDictionary *args ) { CHECK(); @@ -558,7 +558,6 @@ void RCTProfileEndAsyncEvent( } NSTimeInterval time = CACurrentMediaTime(); - NSString *threadName = RCTCurrentThreadName(); dispatch_async(RCTProfileGetQueue(), ^{ NSArray *event = RCTProfileOngoingEvents[@(cookie)];