Skip to content

Commit

Permalink
make RCTFBSystrace actually work
Browse files Browse the repository at this point in the history
Reviewed By: tadeuzagallo

Differential Revision: D3234824

fbshipit-source-id: 9f2f7efd6877fe7b9096dedecb311d226eae7bc8
  • Loading branch information
mhorowitz authored and Facebook Github Bot 8 committed May 14, 2016
1 parent 418e16f commit 86e18ac
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 59 deletions.
12 changes: 6 additions & 6 deletions React/Base/RCTBatchedBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ - (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args
* AnyThread
*/

RCT_PROFILE_BEGIN_EVENT(0, @"-[RCTBatchedBridge enqueueJSCall:]", nil);
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTBatchedBridge enqueueJSCall:]", nil);

NSArray<NSString *> *ids = [moduleDotMethod componentsSeparatedByString:@"."];

Expand Down Expand Up @@ -692,7 +692,7 @@ - (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args
}
}];

RCT_PROFILE_END_EVENT(0, @"", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
}

/**
Expand Down Expand Up @@ -762,10 +762,10 @@ - (void)enqueueApplicationScript:(NSData *)script
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),
});
Expand Down Expand Up @@ -889,7 +889,7 @@ - (void)handleBuffer:(NSArray *)buffer

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 {
Expand All @@ -909,7 +909,7 @@ - (void)handleBuffer:(NSArray *)buffer
}
}

RCT_PROFILE_END_EVENT(0, @"objc_call,dispatch_async", @{
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"objc_call,dispatch_async", @{
@"calls": @(calls.count),
});
};
Expand Down
6 changes: 3 additions & 3 deletions React/Base/RCTDisplayLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)_jsThreadUpdate:(CADisplayLink *)displayLink
{
[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) {
Expand All @@ -114,9 +114,9 @@ - (void)_jsThreadUpdate:(CADisplayLink *)displayLink

[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
Expand Down
4 changes: 2 additions & 2 deletions React/Base/RCTModuleData.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ - (BOOL)hasInstance
- (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
Expand All @@ -199,7 +199,7 @@ - (BOOL)hasInstance
} else {
[self setUpInstanceAndBridge];
}
RCT_PROFILE_END_EVENT(0, @"", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);
}
return _instance;
}
Expand Down
4 changes: 2 additions & 2 deletions React/Base/RCTPerformanceLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
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])) {

Expand Down Expand Up @@ -98,7 +98,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
[self showLoadingView];
}

RCT_PROFILE_END_EVENT(0, @"", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"", nil);

return self;
}
Expand Down
13 changes: 7 additions & 6 deletions React/Executors/RCTJSCExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ - (void)setUp
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;
}];

Expand All @@ -335,9 +335,9 @@ - (void)setUp
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:^{
Expand Down Expand Up @@ -736,7 +736,8 @@ - (void)registerNativeRequire

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);
Expand All @@ -756,7 +757,7 @@ - (void)registerNativeRequire
JSStringRelease(code);
JSStringRelease(sourceURL);

RCT_PROFILE_END_EVENT(0, @"js_call", nil);
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call", nil);
RCTPerformanceLoggerAppendEnd(RCTPLRAMNativeRequires);

if (!result) {
Expand Down
4 changes: 2 additions & 2 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ - (void)flushUIBlocks
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();
Expand All @@ -1123,7 +1123,7 @@ - (void)flushUIBlocks
@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),
});
});
Expand Down
10 changes: 4 additions & 6 deletions React/Profiler/RCTProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
61 changes: 31 additions & 30 deletions React/Profiler/RCTProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
NSString *const RCTProfileDidStartProfiling = @"RCTProfileDidStartProfiling";
NSString *const RCTProfileDidEndProfiling = @"RCTProfileDidEndProfiling";

const uint64_t RCTProfileTagAlways = 1L << 0;

#if RCT_DEV

#pragma mark - Constants
Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -370,7 +372,7 @@ @implementation RCTProfile

+ (void)vsync:(CADisplayLink *)displayLink
{
RCTProfileImmediateEvent(0, @"VSYNC", displayLink.timestamp, 'g');
RCTProfileImmediateEvent(RCTProfileTagAlways, @"VSYNC", displayLink.timestamp, 'g');
}

+ (void)reload
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 86e18ac

Please sign in to comment.