2
0
mirror of https://github.com/status-im/react-native.git synced 2025-01-28 02:04:55 +00:00
Mike Armstrong af753a8a4d Add NativeProfiling module that uses RN nativeProfiler or console.profile
Reviewed By: jspahrsummers

Differential Revision: D2696072

fb-gh-sync-id: 6a2b9793424cf9a82b9472e6d468cbd81dd6780a
2015-11-27 04:44:25 -08:00

44 lines
1008 B
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 CPUProfiler
* @flow
*/
'use strict';
var _label;
var _nestingLevel = 0;
var CPUProfiler = {
start(profileName: string) {
if (_nestingLevel === 0) {
if (global.nativeProfilerStart) {
_label = profileName;
global.nativeProfilerStart(profileName);
} else if (console.profile) {
console.profile(profileName);
}
}
_nestingLevel++;
},
end() {
_nestingLevel--;
if (_nestingLevel === 0) {
if (global.nativeProfilerEnd) {
global.nativeProfilerEnd(_label);
} else if (console.profileEnd) {
console.profileEnd();
}
_label = undefined;
}
}
};
module.exports = CPUProfiler;