react-native/Libraries/Performance/RCTRenderingPerf.js
Dan Abramov 32a0ee0975 Implement Systrace integration for Fiber
Reviewed By: bvaughn

Differential Revision: D5210738

fbshipit-source-id: db7df5ca7a1b4944f86719361d22ec3cc2ce8f22
2017-06-08 14:31:52 -07:00

62 lines
1.3 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 invariant = require('fbjs/lib/invariant');
var performanceNow = require('fbjs/lib/performanceNow');
type perfModule = {
start: () => void,
stop: () => void,
}
var perfModules = [];
var enabled = false;
var RCTRenderingPerf = {
// Once perf is enabled, it stays enabled
toggle: function() {
console.log('Render perfomance measurements enabled');
enabled = true;
},
start: function() {
if (!enabled) {
return;
}
perfModules.forEach((module) => module.start());
},
stop: function() {
if (!enabled) {
return;
}
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;