mirror of
https://github.com/status-im/react-native.git
synced 2025-01-09 17:15:54 +00:00
212d31e322
Summary: A temporary React Native compatibility fix was added to React in commit [bba0d99](bba0d992d8
) and subsequently removed in commit [e612826](e612826650
). I noticed this while testing the React Native fiber renderer and attempting to use `Systrace`. This commit updates React Native to no longer rely on the deprecated method and module. PS I'm not sure if I should also update `ReactDebugTool` with this commit or wait for a subsequent sync script to update it. I haven't committed to this repo before. Please advise. 😄 Closes https://github.com/facebook/react-native/pull/11970 Differential Revision: D4446219 Pulled By: bvaughn fbshipit-source-id: f286b8a4d00cdcbfbb49f52b9f1db5231d453f4c
92 lines
2.2 KiB
JavaScript
92 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @providesModule RCTRenderingPerf
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
var ReactDebugTool = require('ReactDebugTool');
|
|
var ReactPerf = require('ReactPerf');
|
|
|
|
var invariant = require('fbjs/lib/invariant');
|
|
var performanceNow = require('fbjs/lib/performanceNow');
|
|
|
|
type perfModule = {
|
|
start: () => void,
|
|
stop: () => void,
|
|
}
|
|
|
|
var perfModules = [];
|
|
var enabled = false;
|
|
var lastRenderStartTime = 0;
|
|
var totalRenderDuration = 0;
|
|
|
|
var RCTRenderingPerfDevtool = {
|
|
onBeginLifeCycleTimer(debugID, timerType) {
|
|
if (timerType === 'render') {
|
|
lastRenderStartTime = performanceNow();
|
|
}
|
|
},
|
|
onEndLifeCycleTimer(debugID, timerType) {
|
|
if (timerType === 'render') {
|
|
var lastRenderDuration = performanceNow() - lastRenderStartTime;
|
|
totalRenderDuration += lastRenderDuration;
|
|
}
|
|
},
|
|
};
|
|
|
|
var RCTRenderingPerf = {
|
|
// Once perf is enabled, it stays enabled
|
|
toggle: function() {
|
|
console.log('Render perfomance measurements enabled');
|
|
enabled = true;
|
|
},
|
|
|
|
start: function() {
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
|
|
ReactPerf.start();
|
|
ReactDebugTool.addHook(RCTRenderingPerfDevtool);
|
|
perfModules.forEach((module) => module.start());
|
|
},
|
|
|
|
stop: function() {
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
|
|
ReactPerf.stop();
|
|
ReactPerf.printInclusive();
|
|
ReactPerf.printWasted();
|
|
ReactDebugTool.removeHook(RCTRenderingPerfDevtool);
|
|
|
|
console.log(`Total time spent in render(): ${totalRenderDuration.toFixed(2)} ms`);
|
|
lastRenderStartTime = 0;
|
|
totalRenderDuration = 0;
|
|
|
|
perfModules.forEach((module) => module.stop());
|
|
},
|
|
|
|
register: function(module: perfModule) {
|
|
invariant(
|
|
typeof module.start === 'function',
|
|
'Perf module should have start() function'
|
|
);
|
|
invariant(
|
|
typeof module.stop === 'function',
|
|
'Perf module should have stop() function'
|
|
);
|
|
perfModules.push(module);
|
|
}
|
|
};
|
|
|
|
module.exports = RCTRenderingPerf;
|