Add option to start sampling profiler on app launch

Reviewed By: mhorowitz

Differential Revision: D4415989

fbshipit-source-id: 30704c2b618656cb7cc0ccdf87dec315b30b62f3
This commit is contained in:
Pieter De Baets 2017-01-25 14:28:02 -08:00 committed by Facebook Github Bot
parent 5bb19a5bf5
commit a407ff94ee
5 changed files with 23 additions and 4 deletions

View File

@ -338,7 +338,9 @@ static NSThread *newJavaScriptThread(void)
contextRef = context.JSGlobalContextRef;
} else {
if (self->_useCustomJSCLibrary) {
JSC_configureJSCForIOS(true);
JSC_configureJSCForIOS(true, RCTJSONStringify(@{
@"StartSamplingProfilerOnInit": @(self->_bridge.devMenu.startSamplingProfilerOnLaunch)
}, NULL).UTF8String);
}
contextRef = JSC_JSGlobalContextCreateInGroup(self->_useCustomJSCLibrary, nullptr, nullptr);
context = [JSC_JSContext(contextRef) contextWithJSGlobalContextRef:contextRef];
@ -1028,7 +1030,7 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund
- (void)_createContext
{
if (_useCustomJSCLibrary) {
JSC_configureJSCForIOS(true);
JSC_configureJSCForIOS(true, "{}");
}
JSGlobalContextRef ctx = JSC_JSGlobalContextCreateInGroup(_useCustomJSCLibrary, nullptr, nullptr);
_context = [JSC_JSContext(ctx) contextWithJSGlobalContextRef:ctx];

View File

@ -30,6 +30,11 @@
*/
@property (nonatomic, assign) BOOL profilingEnabled;
/**
* Enables starting of profiling sampler on launch
*/
@property (nonatomic, assign) BOOL startSamplingProfilerOnLaunch;
/**
* Enables automatic polling for JS code changes. Only applicable when
* running the app from a server.

View File

@ -212,6 +212,9 @@ RCT_EXPORT_MODULE()
self->_executorOverride = [self->_defaults objectForKey:@"executor-override"];
});
// Same values are read during the bridge starup path
_startSamplingProfilerOnLaunch = [_settings[@"startSamplingProfilerOnLaunch"] boolValue];
// Delay setup until after Bridge init
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf updateSettings:self->_settings];
@ -537,6 +540,8 @@ RCT_EXPORT_MODULE()
}
// Add toggles for JSC's sampling profiler, if the profiler is enabled
// Note: bridge.jsContext is not implemented in the old bridge, so this code is
// duplicated in RCTJSCExecutor
if (JSC_JSSamplingProfilerEnabled(self->_bridge.jsContext.JSGlobalContextRef)) {
JSContext *context = self->_bridge.jsContext;
// Allow to toggle the sampling profiler through RN's dev menu
@ -625,6 +630,12 @@ RCT_EXPORT_METHOD(debugRemotely:(BOOL)enableDebug)
[self updateSetting:@"shakeToShow" value:@(_shakeToShow)];
}
- (void)setStartSamplingProfilerOnLaunch:(BOOL)startSamplingProfilerOnLaunch
{
_startSamplingProfilerOnLaunch = startSamplingProfilerOnLaunch;
[self updateSetting:@"startSamplingProfilerOnLaunch" value:@(_startSamplingProfilerOnLaunch)];
}
RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled)
{
_profilingEnabled = enabled;

View File

@ -226,7 +226,7 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
#if defined(__APPLE__)
const bool useCustomJSC = m_jscConfig.getDefault("UseCustomJSC", false).getBool();
if (useCustomJSC) {
JSC_configureJSCForIOS(true);
JSC_configureJSCForIOS(true, toJson(m_jscConfig));
}
#else
const bool useCustomJSC = false;

View File

@ -18,10 +18,11 @@
#if defined(__APPLE__)
#import <objc/objc.h>
#import <JavaScriptCore/JSStringRefCF.h>
#import <string>
// This is used to substitute an alternate JSC implementation for
// testing. These calls must all be ABI compatible with the standard JSC.
extern void configureJSCForIOS();
extern void configureJSCForIOS(std::string); // TODO: replace with folly::dynamic once supported
extern JSValueRef JSEvaluateBytecodeBundle(JSContextRef, JSObjectRef, int, JSStringRef, JSValueRef*);
extern bool JSSamplingProfilerEnabled();
extern void JSStartSamplingProfilingOnMainJSCThread(JSGlobalContextRef);