process: set the trace category update handler during bootstrap
Set the trace category update handler during bootstrap, but delay the initial invocation of it until pre-execution. In addition, do not serialize the `node.async_hooks` category state when loading the trace_event binding during bootstrap, since it depends on run time states (e.g. CLI flags). Instead, use the `isTraceCategoryEnabled` v8 intrinsics to query that value during pre-execution. PR-URL: https://github.com/nodejs/node/pull/26605 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
e2a2f9398e
commit
a91d36fcc1
@ -197,6 +197,13 @@ if (!config.noBrowserGlobals) {
|
|||||||
defineOperation(global, 'setImmediate', timers.setImmediate);
|
defineOperation(global, 'setImmediate', timers.setImmediate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the per-Environment callback that will be called
|
||||||
|
// when the TrackingTraceStateObserver updates trace state.
|
||||||
|
// Note that when NODE_USE_V8_PLATFORM is true, the observer is
|
||||||
|
// attached to the per-process TracingController.
|
||||||
|
const { setTraceCategoryStateUpdateHandler } = internalBinding('trace_events');
|
||||||
|
setTraceCategoryStateUpdateHandler(perThreadSetup.toggleTraceCategoryState);
|
||||||
|
|
||||||
// process.allowedNodeEnvironmentFlags
|
// process.allowedNodeEnvironmentFlags
|
||||||
Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
|
Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
|
||||||
get() {
|
get() {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { getOptionValue } = require('internal/options');
|
const { getOptionValue } = require('internal/options');
|
||||||
// Lazy load internal/trace_events_async_hooks only if the async_hooks
|
|
||||||
// trace event category is enabled.
|
|
||||||
let traceEventsAsyncHook;
|
|
||||||
|
|
||||||
function prepareMainThreadExecution() {
|
function prepareMainThreadExecution() {
|
||||||
// Patch the process object with legacy properties and normalizations
|
// Patch the process object with legacy properties and normalizations
|
||||||
@ -162,26 +159,9 @@ function initializeReportSignalHandlers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupTraceCategoryState() {
|
function setupTraceCategoryState() {
|
||||||
const {
|
const { isTraceCategoryEnabled } = internalBinding('trace_events');
|
||||||
asyncHooksEnabledInitial,
|
const { toggleTraceCategoryState } = require('internal/process/per_thread');
|
||||||
setTraceCategoryStateUpdateHandler
|
toggleTraceCategoryState(isTraceCategoryEnabled('node.async_hooks'));
|
||||||
} = internalBinding('trace_events');
|
|
||||||
|
|
||||||
toggleTraceCategoryState(asyncHooksEnabledInitial);
|
|
||||||
setTraceCategoryStateUpdateHandler(toggleTraceCategoryState);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamically enable/disable the traceEventsAsyncHook
|
|
||||||
function toggleTraceCategoryState(asyncHooksEnabled) {
|
|
||||||
if (asyncHooksEnabled) {
|
|
||||||
if (!traceEventsAsyncHook) {
|
|
||||||
traceEventsAsyncHook =
|
|
||||||
require('internal/trace_events_async_hooks').createHook();
|
|
||||||
}
|
|
||||||
traceEventsAsyncHook.enable();
|
|
||||||
} else if (traceEventsAsyncHook) {
|
|
||||||
traceEventsAsyncHook.disable();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In general deprecations are intialized wherever the APIs are implemented,
|
// In general deprecations are intialized wherever the APIs are implemented,
|
||||||
|
@ -304,7 +304,24 @@ function buildAllowedFlags() {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lazy load internal/trace_events_async_hooks only if the async_hooks
|
||||||
|
// trace event category is enabled.
|
||||||
|
let traceEventsAsyncHook;
|
||||||
|
// Dynamically enable/disable the traceEventsAsyncHook
|
||||||
|
function toggleTraceCategoryState(asyncHooksEnabled) {
|
||||||
|
if (asyncHooksEnabled) {
|
||||||
|
if (!traceEventsAsyncHook) {
|
||||||
|
traceEventsAsyncHook =
|
||||||
|
require('internal/trace_events_async_hooks').createHook();
|
||||||
|
}
|
||||||
|
traceEventsAsyncHook.enable();
|
||||||
|
} else if (traceEventsAsyncHook) {
|
||||||
|
traceEventsAsyncHook.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
toggleTraceCategoryState,
|
||||||
assert,
|
assert,
|
||||||
buildAllowedFlags,
|
buildAllowedFlags,
|
||||||
wrapProcessMethods
|
wrapProcessMethods
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
using v8::Array;
|
using v8::Array;
|
||||||
using v8::Boolean;
|
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
using v8::Function;
|
using v8::Function;
|
||||||
using v8::FunctionCallbackInfo;
|
using v8::FunctionCallbackInfo;
|
||||||
@ -149,15 +148,6 @@ void NodeCategorySet::Initialize(Local<Object> target,
|
|||||||
.FromJust();
|
.FromJust();
|
||||||
target->Set(context, trace,
|
target->Set(context, trace,
|
||||||
binding->Get(context, trace).ToLocalChecked()).FromJust();
|
binding->Get(context, trace).ToLocalChecked()).FromJust();
|
||||||
|
|
||||||
// Initial value of async hook trace events
|
|
||||||
bool async_hooks_enabled = (*(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
|
|
||||||
TRACING_CATEGORY_NODE1(async_hooks)))) != 0;
|
|
||||||
target
|
|
||||||
->Set(context,
|
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "asyncHooksEnabledInitial"),
|
|
||||||
Boolean::New(env->isolate(), async_hooks_enabled))
|
|
||||||
.FromJust();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user