Skip to content

Commit c1e2d6b

Browse files
committed
trace_events: move trace_events to internalBinding
PR-URL: #22159 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Jon Moss <[email protected]>
1 parent 9f5cc1f commit c1e2d6b

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed

Diff for: benchmark/misc/trace.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,27 @@ const bench = common.createBenchmark(main, {
99
flags: ['--expose-internals', '--trace-event-categories', 'foo']
1010
});
1111

12-
const {
13-
trace,
14-
isTraceCategoryEnabled,
15-
emit,
16-
categoryGroupEnabled
17-
} = process.binding('trace_events');
18-
1912
const {
2013
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
2114
} = process.binding('constants').trace;
2215

23-
function doEmit(n) {
16+
function doEmit(n, emit) {
2417
bench.start();
2518
for (var i = 0; i < n; i++) {
2619
emit(kBeforeEvent, 'foo', 'test', 0, 'arg1', 1);
2720
}
2821
bench.end(n);
2922
}
3023

31-
function doTrace(n) {
24+
function doTrace(n, trace) {
3225
bench.start();
3326
for (var i = 0; i < n; i++) {
3427
trace(kBeforeEvent, 'foo', 'test', 0, 'test');
3528
}
3629
bench.end(n);
3730
}
3831

39-
function doIsTraceCategoryEnabled(n) {
32+
function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
4033
bench.start();
4134
for (var i = 0; i < n; i++) {
4235
isTraceCategoryEnabled('foo');
@@ -45,7 +38,7 @@ function doIsTraceCategoryEnabled(n) {
4538
bench.end(n);
4639
}
4740

48-
function doCategoryGroupEnabled(n) {
41+
function doCategoryGroupEnabled(n, categoryGroupEnabled) {
4942
bench.start();
5043
for (var i = 0; i < n; i++) {
5144
categoryGroupEnabled('foo');
@@ -55,19 +48,28 @@ function doCategoryGroupEnabled(n) {
5548
}
5649

5750
function main({ n, method }) {
51+
const { internalBinding } = require('internal/test/binding');
52+
53+
const {
54+
trace,
55+
isTraceCategoryEnabled,
56+
emit,
57+
categoryGroupEnabled
58+
} = internalBinding('trace_events');
59+
5860
switch (method) {
5961
case '':
6062
case 'trace':
61-
doTrace(n);
63+
doTrace(n, trace);
6264
break;
6365
case 'emit':
64-
doEmit(n);
66+
doEmit(n, emit);
6567
break;
6668
case 'isTraceCategoryEnabled':
67-
doIsTraceCategoryEnabled(n);
69+
doIsTraceCategoryEnabled(n, isTraceCategoryEnabled);
6870
break;
6971
case 'categoryGroupEnabled':
70-
doCategoryGroupEnabled(n);
72+
doCategoryGroupEnabled(n, categoryGroupEnabled);
7173
break;
7274
default:
7375
throw new Error(`Unexpected method "${method}"`);

Diff for: lib/internal/bootstrap/node.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101

102102
{
103-
const traceEvents = process.binding('trace_events');
103+
const traceEvents = internalBinding('trace_events');
104104
const traceEventCategory = 'node,node.async_hooks';
105105

106106
if (traceEvents.categoryGroupEnabled(traceEventCategory)) {

Diff for: lib/trace_events.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const {
1616
if (!hasTracing)
1717
throw new ERR_TRACE_EVENTS_UNAVAILABLE();
1818

19-
const { CategorySet, getEnabledCategories } = process.binding('trace_events');
19+
const { internalBinding } = require('internal/bootstrap/loaders');
20+
const { CategorySet, getEnabledCategories } = internalBinding('trace_events');
2021
const { customInspectSymbol } = require('internal/util');
2122
const { format } = require('util');
2223

Diff for: src/node_trace_events.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,4 @@ void Initialize(Local<Object> target,
257257

258258
} // namespace node
259259

260-
NODE_BUILTIN_MODULE_CONTEXT_AWARE(trace_events, node::Initialize)
260+
NODE_MODULE_CONTEXT_AWARE_INTERNAL(trace_events, node::Initialize)

Diff for: test/parallel/test-trace-events-binding.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@ if (!common.isMainThread)
88
common.skip('process.chdir is not available in Workers');
99

1010
const CODE = `
11-
process.binding("trace_events").emit(
12-
'b'.charCodeAt(0), 'custom',
13-
'type-value', 10, 'extra-value', 20);
14-
process.binding("trace_events").emit(
15-
'b'.charCodeAt(0), 'custom',
16-
'type-value', 20, 'first-value', 20, 'second-value', 30);
17-
process.binding("trace_events").emit(
18-
'b'.charCodeAt(0), 'custom',
19-
'type-value', 30);
20-
process.binding("trace_events").emit(
21-
'b'.charCodeAt(0), 'missing',
22-
'type-value', 10, 'extra-value', 20);
11+
const { internalBinding } = require('internal/test/binding');
12+
const { emit } = internalBinding('trace_events');
13+
emit('b'.charCodeAt(0), 'custom',
14+
'type-value', 10, 'extra-value', 20);
15+
emit('b'.charCodeAt(0), 'custom',
16+
'type-value', 20, 'first-value', 20, 'second-value', 30);
17+
emit('b'.charCodeAt(0), 'custom',
18+
'type-value', 30);
19+
emit('b'.charCodeAt(0), 'missing',
20+
'type-value', 10, 'extra-value', 20);
2321
`;
2422
const FILE_NAME = 'node_trace.1.log';
2523

@@ -29,6 +27,7 @@ process.chdir(tmpdir.path);
2927

3028
const proc = cp.spawn(process.execPath,
3129
[ '--trace-event-categories', 'custom',
30+
'--expose-internals',
3231
'-e', CODE ]);
3332

3433
proc.once('exit', common.mustCall(() => {

Diff for: test/parallel/test-trace-events-category-used.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ const cp = require('child_process');
66
if (!common.isMainThread)
77
common.skip('process.chdir is not available in Workers');
88

9-
const CODE = `console.log(
10-
process.binding("trace_events").categoryGroupEnabled("custom")
11-
);`;
9+
const CODE = `
10+
const { internalBinding } = require('internal/test/binding');
11+
const { categoryGroupEnabled } = internalBinding('trace_events');
12+
console.log(
13+
categoryGroupEnabled("custom")
14+
);
15+
`;
1216

1317
const tmpdir = require('../common/tmpdir');
1418
tmpdir.refresh();
1519
process.chdir(tmpdir.path);
1620

1721
const procEnabled = cp.spawn(
1822
process.execPath,
19-
[ '--trace-event-categories', 'custom', '-e', CODE ]
23+
[ '--trace-event-categories', 'custom',
24+
'--expose-internals',
25+
'-e', CODE ]
2026
);
2127
let procEnabledOutput = '';
2228

@@ -28,7 +34,9 @@ procEnabled.once('exit', common.mustCall(() => {
2834

2935
const procDisabled = cp.spawn(
3036
process.execPath,
31-
[ '--trace-event-categories', 'other', '-e', CODE ]
37+
[ '--trace-event-categories', 'other',
38+
'--expose-internals',
39+
'-e', CODE ]
3240
);
3341
let procDisabledOutput = '';
3442

0 commit comments

Comments
 (0)