[ReactNative] Add ReactPerf info to profiler timeline

Summary:
@public

Hook into ReactPerf to add markers to `RCTProfile` timeline.

Test Plan: {F22569628}
This commit is contained in:
Tadeu Zagallo
2015-06-15 13:05:05 -07:00
parent 03f49c8b0f
commit 86dc92d5ab
4 changed files with 42 additions and 14 deletions

View File

@@ -14,7 +14,7 @@
var GLOBAL = GLOBAL || this;
var BridgeProfiling = {
profile(profileName: string, args?: any) {
profile(profileName?: string, args?: any) {
if (GLOBAL.__BridgeProfilingIsProfiling) {
if (args) {
try {
@@ -27,11 +27,30 @@ var BridgeProfiling = {
}
},
profileEnd() {
profileEnd(profileName?: string) {
if (GLOBAL.__BridgeProfilingIsProfiling) {
console.profileEnd();
console.profileEnd(profileName);
}
},
swizzleReactPerf() {
var ReactPerf = require('ReactPerf');
var originalMeasure = ReactPerf.measure;
ReactPerf.measure = function (objName, fnName, func) {
func = originalMeasure.call(ReactPerf, objName, fnName, func);
return function (component) {
BridgeProfiling.profile();
var ret = func.apply(this, arguments);
if (GLOBAL.__BridgeProfilingIsProfiling) {
var name = this._instance && this._instance.constructor &&
(this._instance.constructor.displayName ||
this._instance.constructor.name);
BridgeProfiling.profileEnd(`${objName}.${fnName}(${name})`);
}
return ret;
};
};
},
};
module.exports = BridgeProfiling;