Fix ReactPerf markers in Systrace
Reviewed By: @spicyj Differential Revision: D2468107
This commit is contained in:
parent
d447edc5ed
commit
d96748492f
|
@ -133,7 +133,9 @@ function setUpWebSockets() {
|
||||||
function setupProfile() {
|
function setupProfile() {
|
||||||
console.profile = console.profile || GLOBAL.nativeTraceBeginSection || function () {};
|
console.profile = console.profile || GLOBAL.nativeTraceBeginSection || function () {};
|
||||||
console.profileEnd = console.profileEnd || GLOBAL.nativeTraceEndSection || function () {};
|
console.profileEnd = console.profileEnd || GLOBAL.nativeTraceEndSection || function () {};
|
||||||
|
if (__DEV__) {
|
||||||
require('BridgeProfiling').swizzleReactPerf();
|
require('BridgeProfiling').swizzleReactPerf();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUpProcessEnv() {
|
function setUpProcessEnv() {
|
||||||
|
|
|
@ -14,9 +14,24 @@
|
||||||
var GLOBAL = GLOBAL || this;
|
var GLOBAL = GLOBAL || this;
|
||||||
var TRACE_TAG_REACT_APPS = 1 << 17;
|
var TRACE_TAG_REACT_APPS = 1 << 17;
|
||||||
|
|
||||||
|
var _enabled = false;
|
||||||
|
var _ReactPerf = null;
|
||||||
|
function ReactPerf() {
|
||||||
|
if (!_ReactPerf) {
|
||||||
|
_ReactPerf = require('ReactPerf');
|
||||||
|
}
|
||||||
|
return _ReactPerf;
|
||||||
|
}
|
||||||
|
|
||||||
var BridgeProfiling = {
|
var BridgeProfiling = {
|
||||||
|
setEnabled(enabled: boolean) {
|
||||||
|
_enabled = enabled;
|
||||||
|
|
||||||
|
ReactPerf().enableMeasure = enabled;
|
||||||
|
},
|
||||||
|
|
||||||
profile(profileName?: any) {
|
profile(profileName?: any) {
|
||||||
if (GLOBAL.__BridgeProfilingIsProfiling) {
|
if (_enabled) {
|
||||||
profileName = typeof profileName === 'function' ?
|
profileName = typeof profileName === 'function' ?
|
||||||
profileName() : profileName;
|
profileName() : profileName;
|
||||||
console.profile(TRACE_TAG_REACT_APPS, profileName);
|
console.profile(TRACE_TAG_REACT_APPS, profileName);
|
||||||
|
@ -24,28 +39,27 @@ var BridgeProfiling = {
|
||||||
},
|
},
|
||||||
|
|
||||||
profileEnd() {
|
profileEnd() {
|
||||||
if (GLOBAL.__BridgeProfilingIsProfiling) {
|
if (_enabled) {
|
||||||
console.profileEnd(TRACE_TAG_REACT_APPS);
|
console.profileEnd(TRACE_TAG_REACT_APPS);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
swizzleReactPerf() {
|
reactPerfMeasure(objName: string, fnName: string, func: any): any {
|
||||||
var ReactPerf = require('ReactPerf');
|
|
||||||
var originalMeasure = ReactPerf.measure;
|
|
||||||
ReactPerf.measure = function (objName, fnName, func) {
|
|
||||||
func = originalMeasure.apply(ReactPerf, arguments);
|
|
||||||
return function (component) {
|
return function (component) {
|
||||||
if (GLOBAL.__BridgeProfilingIsProfiling) {
|
if (!_enabled) {
|
||||||
var name = this._instance && this._instance.constructor &&
|
return func.apply(this, arguments);
|
||||||
(this._instance.constructor.displayName ||
|
|
||||||
this._instance.constructor.name);
|
|
||||||
BridgeProfiling.profile(`${objName}.${fnName}(${name})`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var name = objName === 'ReactCompositeComponent' && this.getName() || '';
|
||||||
|
BridgeProfiling.profile(`${objName}.${fnName}(${name})`);
|
||||||
var ret = func.apply(this, arguments);
|
var ret = func.apply(this, arguments);
|
||||||
BridgeProfiling.profileEnd();
|
BridgeProfiling.profileEnd();
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
};
|
},
|
||||||
|
|
||||||
|
swizzleReactPerf() {
|
||||||
|
ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -336,17 +336,13 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
||||||
|
|
||||||
- (void)toggleProfilingFlag:(NSNotification *)notification
|
- (void)toggleProfilingFlag:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
JSObjectRef globalObject = JSContextGetGlobalObject(_context.ctx);
|
[self executeBlockOnJavaScriptQueue:^{
|
||||||
|
BOOL enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling];
|
||||||
bool enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling];
|
NSString *script = [NSString stringWithFormat:@"var p = require('BridgeProfiling') || {}; p.setEnabled && p.setEnabled(%@)", enabled ? @"true" : @"false"];
|
||||||
JSStringRef JSName = JSStringCreateWithUTF8CString("__BridgeProfilingIsProfiling");
|
JSStringRef scriptJSRef = JSStringCreateWithUTF8CString(script.UTF8String);
|
||||||
JSObjectSetProperty(_context.ctx,
|
JSEvaluateScript(_context.ctx, scriptJSRef, NULL, NULL, 0, NULL);
|
||||||
globalObject,
|
JSStringRelease(scriptJSRef);
|
||||||
JSName,
|
}];
|
||||||
JSValueMakeBoolean(_context.ctx, enabled),
|
|
||||||
kJSPropertyAttributeNone,
|
|
||||||
NULL);
|
|
||||||
JSStringRelease(JSName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_addNativeHook:(JSObjectCallAsFunctionCallback)hook withName:(const char *)name
|
- (void)_addNativeHook:(JSObjectCallAsFunctionCallback)hook withName:(const char *)name
|
||||||
|
|
Loading…
Reference in New Issue