Skip to content

Commit

Permalink
Add option to start sampling profiler on app launch
Browse files Browse the repository at this point in the history
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 a407ff9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions React/Executors/RCTJSCExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTDevMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions React/Modules/RCTDevMenu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/cxxreact/JSCExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion ReactCommon/jschelpers/JSCWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a407ff9

Please sign in to comment.