Move RelayProfiler Decoupled Initialization to use Double Dispatch

Reviewed By: josephsavona

Differential Revision: D2689433

fb-gh-sync-id: 966b3d855a5a0a755fd55fb583e31ba648de2a7a
This commit is contained in:
Sebastian Markbage
2015-11-23 19:22:34 -08:00
committed by facebook-github-bot-7
parent 26946e07f1
commit 64675dc078
2 changed files with 15 additions and 18 deletions

View File

@@ -162,7 +162,6 @@ function setUpProfile() {
if (__DEV__) { if (__DEV__) {
var BridgeProfiling = require('BridgeProfiling'); var BridgeProfiling = require('BridgeProfiling');
BridgeProfiling.swizzleReactPerf(); BridgeProfiling.swizzleReactPerf();
BridgeProfiling.attachToRelayProfiler();
} }
} }

View File

@@ -11,6 +11,13 @@
*/ */
'use strict'; 'use strict';
type RelayProfiler = {
attachProfileHandler(
name: string,
handler: (name: string, state?: any) => () => void
): void
};
var GLOBAL = GLOBAL || this; var GLOBAL = GLOBAL || this;
var TRACE_TAG_REACT_APPS = 1 << 17; var TRACE_TAG_REACT_APPS = 1 << 17;
@@ -52,7 +59,7 @@ var BridgeProfiling = {
var name = objName === 'ReactCompositeComponent' && this.getName() || ''; var name = objName === 'ReactCompositeComponent' && this.getName() || '';
BridgeProfiling.profile(`${objName}.${fnName}(${name})`); BridgeProfiling.profile(`${objName}.${fnName}(${name})`);
var ret = func.apply(this, arguments); var ret = func.apply(this, arguments);
BridgeProfiling.profileEnd(); BridgeProfiling.profileEnd();
return ret; return ret;
}; };
@@ -62,22 +69,13 @@ var BridgeProfiling = {
ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure); ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure);
}, },
attachToRelayProfiler() { attachToRelayProfiler(relayProfiler: RelayProfiler) {
// We don't want to create a dependency on `RelayProfiler`, so that's why relayProfiler.attachProfileHandler('*', (name) => {
// we require it indirectly (rather than using a literal string). Since BridgeProfiling.profile(name);
// there's no guarantee that the module will be present, we must wrap return () => {
// everything in a try-catch block as requiring a non-existing module BridgeProfiling.profileEnd();
// will just throw. };
try { });
var rpName = 'RelayProfiler';
var RelayProfiler = require(rpName);
RelayProfiler.attachProfileHandler('*', (name) => {
BridgeProfiling.profile(name);
return () => {
BridgeProfiling.profileEnd();
};
});
} catch(err) {}
}, },
/* This is not called by default due to perf overhead but it's useful /* This is not called by default due to perf overhead but it's useful