Skip to content

Commit

Permalink
Revert "Warn that ReactPerf does not work in the production build (#6884
Browse files Browse the repository at this point in the history
, #6975)"

This reverts commit f71dfbc.

Reverting because GitHub stripped the original PR author.
  • Loading branch information
gaearon committed Jun 6, 2016
1 parent f71dfbc commit afe4837
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 104 deletions.
4 changes: 3 additions & 1 deletion src/renderers/shared/ReactDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ var ReactDebugTool = {
}
},
getFlushHistory() {
return flushHistory;
if (__DEV__) {
return flushHistory;
}
},
onBeginFlush() {
if (__DEV__) {
Expand Down
86 changes: 6 additions & 80 deletions src/renderers/shared/ReactPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,17 @@

var ReactDebugTool = require('ReactDebugTool');
var warning = require('warning');
var alreadyWarned = false;

function roundFloat(val, base = 2) {
var n = Math.pow(10, base);
return Math.floor(val * n) / n;
}

function warnInProduction() {
if (alreadyWarned) {
return;
}
alreadyWarned = true;
if (typeof console !== 'undefined') {
console.error(
'ReactPerf is not supported in the production builds of React. ' +
'To collect measurements, please use the development build of React instead.'
);
}
}

function getLastMeasurements() {
if (!__DEV__) {
warnInProduction();
return [];
}

function getFlushHistory() {
return ReactDebugTool.getFlushHistory();
}

function getExclusive(flushHistory = getLastMeasurements()) {
if (!__DEV__) {
warnInProduction();
return [];
}

function getExclusive(flushHistory = getFlushHistory()) {
var aggregatedStats = {};
var affectedIDs = {};

Expand Down Expand Up @@ -97,12 +73,7 @@ function getExclusive(flushHistory = getLastMeasurements()) {
);
}

function getInclusive(flushHistory = getLastMeasurements()) {
if (!__DEV__) {
warnInProduction();
return [];
}

function getInclusive(flushHistory = getFlushHistory()) {
var aggregatedStats = {};
var affectedIDs = {};

Expand Down Expand Up @@ -170,12 +141,7 @@ function getInclusive(flushHistory = getLastMeasurements()) {
);
}

function getWasted(flushHistory = getLastMeasurements()) {
if (!__DEV__) {
warnInProduction();
return [];
}

function getWasted(flushHistory = getFlushHistory()) {
var aggregatedStats = {};
var affectedIDs = {};

Expand Down Expand Up @@ -268,12 +234,7 @@ function getWasted(flushHistory = getLastMeasurements()) {
);
}

function getOperations(flushHistory = getLastMeasurements()) {
if (!__DEV__) {
warnInProduction();
return [];
}

function getOperations(flushHistory = getFlushHistory()) {
var stats = [];
flushHistory.forEach((flush, flushIndex) => {
var {operations, treeSnapshot} = flush;
Expand All @@ -297,11 +258,6 @@ function getOperations(flushHistory = getLastMeasurements()) {
}

function printExclusive(flushHistory) {
if (!__DEV__) {
warnInProduction();
return;
}

var stats = getExclusive(flushHistory);
var table = stats.map(item => {
var {key, instanceCount, totalDuration} = item;
Expand All @@ -323,11 +279,6 @@ function printExclusive(flushHistory) {
}

function printInclusive(flushHistory) {
if (!__DEV__) {
warnInProduction();
return;
}

var stats = getInclusive(flushHistory);
var table = stats.map(item => {
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item;
Expand All @@ -342,11 +293,6 @@ function printInclusive(flushHistory) {
}

function printWasted(flushHistory) {
if (!__DEV__) {
warnInProduction();
return;
}

var stats = getWasted(flushHistory);
var table = stats.map(item => {
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item;
Expand All @@ -361,11 +307,6 @@ function printWasted(flushHistory) {
}

function printOperations(flushHistory) {
if (!__DEV__) {
warnInProduction();
return;
}

var stats = getOperations(flushHistory);
var table = stats.map(stat => ({
'Owner > Node': stat.key,
Expand Down Expand Up @@ -403,34 +344,19 @@ function getMeasurementsSummaryMap(measurements) {
}

function start() {
if (!__DEV__) {
warnInProduction();
return;
}

ReactDebugTool.beginProfiling();
}

function stop() {
if (!__DEV__) {
warnInProduction();
return;
}

ReactDebugTool.endProfiling();
}

function isRunning() {
if (!__DEV__) {
warnInProduction();
return false;
}

return ReactDebugTool.isProfiling();
}

var ReactPerfAnalysis = {
getLastMeasurements,
getLastMeasurements: getFlushHistory,
getExclusive,
getInclusive,
getWasted,
Expand Down
23 changes: 0 additions & 23 deletions src/renderers/shared/__tests__/ReactPerf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,27 +445,4 @@ describe('ReactPerf', function() {
ReactPerf.stop();
expect(ReactPerf.isRunning()).toBe(false);
});

it('should print console error only once', () => {
__DEV__ = false;

spyOn(console, 'error');

expect(ReactPerf.getLastMeasurements()).toEqual([]);
expect(ReactPerf.getExclusive()).toEqual([]);
expect(ReactPerf.getInclusive()).toEqual([]);
expect(ReactPerf.getWasted()).toEqual([]);
expect(ReactPerf.getOperations()).toEqual([]);
expect(ReactPerf.printExclusive()).toEqual(undefined);
expect(ReactPerf.printInclusive()).toEqual(undefined);
expect(ReactPerf.printWasted()).toEqual(undefined);
expect(ReactPerf.printOperations()).toEqual(undefined);
expect(ReactPerf.start()).toBe(undefined);
expect(ReactPerf.stop()).toBe(undefined);
expect(ReactPerf.isRunning()).toBe(false);

expect(console.error.calls.count()).toBe(1);

__DEV__ = true;
})
});

0 comments on commit afe4837

Please sign in to comment.