diff --git a/benchmark/misc/trace.js b/benchmark/misc/trace.js index 75c87d363a6b03..7ac80ca4cf8528 100644 --- a/benchmark/misc/trace.js +++ b/benchmark/misc/trace.js @@ -9,18 +9,11 @@ const bench = common.createBenchmark(main, { flags: ['--expose-internals', '--trace-event-categories', 'foo'] }); -const { - trace, - isTraceCategoryEnabled, - emit, - categoryGroupEnabled -} = process.binding('trace_events'); - const { TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent } = process.binding('constants').trace; -function doEmit(n) { +function doEmit(n, emit) { bench.start(); for (var i = 0; i < n; i++) { emit(kBeforeEvent, 'foo', 'test', 0, 'arg1', 1); @@ -28,7 +21,7 @@ function doEmit(n) { bench.end(n); } -function doTrace(n) { +function doTrace(n, trace) { bench.start(); for (var i = 0; i < n; i++) { trace(kBeforeEvent, 'foo', 'test', 0, 'test'); @@ -36,7 +29,7 @@ function doTrace(n) { bench.end(n); } -function doIsTraceCategoryEnabled(n) { +function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) { bench.start(); for (var i = 0; i < n; i++) { isTraceCategoryEnabled('foo'); @@ -45,7 +38,7 @@ function doIsTraceCategoryEnabled(n) { bench.end(n); } -function doCategoryGroupEnabled(n) { +function doCategoryGroupEnabled(n, categoryGroupEnabled) { bench.start(); for (var i = 0; i < n; i++) { categoryGroupEnabled('foo'); @@ -55,19 +48,28 @@ function doCategoryGroupEnabled(n) { } function main({ n, method }) { + const { internalBinding } = require('internal/test/binding'); + + const { + trace, + isTraceCategoryEnabled, + emit, + categoryGroupEnabled + } = internalBinding('trace_events'); + switch (method) { case '': case 'trace': - doTrace(n); + doTrace(n, trace); break; case 'emit': - doEmit(n); + doEmit(n, emit); break; case 'isTraceCategoryEnabled': - doIsTraceCategoryEnabled(n); + doIsTraceCategoryEnabled(n, isTraceCategoryEnabled); break; case 'categoryGroupEnabled': - doCategoryGroupEnabled(n); + doCategoryGroupEnabled(n, categoryGroupEnabled); break; default: throw new Error(`Unexpected method "${method}"`); diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index d46b0308c64424..5cd00932bd8667 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -100,7 +100,7 @@ { - const traceEvents = process.binding('trace_events'); + const traceEvents = internalBinding('trace_events'); const traceEventCategory = 'node,node.async_hooks'; if (traceEvents.categoryGroupEnabled(traceEventCategory)) { diff --git a/lib/trace_events.js b/lib/trace_events.js index 45015c8a63add0..79347b370e70de 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -16,7 +16,8 @@ const { if (!hasTracing) throw new ERR_TRACE_EVENTS_UNAVAILABLE(); -const { CategorySet, getEnabledCategories } = process.binding('trace_events'); +const { internalBinding } = require('internal/bootstrap/loaders'); +const { CategorySet, getEnabledCategories } = internalBinding('trace_events'); const { customInspectSymbol } = require('internal/util'); const { format } = require('util'); diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index d59b92555795fb..8413620e3f5f5b 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -257,4 +257,4 @@ void Initialize(Local target, } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(trace_events, node::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(trace_events, node::Initialize) diff --git a/test/parallel/test-trace-events-binding.js b/test/parallel/test-trace-events-binding.js index 7ce75ace330990..2544c196acee49 100644 --- a/test/parallel/test-trace-events-binding.js +++ b/test/parallel/test-trace-events-binding.js @@ -8,18 +8,16 @@ if (!common.isMainThread) common.skip('process.chdir is not available in Workers'); const CODE = ` - process.binding("trace_events").emit( - 'b'.charCodeAt(0), 'custom', - 'type-value', 10, 'extra-value', 20); - process.binding("trace_events").emit( - 'b'.charCodeAt(0), 'custom', - 'type-value', 20, 'first-value', 20, 'second-value', 30); - process.binding("trace_events").emit( - 'b'.charCodeAt(0), 'custom', - 'type-value', 30); - process.binding("trace_events").emit( - 'b'.charCodeAt(0), 'missing', - 'type-value', 10, 'extra-value', 20); + const { internalBinding } = require('internal/test/binding'); + const { emit } = internalBinding('trace_events'); + emit('b'.charCodeAt(0), 'custom', + 'type-value', 10, 'extra-value', 20); + emit('b'.charCodeAt(0), 'custom', + 'type-value', 20, 'first-value', 20, 'second-value', 30); + emit('b'.charCodeAt(0), 'custom', + 'type-value', 30); + emit('b'.charCodeAt(0), 'missing', + 'type-value', 10, 'extra-value', 20); `; const FILE_NAME = 'node_trace.1.log'; @@ -29,6 +27,7 @@ process.chdir(tmpdir.path); const proc = cp.spawn(process.execPath, [ '--trace-event-categories', 'custom', + '--expose-internals', '-e', CODE ]); proc.once('exit', common.mustCall(() => { diff --git a/test/parallel/test-trace-events-category-used.js b/test/parallel/test-trace-events-category-used.js index d5aff4e1361ce6..4f9ad69366fdb0 100644 --- a/test/parallel/test-trace-events-category-used.js +++ b/test/parallel/test-trace-events-category-used.js @@ -6,9 +6,13 @@ const cp = require('child_process'); if (!common.isMainThread) common.skip('process.chdir is not available in Workers'); -const CODE = `console.log( - process.binding("trace_events").categoryGroupEnabled("custom") -);`; +const CODE = ` + const { internalBinding } = require('internal/test/binding'); + const { categoryGroupEnabled } = internalBinding('trace_events'); + console.log( + categoryGroupEnabled("custom") + ); +`; const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); @@ -16,7 +20,9 @@ process.chdir(tmpdir.path); const procEnabled = cp.spawn( process.execPath, - [ '--trace-event-categories', 'custom', '-e', CODE ] + [ '--trace-event-categories', 'custom', + '--expose-internals', + '-e', CODE ] ); let procEnabledOutput = ''; @@ -28,7 +34,9 @@ procEnabled.once('exit', common.mustCall(() => { const procDisabled = cp.spawn( process.execPath, - [ '--trace-event-categories', 'other', '-e', CODE ] + [ '--trace-event-categories', 'other', + '--expose-internals', + '-e', CODE ] ); let procDisabledOutput = '';