summaryrefslogtreecommitdiff
path: root/lib/internal/bootstrap/pre_execution.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-02-10 19:09:44 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-02-21 10:47:24 +0800
commit435eea6400522189c9e521bde32134b03791a576 (patch)
tree8639f4fc2941136028750f6fa139594497dfa6b1 /lib/internal/bootstrap/pre_execution.js
parentdec3dadd322de8ab4c600c139629c0c900a52ff9 (diff)
downloadandroid-node-v8-435eea6400522189c9e521bde32134b03791a576.tar.gz
android-node-v8-435eea6400522189c9e521bde32134b03791a576.tar.bz2
android-node-v8-435eea6400522189c9e521bde32134b03791a576.zip
src: move async hooks trace events setup to pre_execution.js
Reasons: - Moves more environment-dependent setup out of bootstrap/node.js - No async operations should be done before the call to the setup functions in pre_execution.js so no async hooks should be triggered before that. Therefore it is safe to delay the setup until then. PR-URL: https://github.com/nodejs/node/pull/26062 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/bootstrap/pre_execution.js')
-rw-r--r--lib/internal/bootstrap/pre_execution.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index ce4af115ba..8c9d7e1eaf 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -3,6 +3,8 @@
const { getOptionValue } = require('internal/options');
function prepareMainThreadExecution() {
+ setupTraceCategoryState();
+
// If the process is spawned with env NODE_CHANNEL_FD, it's probably
// spawned by our child_process module, then initialize IPC.
// This attaches some internal event listeners and creates:
@@ -23,6 +25,34 @@ function prepareMainThreadExecution() {
loadPreloadModules();
}
+function setupTraceCategoryState() {
+ const {
+ traceCategoryState,
+ setTraceCategoryStateUpdateHandler
+ } = internalBinding('trace_events');
+ const kCategoryAsyncHooks = 0;
+ let traceEventsAsyncHook;
+
+ function toggleTraceCategoryState() {
+ // Dynamically enable/disable the traceEventsAsyncHook
+ const asyncHooksEnabled = !!traceCategoryState[kCategoryAsyncHooks];
+
+ if (asyncHooksEnabled) {
+ // Lazy load internal/trace_events_async_hooks only if the async_hooks
+ // trace event category is enabled.
+ if (!traceEventsAsyncHook) {
+ traceEventsAsyncHook = require('internal/trace_events_async_hooks');
+ }
+ traceEventsAsyncHook.enable();
+ } else if (traceEventsAsyncHook) {
+ traceEventsAsyncHook.disable();
+ }
+ }
+
+ toggleTraceCategoryState();
+ setTraceCategoryStateUpdateHandler(toggleTraceCategoryState);
+}
+
// In general deprecations are intialized wherever the APIs are implemented,
// this is used to deprecate APIs implemented in C++ where the deprecation
// utitlities are not easily accessible.
@@ -150,5 +180,6 @@ module.exports = {
prepareMainThreadExecution,
initializeDeprecations,
initializeESMLoader,
- loadPreloadModules
+ loadPreloadModules,
+ setupTraceCategoryState
};