trace_events: move trace_events to internalBinding

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
James M Snell 2018-08-06 12:28:33 -07:00
parent 9f5cc1fc92
commit c1e2d6b0f1
6 changed files with 45 additions and 35 deletions

View File

@ -9,18 +9,11 @@ const bench = common.createBenchmark(main, {
flags: ['--expose-internals', '--trace-event-categories', 'foo'] flags: ['--expose-internals', '--trace-event-categories', 'foo']
}); });
const {
trace,
isTraceCategoryEnabled,
emit,
categoryGroupEnabled
} = process.binding('trace_events');
const { const {
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent
} = process.binding('constants').trace; } = process.binding('constants').trace;
function doEmit(n) { function doEmit(n, emit) {
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
emit(kBeforeEvent, 'foo', 'test', 0, 'arg1', 1); emit(kBeforeEvent, 'foo', 'test', 0, 'arg1', 1);
@ -28,7 +21,7 @@ function doEmit(n) {
bench.end(n); bench.end(n);
} }
function doTrace(n) { function doTrace(n, trace) {
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
trace(kBeforeEvent, 'foo', 'test', 0, 'test'); trace(kBeforeEvent, 'foo', 'test', 0, 'test');
@ -36,7 +29,7 @@ function doTrace(n) {
bench.end(n); bench.end(n);
} }
function doIsTraceCategoryEnabled(n) { function doIsTraceCategoryEnabled(n, isTraceCategoryEnabled) {
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
isTraceCategoryEnabled('foo'); isTraceCategoryEnabled('foo');
@ -45,7 +38,7 @@ function doIsTraceCategoryEnabled(n) {
bench.end(n); bench.end(n);
} }
function doCategoryGroupEnabled(n) { function doCategoryGroupEnabled(n, categoryGroupEnabled) {
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
categoryGroupEnabled('foo'); categoryGroupEnabled('foo');
@ -55,19 +48,28 @@ function doCategoryGroupEnabled(n) {
} }
function main({ n, method }) { function main({ n, method }) {
const { internalBinding } = require('internal/test/binding');
const {
trace,
isTraceCategoryEnabled,
emit,
categoryGroupEnabled
} = internalBinding('trace_events');
switch (method) { switch (method) {
case '': case '':
case 'trace': case 'trace':
doTrace(n); doTrace(n, trace);
break; break;
case 'emit': case 'emit':
doEmit(n); doEmit(n, emit);
break; break;
case 'isTraceCategoryEnabled': case 'isTraceCategoryEnabled':
doIsTraceCategoryEnabled(n); doIsTraceCategoryEnabled(n, isTraceCategoryEnabled);
break; break;
case 'categoryGroupEnabled': case 'categoryGroupEnabled':
doCategoryGroupEnabled(n); doCategoryGroupEnabled(n, categoryGroupEnabled);
break; break;
default: default:
throw new Error(`Unexpected method "${method}"`); throw new Error(`Unexpected method "${method}"`);

View File

@ -100,7 +100,7 @@
{ {
const traceEvents = process.binding('trace_events'); const traceEvents = internalBinding('trace_events');
const traceEventCategory = 'node,node.async_hooks'; const traceEventCategory = 'node,node.async_hooks';
if (traceEvents.categoryGroupEnabled(traceEventCategory)) { if (traceEvents.categoryGroupEnabled(traceEventCategory)) {

View File

@ -16,7 +16,8 @@ const {
if (!hasTracing) if (!hasTracing)
throw new ERR_TRACE_EVENTS_UNAVAILABLE(); 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 { customInspectSymbol } = require('internal/util');
const { format } = require('util'); const { format } = require('util');

View File

@ -257,4 +257,4 @@ void Initialize(Local<Object> target,
} // namespace node } // namespace node
NODE_BUILTIN_MODULE_CONTEXT_AWARE(trace_events, node::Initialize) NODE_MODULE_CONTEXT_AWARE_INTERNAL(trace_events, node::Initialize)

View File

@ -8,17 +8,15 @@ if (!common.isMainThread)
common.skip('process.chdir is not available in Workers'); common.skip('process.chdir is not available in Workers');
const CODE = ` const CODE = `
process.binding("trace_events").emit( const { internalBinding } = require('internal/test/binding');
'b'.charCodeAt(0), 'custom', const { emit } = internalBinding('trace_events');
emit('b'.charCodeAt(0), 'custom',
'type-value', 10, 'extra-value', 20); 'type-value', 10, 'extra-value', 20);
process.binding("trace_events").emit( emit('b'.charCodeAt(0), 'custom',
'b'.charCodeAt(0), 'custom',
'type-value', 20, 'first-value', 20, 'second-value', 30); 'type-value', 20, 'first-value', 20, 'second-value', 30);
process.binding("trace_events").emit( emit('b'.charCodeAt(0), 'custom',
'b'.charCodeAt(0), 'custom',
'type-value', 30); 'type-value', 30);
process.binding("trace_events").emit( emit('b'.charCodeAt(0), 'missing',
'b'.charCodeAt(0), 'missing',
'type-value', 10, 'extra-value', 20); 'type-value', 10, 'extra-value', 20);
`; `;
const FILE_NAME = 'node_trace.1.log'; const FILE_NAME = 'node_trace.1.log';
@ -29,6 +27,7 @@ process.chdir(tmpdir.path);
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-event-categories', 'custom', [ '--trace-event-categories', 'custom',
'--expose-internals',
'-e', CODE ]); '-e', CODE ]);
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {

View File

@ -6,9 +6,13 @@ const cp = require('child_process');
if (!common.isMainThread) if (!common.isMainThread)
common.skip('process.chdir is not available in Workers'); common.skip('process.chdir is not available in Workers');
const CODE = `console.log( const CODE = `
process.binding("trace_events").categoryGroupEnabled("custom") const { internalBinding } = require('internal/test/binding');
);`; const { categoryGroupEnabled } = internalBinding('trace_events');
console.log(
categoryGroupEnabled("custom")
);
`;
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
@ -16,7 +20,9 @@ process.chdir(tmpdir.path);
const procEnabled = cp.spawn( const procEnabled = cp.spawn(
process.execPath, process.execPath,
[ '--trace-event-categories', 'custom', '-e', CODE ] [ '--trace-event-categories', 'custom',
'--expose-internals',
'-e', CODE ]
); );
let procEnabledOutput = ''; let procEnabledOutput = '';
@ -28,7 +34,9 @@ procEnabled.once('exit', common.mustCall(() => {
const procDisabled = cp.spawn( const procDisabled = cp.spawn(
process.execPath, process.execPath,
[ '--trace-event-categories', 'other', '-e', CODE ] [ '--trace-event-categories', 'other',
'--expose-internals',
'-e', CODE ]
); );
let procDisabledOutput = ''; let procDisabledOutput = '';