From 64675dc078a7447fc7c92c441f0c04219b4db2d3 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 23 Nov 2015 19:22:34 -0800 Subject: [PATCH] Move RelayProfiler Decoupled Initialization to use Double Dispatch Reviewed By: josephsavona Differential Revision: D2689433 fb-gh-sync-id: 966b3d855a5a0a755fd55fb583e31ba648de2a7a --- .../InitializeJavaScriptAppEngine.js | 1 - Libraries/Utilities/BridgeProfiling.js | 32 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js index 8735e1ab0..ec13c1615 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js +++ b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js @@ -162,7 +162,6 @@ function setUpProfile() { if (__DEV__) { var BridgeProfiling = require('BridgeProfiling'); BridgeProfiling.swizzleReactPerf(); - BridgeProfiling.attachToRelayProfiler(); } } diff --git a/Libraries/Utilities/BridgeProfiling.js b/Libraries/Utilities/BridgeProfiling.js index f71b6511c..526775b20 100644 --- a/Libraries/Utilities/BridgeProfiling.js +++ b/Libraries/Utilities/BridgeProfiling.js @@ -11,6 +11,13 @@ */ 'use strict'; +type RelayProfiler = { + attachProfileHandler( + name: string, + handler: (name: string, state?: any) => () => void + ): void +}; + var GLOBAL = GLOBAL || this; var TRACE_TAG_REACT_APPS = 1 << 17; @@ -52,7 +59,7 @@ var BridgeProfiling = { var name = objName === 'ReactCompositeComponent' && this.getName() || ''; BridgeProfiling.profile(`${objName}.${fnName}(${name})`); - var ret = func.apply(this, arguments); + var ret = func.apply(this, arguments); BridgeProfiling.profileEnd(); return ret; }; @@ -62,22 +69,13 @@ var BridgeProfiling = { ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure); }, - attachToRelayProfiler() { - // We don't want to create a dependency on `RelayProfiler`, so that's why - // we require it indirectly (rather than using a literal string). Since - // there's no guarantee that the module will be present, we must wrap - // everything in a try-catch block as requiring a non-existing module - // will just throw. - try { - var rpName = 'RelayProfiler'; - var RelayProfiler = require(rpName); - RelayProfiler.attachProfileHandler('*', (name) => { - BridgeProfiling.profile(name); - return () => { - BridgeProfiling.profileEnd(); - }; - }); - } catch(err) {} + attachToRelayProfiler(relayProfiler: RelayProfiler) { + relayProfiler.attachProfileHandler('*', (name) => { + BridgeProfiling.profile(name); + return () => { + BridgeProfiling.profileEnd(); + }; + }); }, /* This is not called by default due to perf overhead but it's useful