-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrument module init in DEV (#1787)
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
diff --git a/node_modules/metro-runtime/src/polyfills/require.js b/node_modules/metro-runtime/src/polyfills/require.js | ||
index ce67cb4..eeeae84 100644 | ||
--- a/node_modules/metro-runtime/src/polyfills/require.js | ||
+++ b/node_modules/metro-runtime/src/polyfills/require.js | ||
@@ -22,6 +22,13 @@ global.__c = clear; | ||
global.__registerSegment = registerSegment; | ||
var modules = clear(); | ||
|
||
+if (__DEV__) { | ||
+ // Added by Dan for module init logging. | ||
+ global.__INIT_LOGS__ = [] | ||
+ var initModuleCounter = 0 | ||
+ var initModuleStack = [] | ||
+} | ||
+ | ||
// Don't use a Symbol here, it would pull in an extra polyfill with all sorts of | ||
// additional stuff (e.g. Array.from). | ||
const EMPTY = {}; | ||
@@ -303,7 +310,30 @@ function loadModuleImplementation(moduleId, module) { | ||
throw module.error; | ||
} | ||
if (__DEV__) { | ||
- var Systrace = requireSystrace(); | ||
+ // Added by Dan for module init logging. | ||
+ var Systrace = { | ||
+ beginEvent(label) { | ||
+ let fullLabel = initModuleCounter++ + ' ' + label | ||
+ global.__INIT_LOGS__.push( | ||
+ ' '.repeat(initModuleStack.length) + | ||
+ ' ENTER ' + fullLabel | ||
+ ) | ||
+ initModuleStack.push({ | ||
+ fullLabel, | ||
+ startTime: nativePerformanceNow(), | ||
+ }) | ||
+ }, | ||
+ endEvent() { | ||
+ const res = initModuleStack.pop() | ||
+ const fullLabel = res.fullLabel | ||
+ const startTime = res.startTime | ||
+ const timeElapsed = Math.round(nativePerformanceNow() - startTime) | ||
+ global.__INIT_LOGS__.push( | ||
+ ' '.repeat(initModuleStack.length) + | ||
+ ' LEAVE ' + fullLabel + ' [' + timeElapsed + 'ms]', | ||
+ ) | ||
+ } | ||
+ }; | ||
var Refresh = requireRefresh(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters