From 7febd1367656aa1c337f62763624078f9e3062f8 Mon Sep 17 00:00:00 2001 From: Milen Dzhumerov Date: Fri, 20 Nov 2015 10:03:21 -0800 Subject: [PATCH] Attach to all RelayProfiler events Summary: public Dynamically profile events from RelayProfiler if available. This will expose time spent in Relay in the systraces. Reviewed By: tadeuzagallo Differential Revision: D2674215 fb-gh-sync-id: d5f9d529b86d267a80b0cda2223f6a28a08ac385 --- .../InitializeJavaScriptAppEngine.js | 4 +++- Libraries/Utilities/BridgeProfiling.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js index 501d4c9cc..8735e1ab0 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js +++ b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js @@ -160,7 +160,9 @@ function setUpWebSockets() { function setUpProfile() { if (__DEV__) { - require('BridgeProfiling').swizzleReactPerf(); + var BridgeProfiling = require('BridgeProfiling'); + BridgeProfiling.swizzleReactPerf(); + BridgeProfiling.attachToRelayProfiler(); } } diff --git a/Libraries/Utilities/BridgeProfiling.js b/Libraries/Utilities/BridgeProfiling.js index 16b6a7159..e62c8b76d 100644 --- a/Libraries/Utilities/BridgeProfiling.js +++ b/Libraries/Utilities/BridgeProfiling.js @@ -61,6 +61,24 @@ var BridgeProfiling = { swizzleReactPerf() { 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) {} + } }; BridgeProfiling.setEnabled(global.__RCTProfileIsProfiling || false);