Skip to content

Commit 5af3038

Browse files
javachefacebook-github-bot
authored andcommitted
Improve fbsystrace support
Reviewed By: mhorowitz Differential Revision: D4756318 fbshipit-source-id: 7811f680a7ad044b5ae028ee9b2fed5f46ce2a63
1 parent 12de972 commit 5af3038

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

React/Base/RCTBridge.m

-9
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,6 @@ - (Class)bridgeClass
301301
}
302302

303303
RCTAssert(implClass != nil, @"No bridge implementation is available, giving up.");
304-
305-
#ifdef WITH_FBSYSTRACE
306-
if (implClass == cxxBridgeClass) {
307-
[RCTFBSystrace registerCallbacks];
308-
} else {
309-
[RCTFBSystrace unregisterCallbacks];
310-
}
311-
#endif
312-
313304
return implClass;
314305
}
315306

React/CxxBridge/RCTCxxBridge.mm

+6
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,9 @@ - (void)startProfiling
11391139
RCTAssertMainQueue();
11401140

11411141
[self executeBlockOnJavaScriptThread:^{
1142+
#if WITH_FBSYSTRACE
1143+
[RCTFBSystrace registerCallbacks];
1144+
#endif
11421145
RCTProfileInit(self);
11431146
}];
11441147
}
@@ -1151,6 +1154,9 @@ - (void)stopProfiling:(void (^)(NSData *))callback
11511154
RCTProfileEnd(self, ^(NSString *log) {
11521155
NSData *logData = [log dataUsingEncoding:NSUTF8StringEncoding];
11531156
callback(logData);
1157+
#if WITH_FBSYSTRACE
1158+
[RCTFBSystrace unregisterCallbacks];
1159+
#endif
11541160
});
11551161
}];
11561162
}

React/Profiler/RCTProfile.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ typedef struct {
175175
} systrace_arg_t;
176176

177177
typedef struct {
178-
void (*start)(uint64_t enabledTags, char *buffer, size_t bufferSize);
178+
char *(*start)(void);
179179
void (*stop)(void);
180180

181181
void (*begin_section)(uint64_t tag, const char *name, size_t numArgs, systrace_arg_t *args);

React/Profiler/RCTProfile.m

+5-6
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,7 @@ void RCTProfileInit(RCTBridge *bridge)
455455
OSAtomicOr32Barrier(1, &RCTProfileProfiling);
456456

457457
if (callbacks != NULL) {
458-
size_t buffer_size = 1 << 22;
459-
systrace_buffer = calloc(1, buffer_size);
460-
callbacks->start(~((uint64_t)0), systrace_buffer, buffer_size);
458+
systrace_buffer = callbacks->start();
461459
} else {
462460
NSTimeInterval time = CACurrentMediaTime();
463461
dispatch_async(RCTProfileGetQueue(), ^{
@@ -514,9 +512,10 @@ void RCTProfileEnd(RCTBridge *bridge, void (^callback)(NSString *))
514512
RCTProfileUnhookModules(bridge);
515513

516514
if (callbacks != NULL) {
517-
callbacks->stop();
518-
519-
callback(@(systrace_buffer));
515+
if (systrace_buffer) {
516+
callbacks->stop();
517+
callback(@(systrace_buffer));
518+
}
520519
} else {
521520
dispatch_async(RCTProfileGetQueue(), ^{
522521
NSString *log = RCTJSONStringify(RCTProfileInfo, NULL);

0 commit comments

Comments
 (0)