Add option to start sampling profiler on app launch
Reviewed By: mhorowitz Differential Revision: D4415989 fbshipit-source-id: 30704c2b618656cb7cc0ccdf87dec315b30b62f3
This commit is contained in:
parent
5bb19a5bf5
commit
a407ff94ee
|
@ -338,7 +338,9 @@ static NSThread *newJavaScriptThread(void)
|
||||||
contextRef = context.JSGlobalContextRef;
|
contextRef = context.JSGlobalContextRef;
|
||||||
} else {
|
} else {
|
||||||
if (self->_useCustomJSCLibrary) {
|
if (self->_useCustomJSCLibrary) {
|
||||||
JSC_configureJSCForIOS(true);
|
JSC_configureJSCForIOS(true, RCTJSONStringify(@{
|
||||||
|
@"StartSamplingProfilerOnInit": @(self->_bridge.devMenu.startSamplingProfilerOnLaunch)
|
||||||
|
}, NULL).UTF8String);
|
||||||
}
|
}
|
||||||
contextRef = JSC_JSGlobalContextCreateInGroup(self->_useCustomJSCLibrary, nullptr, nullptr);
|
contextRef = JSC_JSGlobalContextCreateInGroup(self->_useCustomJSCLibrary, nullptr, nullptr);
|
||||||
context = [JSC_JSContext(contextRef) contextWithJSGlobalContextRef:contextRef];
|
context = [JSC_JSContext(contextRef) contextWithJSGlobalContextRef:contextRef];
|
||||||
|
@ -1028,7 +1030,7 @@ static NSData *loadRAMBundle(NSURL *sourceURL, NSError **error, RandomAccessBund
|
||||||
- (void)_createContext
|
- (void)_createContext
|
||||||
{
|
{
|
||||||
if (_useCustomJSCLibrary) {
|
if (_useCustomJSCLibrary) {
|
||||||
JSC_configureJSCForIOS(true);
|
JSC_configureJSCForIOS(true, "{}");
|
||||||
}
|
}
|
||||||
JSGlobalContextRef ctx = JSC_JSGlobalContextCreateInGroup(_useCustomJSCLibrary, nullptr, nullptr);
|
JSGlobalContextRef ctx = JSC_JSGlobalContextCreateInGroup(_useCustomJSCLibrary, nullptr, nullptr);
|
||||||
_context = [JSC_JSContext(ctx) contextWithJSGlobalContextRef:ctx];
|
_context = [JSC_JSContext(ctx) contextWithJSGlobalContextRef:ctx];
|
||||||
|
|
|
@ -30,6 +30,11 @@
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) BOOL profilingEnabled;
|
@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
|
* Enables automatic polling for JS code changes. Only applicable when
|
||||||
* running the app from a server.
|
* running the app from a server.
|
||||||
|
|
|
@ -212,6 +212,9 @@ RCT_EXPORT_MODULE()
|
||||||
self->_executorOverride = [self->_defaults objectForKey:@"executor-override"];
|
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
|
// Delay setup until after Bridge init
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[weakSelf updateSettings:self->_settings];
|
[weakSelf updateSettings:self->_settings];
|
||||||
|
@ -537,6 +540,8 @@ RCT_EXPORT_MODULE()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add toggles for JSC's sampling profiler, if the profiler is enabled
|
// 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)) {
|
if (JSC_JSSamplingProfilerEnabled(self->_bridge.jsContext.JSGlobalContextRef)) {
|
||||||
JSContext *context = self->_bridge.jsContext;
|
JSContext *context = self->_bridge.jsContext;
|
||||||
// Allow to toggle the sampling profiler through RN's dev menu
|
// 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)];
|
[self updateSetting:@"shakeToShow" value:@(_shakeToShow)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setStartSamplingProfilerOnLaunch:(BOOL)startSamplingProfilerOnLaunch
|
||||||
|
{
|
||||||
|
_startSamplingProfilerOnLaunch = startSamplingProfilerOnLaunch;
|
||||||
|
[self updateSetting:@"startSamplingProfilerOnLaunch" value:@(_startSamplingProfilerOnLaunch)];
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled)
|
RCT_EXPORT_METHOD(setProfilingEnabled:(BOOL)enabled)
|
||||||
{
|
{
|
||||||
_profilingEnabled = enabled;
|
_profilingEnabled = enabled;
|
||||||
|
|
|
@ -226,7 +226,7 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
const bool useCustomJSC = m_jscConfig.getDefault("UseCustomJSC", false).getBool();
|
const bool useCustomJSC = m_jscConfig.getDefault("UseCustomJSC", false).getBool();
|
||||||
if (useCustomJSC) {
|
if (useCustomJSC) {
|
||||||
JSC_configureJSCForIOS(true);
|
JSC_configureJSCForIOS(true, toJson(m_jscConfig));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
const bool useCustomJSC = false;
|
const bool useCustomJSC = false;
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#import <objc/objc.h>
|
#import <objc/objc.h>
|
||||||
#import <JavaScriptCore/JSStringRefCF.h>
|
#import <JavaScriptCore/JSStringRefCF.h>
|
||||||
|
#import <string>
|
||||||
|
|
||||||
// This is used to substitute an alternate JSC implementation for
|
// This is used to substitute an alternate JSC implementation for
|
||||||
// testing. These calls must all be ABI compatible with the standard JSC.
|
// 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 JSValueRef JSEvaluateBytecodeBundle(JSContextRef, JSObjectRef, int, JSStringRef, JSValueRef*);
|
||||||
extern bool JSSamplingProfilerEnabled();
|
extern bool JSSamplingProfilerEnabled();
|
||||||
extern void JSStartSamplingProfilingOnMainJSCThread(JSGlobalContextRef);
|
extern void JSStartSamplingProfilingOnMainJSCThread(JSGlobalContextRef);
|
||||||
|
|
Loading…
Reference in New Issue