Skip to content

Commit

Permalink
trace_events: move trace_events to internalBinding
Browse files Browse the repository at this point in the history
PR-URL: #22159
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
  • Loading branch information
jasnell committed Aug 9, 2018
1 parent 9f5cc1f commit c1e2d6b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
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

0 comments on commit c1e2d6b

Please sign in to comment.