Add NativeProfiling module that uses RN nativeProfiler or console.profile
Reviewed By: jspahrsummers Differential Revision: D2696072 fb-gh-sync-id: 6a2b9793424cf9a82b9472e6d468cbd81dd6780a
This commit is contained in:
parent
af1475fc4c
commit
af753a8a4d
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* 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;
|
Loading…
Reference in New Issue