make RCTFBSystrace actually work

Reviewed By: tadeuzagallo

Differential Revision: D3234824

fbshipit-source-id: 9f2f7efd6877fe7b9096dedecb311d226eae7bc8
This commit is contained in:
Marc Horowitz 2016-05-13 17:14:59 -07:00 committed by Facebook Github Bot 8
parent 418e16f711
commit 86e18ace94
9 changed files with 59 additions and 59 deletions

View File

@ -664,7 +664,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
* AnyThread
*/
RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBatchedBridge enqueueJSCall:]", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTBatchedBridge enqueueJSCall:]", nil);
NSArray<NSString *> *ids = [moduleDotMethod componentsSeparatedByString:@"."];
@ -692,7 +692,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
}
}];
RCT_PROFILE_END_EVENT(0, @"", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
}
/**
@ -762,10 +762,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
return;
}
RCT_PROFILE_BEGIN_EVENT(0, @"FetchApplicationScriptCallbacks", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"FetchApplicationScriptCallbacks", nil);
[_javaScriptExecutor flushedQueue:^(id json, NSError *error)
{
RCT_PROFILE_END_EVENT(0, @"js_call,init", @{
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call,init", @{
@"json": RCTNullIfNil(json),
@"error": RCTNullIfNil(error),
});
@ -889,7 +889,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
dispatch_block_t block = ^{
RCTProfileEndFlowEvent();
RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBatchedBridge handleBuffer:]", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTBatchedBridge handleBuffer:]", nil);
NSOrderedSet *calls = [buckets objectForKey:queue];
@autoreleasepool {
@ -909,7 +909,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
}
}
RCT_PROFILE_END_EVENT(0, @"objc_call,dispatch_async", @{
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"objc_call,dispatch_async", @{
@"calls": @(calls.count),
});
};

View File

@ -97,7 +97,7 @@
{
[self assertOnRunLoop];
RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTDisplayLink _jsThreadUpdate:]", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTDisplayLink _jsThreadUpdate:]", nil);
RCTFrameUpdate *frameUpdate = [[RCTFrameUpdate alloc] initWithDisplayLink:displayLink];
for (RCTModuleData *moduleData in _frameUpdateObservers) {
@ -114,9 +114,9 @@
[self updateJSDisplayLinkState];
RCTProfileImmediateEvent(0, @"JS Thread Tick", displayLink.timestamp, 'g');
RCTProfileImmediateEvent(RCTProfileTagAlways, @"JS Thread Tick", displayLink.timestamp, 'g');
RCT_PROFILE_END_EVENT(0, @"objc_call", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"objc_call", nil);
}
- (void)updateJSDisplayLinkState

View File

@ -187,7 +187,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
- (id<RCTBridgeModule>)instance
{
if (!_setupComplete) {
RCT_PROFILE_BEGIN_EVENT(0, [NSString stringWithFormat:@"[RCTModuleData instanceForClass:%@]", _moduleClass], nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"[RCTModuleData instanceForClass:%@]", _moduleClass], nil);
if (_requiresMainThreadSetup) {
// The chances of deadlock here are low, because module init very rarely
// calls out to other threads, however we can't control when a module might
@ -199,7 +199,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init);
} else {
[self setUpInstanceAndBridge];
}
RCT_PROFILE_END_EVENT(0, @"", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
}
return _instance;
}

View File

@ -21,7 +21,7 @@ void RCTPerformanceLoggerStart(RCTPLTag tag)
{
if (RCTProfileIsProfiling()) {
NSString *label = RCTPerformanceLoggerLabels()[tag];
RCTPLCookies[tag] = RCTProfileBeginAsyncEvent(0, label, nil);
RCTPLCookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil);
}
RCTPLData[tag][0] = CACurrentMediaTime() * 1000;
@ -35,7 +35,7 @@ void RCTPerformanceLoggerEnd(RCTPLTag tag)
if (RCTProfileIsProfiling()) {
NSString *label = RCTPerformanceLoggerLabels()[tag];
RCTProfileEndAsyncEvent(0, @"native", RCTPLCookies[tag], label, @"RCTPerformanceLogger", nil);
RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", RCTPLCookies[tag], label, @"RCTPerformanceLogger", nil);
}
} else {
RCTLogInfo(@"Unbalanced calls start/end for tag %li", (unsigned long)tag);

View File

@ -62,7 +62,7 @@ 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);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTRootView init]", nil);
if ((self = [super initWithFrame:CGRectZero])) {
@ -98,7 +98,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
[self showLoadingView];
}
RCT_PROFILE_END_EVENT(0, @"", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
return self;
}

View File

@ -322,10 +322,10 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
return nil;
}
RCT_PROFILE_BEGIN_EVENT(0, @"nativeRequireModuleConfig", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"nativeRequireModuleConfig", nil);
NSArray *config = [strongSelf->_bridge configForModuleName:moduleName];
NSString *result = config ? RCTJSONStringify(config, NULL) : nil;
RCT_PROFILE_END_EVENT(0, @"js_call,config", @{ @"moduleName": moduleName });
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call,config", @{ @"moduleName": moduleName });
return result;
}];
@ -335,9 +335,9 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
return;
}
RCT_PROFILE_BEGIN_EVENT(0, @"nativeFlushQueueImmediate", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"nativeFlushQueueImmediate", nil);
[strongSelf->_bridge handleBuffer:calls batchEnded:NO];
RCT_PROFILE_END_EVENT(0, @"js_call", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call", nil);
}];
[self addSynchronousHookWithName:@"nativePerformanceNow" usingBlock:^{
@ -736,7 +736,8 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr)
RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresCount, 1);
RCTPerformanceLoggerAppendStart(RCTPLRAMNativeRequires);
RCT_PROFILE_BEGIN_EVENT(0, [@"nativeRequire_" stringByAppendingString:moduleName], nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
[@"nativeRequire_" stringByAppendingString:moduleName], nil);
ModuleData *data = (ModuleData *)CFDictionaryGetValue(strongSelf->_jsModules, moduleName.UTF8String);
RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresSize, data->length);
@ -756,7 +757,7 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr)
JSStringRelease(code);
JSStringRelease(sourceURL);
RCT_PROFILE_END_EVENT(0, @"js_call", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call", nil);
RCTPerformanceLoggerAppendEnd(RCTPLRAMNativeRequires);
if (!result) {

View File

@ -1114,7 +1114,7 @@ RCT_EXPORT_METHOD(dispatchViewManagerCommand:(nonnull NSNumber *)reactTag
RCTProfileBeginFlowEvent();
dispatch_async(dispatch_get_main_queue(), ^{
RCTProfileEndFlowEvent();
RCT_PROFILE_BEGIN_EVENT(0, @"-[UIManager flushUIBlocks]", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[UIManager flushUIBlocks]", nil);
@try {
for (dispatch_block_t block in previousPendingUIBlocks) {
block();
@ -1123,7 +1123,7 @@ RCT_EXPORT_METHOD(dispatchViewManagerCommand:(nonnull NSNumber *)reactTag
@catch (NSException *exception) {
RCTLogError(@"Exception thrown while executing UI block: %@", exception);
}
RCT_PROFILE_END_EVENT(0, @"objc_call", @{
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"objc_call", @{
@"count": @(previousPendingUIBlocks.count),
});
});

View File

@ -24,6 +24,8 @@
RCT_EXTERN NSString *const RCTProfileDidStartProfiling;
RCT_EXTERN NSString *const RCTProfileDidEndProfiling;
RCT_EXTERN const uint64_t RCTProfileTagAlways;
#if RCT_DEV
@class RCTBridge;
@ -72,9 +74,7 @@ RCT_EXTERN void _RCTProfileBeginEvent(NSThread *calleeThread,
if (RCTProfileIsProfiling()) { \
NSThread *__calleeThread = [NSThread currentThread]; \
NSTimeInterval __time = CACurrentMediaTime(); \
dispatch_async(RCTProfileGetQueue(), ^{ \
_RCTProfileBeginEvent(__calleeThread, __time, __VA_ARGS__); \
}); \
_RCTProfileBeginEvent(__calleeThread, __time, __VA_ARGS__); \
} \
} while(0)
@ -96,9 +96,7 @@ RCT_EXTERN void _RCTProfileEndEvent(NSThread *calleeThread,
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)

View File

@ -32,6 +32,8 @@
NSString *const RCTProfileDidStartProfiling = @"RCTProfileDidStartProfiling";
NSString *const RCTProfileDidEndProfiling = @"RCTProfileDidEndProfiling";
const uint64_t RCTProfileTagAlways = 1L << 0;
#if RCT_DEV
#pragma mark - Constants
@ -205,13 +207,13 @@ void RCTProfileTrampolineStart(id self, SEL cmd)
* block.
*/
Class klass = [self class];
RCT_PROFILE_BEGIN_EVENT(0, [NSString stringWithFormat:@"-[%s %s]", class_getName(klass), sel_getName(cmd)], nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, [NSString stringWithFormat:@"-[%s %s]", class_getName(klass), sel_getName(cmd)], nil);
}
RCT_EXTERN void RCTProfileTrampolineEnd(void);
void RCTProfileTrampolineEnd(void)
{
RCT_PROFILE_END_EVENT(0, @"objc_call,modules,auto", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"objc_call,modules,auto", nil);
}
static UIView *(*originalCreateView)(RCTComponentData *, SEL, NSNumber *);
@ -370,7 +372,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge)
+ (void)vsync:(CADisplayLink *)displayLink
{
RCTProfileImmediateEvent(0, @"VSYNC", displayLink.timestamp, 'g');
RCTProfileImmediateEvent(RCTProfileTagAlways, @"VSYNC", displayLink.timestamp, 'g');
}
+ (void)reload
@ -543,22 +545,21 @@ void _RCTProfileBeginEvent(
NSString *name,
NSDictionary *args
) {
CHECK();
RCTAssertThread(RCTProfileGetQueue(), @"Must be called RCTProfile queue");;
if (callbacks != NULL) {
callbacks->begin_section(tag, name.UTF8String, args.count, RCTProfileSystraceArgsFromNSDictionary(args));
return;
}
NSMutableArray *events = RCTProfileGetThreadEvents(calleeThread);
[events addObject:@[
RCTProfileTimestamp(time),
name,
RCTNullIfNil(args),
]];
dispatch_async(RCTProfileGetQueue(), ^{
NSMutableArray *events = RCTProfileGetThreadEvents(calleeThread);
[events addObject:@[
RCTProfileTimestamp(time),
name,
RCTNullIfNil(args),
]];
});
}
void _RCTProfileEndEvent(
@ -571,32 +572,32 @@ void _RCTProfileEndEvent(
) {
CHECK();
RCTAssertThread(RCTProfileGetQueue(), @"Must be called RCTProfile queue");;
if (callbacks != NULL) {
callbacks->end_section(tag, args.count, RCTProfileSystraceArgsFromNSDictionary(args));
return;
}
NSMutableArray<NSArray *> *events = RCTProfileGetThreadEvents(calleeThread);
NSArray *event = events.lastObject;
[events removeLastObject];
dispatch_async(RCTProfileGetQueue(), ^{
NSMutableArray<NSArray *> *events = RCTProfileGetThreadEvents(calleeThread);
NSArray *event = events.lastObject;
[events removeLastObject];
if (!event) {
return;
}
if (!event) {
return;
}
NSNumber *start = event[0];
NSNumber *start = event[0];
RCTProfileAddEvent(RCTProfileTraceEvents,
@"tid": threadName,
@"name": event[1],
@"cat": category,
@"ph": @"X",
@"ts": start,
@"dur": @(RCTProfileTimestamp(time).doubleValue - start.doubleValue),
@"args": RCTProfileMergeArgs(event[2], args),
);
RCTProfileAddEvent(RCTProfileTraceEvents,
@"tid": threadName,
@"name": event[1],
@"cat": category,
@"ph": @"X",
@"ts": start,
@"dur": @(RCTProfileTimestamp(time).doubleValue - start.doubleValue),
@"args": RCTProfileMergeArgs(event[2], args),
);
});
}
NSUInteger RCTProfileBeginAsyncEvent(