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']
});
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}"`);

View File

@ -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)) {

View File

@ -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');

View File

@ -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)

View File

@ -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(() => {

View File

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