Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace_events: move trace_events to internalBinding #22159

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions benchmark/misc/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,27 @@ 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);
}
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');
}
bench.end(n);
}

function doIsTraceCategoryEnabled(n) {
function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
bench.start();
for (var i = 0; i < n; i++) {
isTraceCategoryEnabled('foo');
Expand All @@ -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');
Expand All @@ -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}"`);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion lib/trace_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion src/node_trace_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ void Initialize(Local<Object> target,

} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(trace_events, node::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(trace_events, node::Initialize)
23 changes: 11 additions & 12 deletions test/parallel/test-trace-events-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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(() => {
Expand Down
18 changes: 13 additions & 5 deletions test/parallel/test-trace-events-category-used.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ 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();
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 = '';

Expand All @@ -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 = '';

Expand Down