Skip to content

Commit

Permalink
Prevent Systrace from including React in the preloaded modules section
Browse files Browse the repository at this point in the history
Reviewed By: tadeuzagallo

Differential Revision: D3304923

fbshipit-source-id: 25dea5b57002578ccb3e38e8946c6b73db008ed0
  • Loading branch information
javache authored and Facebook Github Bot 8 committed May 23, 2016
1 parent 8f9a3aa commit 4880309
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions Libraries/Utilities/Systrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,44 @@ type RelayProfiler = {
): void,
};

var TRACE_TAG_REACT_APPS = 1 << 17;
var TRACE_TAG_JSC_CALLS = 1 << 27;

var _enabled = false;
var _asyncCookie = 0;
var _ReactDebugTool = null;
var _ReactComponentTreeDevtool = null;
function ReactDebugTool() {
if (!_ReactDebugTool) {
_ReactDebugTool = require('ReactDebugTool');
}
return _ReactDebugTool;
}
function ReactComponentTreeDevtool() {
if (!_ReactComponentTreeDevtool) {
_ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
}
return _ReactComponentTreeDevtool;
}
/* eslint no-bitwise: 0 */
const TRACE_TAG_REACT_APPS = 1 << 17;
const TRACE_TAG_JSC_CALLS = 1 << 27;

var ReactSystraceDevtool = {
let _enabled = false;
let _asyncCookie = 0;

const ReactSystraceDevtool = __DEV__ ? {
onBeginReconcilerTimer(debugID, timerType) {
var displayName = ReactComponentTreeDevtool().getDisplayName(debugID);
const displayName = require('ReactComponentTreeDevtool').getDisplayName(debugID);
Systrace.beginEvent(`ReactReconciler.${timerType}(${displayName})`);
},
onEndReconcilerTimer(debugID, timerType) {
Systrace.endEvent();
},
onBeginLifeCycleTimer(debugID, timerType) {
var displayName = ReactComponentTreeDevtool().getDisplayName(debugID);
const displayName = require('ReactComponentTreeDevtool').getDisplayName(debugID);
Systrace.beginEvent(`${displayName}.${timerType}()`);
},
onEndLifeCycleTimer(debugID, timerType) {
Systrace.endEvent();
},
};
} : null;

var Systrace = {
const Systrace = {
setEnabled(enabled: boolean) {
if (_enabled !== enabled) {
if (enabled) {
global.nativeTraceBeginLegacy && global.nativeTraceBeginLegacy(TRACE_TAG_JSC_CALLS);
ReactDebugTool().addDevtool(ReactSystraceDevtool);
} else {
global.nativeTraceEndLegacy && global.nativeTraceEndLegacy(TRACE_TAG_JSC_CALLS);
ReactDebugTool().removeDevtool(ReactSystraceDevtool);
if (__DEV__) {
if (enabled) {
global.nativeTraceBeginLegacy && global.nativeTraceBeginLegacy(TRACE_TAG_JSC_CALLS);
require('ReactDebugTool').addDevtool(ReactSystraceDevtool);
} else {
global.nativeTraceEndLegacy && global.nativeTraceEndLegacy(TRACE_TAG_JSC_CALLS);
require('ReactDebugTool').removeDevtool(ReactSystraceDevtool);
}
}
_enabled = enabled;
}
_enabled = enabled;
},

/**
Expand All @@ -97,7 +86,7 @@ var Systrace = {
* the returned cookie variable should be used as input into the endAsyncEvent call to end the profile
**/
beginAsyncEvent(profileName?: any): any {
var cookie = _asyncCookie;
const cookie = _asyncCookie;
if (_enabled) {
_asyncCookie++;
profileName = typeof profileName === 'function' ?
Expand Down Expand Up @@ -133,7 +122,7 @@ var Systrace = {
**/
attachToRelayProfiler(relayProfiler: RelayProfiler) {
relayProfiler.attachProfileHandler('*', (name) => {
var cookie = Systrace.beginAsyncEvent(name);
const cookie = Systrace.beginAsyncEvent(name);
return () => {
Systrace.endAsyncEvent(name, cookie);
};
Expand Down Expand Up @@ -191,14 +180,14 @@ var Systrace = {
return func;
}

var profileName = `${objName}.${fnName}`;
const profileName = `${objName}.${fnName}`;
return function() {
if (!_enabled) {
return func.apply(this, arguments);
}

Systrace.beginEvent(profileName);
var ret = func.apply(this, arguments);
const ret = func.apply(this, arguments);
Systrace.endEvent();
return ret;
};
Expand Down

0 comments on commit 4880309

Please sign in to comment.