mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-07 23:27:05 +08:00
[ReactNative] Add JSC profiler to Dev Menu
Summary: Add JSC profiler to the dev menu and rename the pre-existent one to systrace. For now it just outputs to the console, but a better workflow is on the way.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
#import "RCTAssert.h"
|
||||
#import "RCTDefines.h"
|
||||
#import "RCTDevMenu.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTProfile.h"
|
||||
#import "RCTPerformanceLogger.h"
|
||||
@@ -89,6 +90,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
}
|
||||
|
||||
@synthesize valid = _valid;
|
||||
@synthesize bridge = _bridge;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
@@ -285,11 +287,18 @@ static JSValueRef RCTNativeTraceEndSection(JSContextRef context, __unused JSObje
|
||||
#if RCT_JSC_PROFILER
|
||||
void *JSCProfiler = dlopen(RCT_JSC_PROFILER_DYLIB, RTLD_NOW);
|
||||
if (JSCProfiler != NULL) {
|
||||
JSObjectCallAsFunctionCallback nativeProfilerStart = dlsym(JSCProfiler, "nativeProfilerStart");
|
||||
JSObjectCallAsFunctionCallback nativeProfilerEnd = dlsym(JSCProfiler, "nativeProfilerEnd");
|
||||
void (*nativeProfilerStart)(JSContextRef, const char *) = (void (*)(JSContextRef, const char *))dlsym(JSCProfiler, "nativeProfilerStart");
|
||||
const char *(*nativeProfilerEnd)(JSContextRef, const char *) = (const char *(*)(JSContextRef, const char *))dlsym(JSCProfiler, "nativeProfilerEnd");
|
||||
if (nativeProfilerStart != NULL && nativeProfilerEnd != NULL) {
|
||||
[strongSelf _addNativeHook:nativeProfilerStart withName:"nativeProfilerStart"];
|
||||
[strongSelf _addNativeHook:nativeProfilerEnd withName:"nativeProfilerStop"];
|
||||
__block BOOL isProfiling = NO;
|
||||
[_bridge.devMenu addItem:@"Profile" handler:^{
|
||||
if (isProfiling) {
|
||||
RCTLogInfo(@"%s", nativeProfilerEnd(strongSelf->_context.ctx, "profile"));
|
||||
} else {
|
||||
nativeProfilerStart(strongSelf->_context.ctx, "profile");
|
||||
}
|
||||
isProfiling = !isProfiling;
|
||||
}];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user