[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:
Tadeu Zagallo
2015-08-28 10:11:02 -07:00
parent e15f584a3d
commit aee74efde7
5 changed files with 23 additions and 58 deletions

View File

@@ -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