Permalink
Browse files

Add option to start sampling profiler on app launch

Reviewed By: mhorowitz

Differential Revision: D4415989

fbshipit-source-id: 30704c2b618656cb7cc0ccdf87dec315b30b62f3
  • Loading branch information...
javache authored and facebook-github-bot committed Jan 25, 2017
1 parent 5bb19a5 commit a407ff94eeb09629d21ecb1b1204c53d3fc3cead
@@ -338,7 +338,9 @@ - (void)setUp
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 @@ - (instancetype)initWithUseCustomJSCLibrary:(BOOL)useCustomJSCLibrary
- (void)_createContext
{
if (_useCustomJSCLibrary) {
JSC_configureJSCForIOS(true);
JSC_configureJSCForIOS(true, "{}");
}
JSGlobalContextRef ctx = JSC_JSGlobalContextCreateInGroup(_useCustomJSCLibrary, nullptr, nullptr);
_context = [JSC_JSContext(ctx) contextWithJSGlobalContextRef:ctx];
@@ -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.
@@ -212,6 +212,9 @@ - (instancetype)init
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 @@ - (void)addItem:(RCTDevMenuItem *)item
}
// 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 @@ - (void)setShakeToShow:(BOOL)shakeToShow
[self updateSetting:@"shakeToShow" value:@(_shakeToShow)];
}
- (void)setStartSamplingProfilerOnLaunch:(BOOL)startSamplingProfilerOnLaunch
{
_startSamplingProfilerOnLaunch = startSamplingProfilerOnLaunch;
[self updateSetting:@"startSamplingProfilerOnLaunch" value:@(_startSamplingProfilerOnLaunch)];
}
RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled)
{
_profilingEnabled = enabled;
@@ -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;
@@ -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);

0 comments on commit a407ff9

Please sign in to comment.