1313
1414var ReactDebugTool = require ( 'ReactDebugTool' ) ;
1515var warning = require ( 'warning' ) ;
16+ var alreadyWarned = false ;
1617
1718function roundFloat ( val , base = 2 ) {
1819 var n = Math . pow ( 10 , base ) ;
1920 return Math . floor ( val * n ) / n ;
2021}
2122
22- function getFlushHistory ( ) {
23+ function warnInProduction ( ) {
24+ if ( alreadyWarned ) {
25+ return ;
26+ }
27+ alreadyWarned = true ;
28+ if ( typeof console !== 'undefined' ) {
29+ console . error (
30+ 'ReactPerf is not supported in the production builds of React. ' +
31+ 'To collect measurements, please use the development build of React instead.'
32+ ) ;
33+ }
34+ }
35+
36+ function getLastMeasurements ( ) {
37+ if ( ! __DEV__ ) {
38+ warnInProduction ( ) ;
39+ return [ ] ;
40+ }
41+
2342 return ReactDebugTool . getFlushHistory ( ) ;
2443}
2544
26- function getExclusive ( flushHistory = getFlushHistory ( ) ) {
45+ function getExclusive ( flushHistory = getLastMeasurements ( ) ) {
46+ if ( ! __DEV__ ) {
47+ warnInProduction ( ) ;
48+ return [ ] ;
49+ }
50+
2751 var aggregatedStats = { } ;
2852 var affectedIDs = { } ;
2953
@@ -73,7 +97,12 @@ function getExclusive(flushHistory = getFlushHistory()) {
7397 ) ;
7498}
7599
76- function getInclusive ( flushHistory = getFlushHistory ( ) ) {
100+ function getInclusive ( flushHistory = getLastMeasurements ( ) ) {
101+ if ( ! __DEV__ ) {
102+ warnInProduction ( ) ;
103+ return [ ] ;
104+ }
105+
77106 var aggregatedStats = { } ;
78107 var affectedIDs = { } ;
79108
@@ -141,7 +170,12 @@ function getInclusive(flushHistory = getFlushHistory()) {
141170 ) ;
142171}
143172
144- function getWasted ( flushHistory = getFlushHistory ( ) ) {
173+ function getWasted ( flushHistory = getLastMeasurements ( ) ) {
174+ if ( ! __DEV__ ) {
175+ warnInProduction ( ) ;
176+ return [ ] ;
177+ }
178+
145179 var aggregatedStats = { } ;
146180 var affectedIDs = { } ;
147181
@@ -234,7 +268,12 @@ function getWasted(flushHistory = getFlushHistory()) {
234268 ) ;
235269}
236270
237- function getOperations ( flushHistory = getFlushHistory ( ) ) {
271+ function getOperations ( flushHistory = getLastMeasurements ( ) ) {
272+ if ( ! __DEV__ ) {
273+ warnInProduction ( ) ;
274+ return [ ] ;
275+ }
276+
238277 var stats = [ ] ;
239278 flushHistory . forEach ( ( flush , flushIndex ) => {
240279 var { operations, treeSnapshot} = flush ;
@@ -258,6 +297,11 @@ function getOperations(flushHistory = getFlushHistory()) {
258297}
259298
260299function printExclusive ( flushHistory ) {
300+ if ( ! __DEV__ ) {
301+ warnInProduction ( ) ;
302+ return ;
303+ }
304+
261305 var stats = getExclusive ( flushHistory ) ;
262306 var table = stats . map ( item => {
263307 var { key, instanceCount, totalDuration} = item ;
@@ -279,6 +323,11 @@ function printExclusive(flushHistory) {
279323}
280324
281325function printInclusive ( flushHistory ) {
326+ if ( ! __DEV__ ) {
327+ warnInProduction ( ) ;
328+ return ;
329+ }
330+
282331 var stats = getInclusive ( flushHistory ) ;
283332 var table = stats . map ( item => {
284333 var { key, instanceCount, inclusiveRenderDuration, renderCount} = item ;
@@ -293,6 +342,11 @@ function printInclusive(flushHistory) {
293342}
294343
295344function printWasted ( flushHistory ) {
345+ if ( ! __DEV__ ) {
346+ warnInProduction ( ) ;
347+ return ;
348+ }
349+
296350 var stats = getWasted ( flushHistory ) ;
297351 var table = stats . map ( item => {
298352 var { key, instanceCount, inclusiveRenderDuration, renderCount} = item ;
@@ -307,6 +361,11 @@ function printWasted(flushHistory) {
307361}
308362
309363function printOperations ( flushHistory ) {
364+ if ( ! __DEV__ ) {
365+ warnInProduction ( ) ;
366+ return ;
367+ }
368+
310369 var stats = getOperations ( flushHistory ) ;
311370 var table = stats . map ( stat => ( {
312371 'Owner > Node' : stat . key ,
@@ -344,19 +403,34 @@ function getMeasurementsSummaryMap(measurements) {
344403}
345404
346405function start ( ) {
406+ if ( ! __DEV__ ) {
407+ warnInProduction ( ) ;
408+ return ;
409+ }
410+
347411 ReactDebugTool . beginProfiling ( ) ;
348412}
349413
350414function stop ( ) {
415+ if ( ! __DEV__ ) {
416+ warnInProduction ( ) ;
417+ return ;
418+ }
419+
351420 ReactDebugTool . endProfiling ( ) ;
352421}
353422
354423function isRunning ( ) {
424+ if ( ! __DEV__ ) {
425+ warnInProduction ( ) ;
426+ return false ;
427+ }
428+
355429 return ReactDebugTool . isProfiling ( ) ;
356430}
357431
358432var ReactPerfAnalysis = {
359- getLastMeasurements : getFlushHistory ,
433+ getLastMeasurements,
360434 getExclusive,
361435 getInclusive,
362436 getWasted,
0 commit comments