mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 16:10:50 +00:00

Removes the requirement to use `--trace-events-enabled` to enable trace events. Tracing is enabled automatically if there are any enabled categories. Adds a new `trace_events` module with an API for enabling/disabling trace events at runtime without a command line flag. ```js const trace_events = require('trace_events'); const categories = [ 'node.perf', 'node.async_hooks' ]; const tracing = trace_events.createTracing({ categories }); tracing.enable(); // do stuff tracing.disable(); ``` Multiple `Tracing` objects may exist and be enabled at any point in time. The enabled trace event categories is the union of all enabled `Tracing` objects and the `--trace-event-categories` flag. PR-URL: https://github.com/nodejs/node/pull/19803 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cp = require('child_process');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
const names = [
|
|
'environment',
|
|
'nodeStart',
|
|
'v8Start',
|
|
'loopStart',
|
|
'loopExit',
|
|
'bootstrapComplete',
|
|
'thirdPartyMainStart',
|
|
'thirdPartyMainEnd',
|
|
'clusterSetupStart',
|
|
'clusterSetupEnd',
|
|
'moduleLoadStart',
|
|
'moduleLoadEnd',
|
|
'preloadModulesLoadStart',
|
|
'preloadModulesLoadEnd'
|
|
];
|
|
|
|
if (process.argv[2] === 'child') {
|
|
1 + 1;
|
|
} else {
|
|
tmpdir.refresh();
|
|
process.chdir(tmpdir.path);
|
|
|
|
const proc = cp.fork(__filename,
|
|
[ 'child' ], {
|
|
execArgv: [
|
|
'--trace-event-categories',
|
|
'node.bootstrap'
|
|
]
|
|
});
|
|
|
|
proc.once('exit', common.mustCall(() => {
|
|
const file = path.join(tmpdir.path, 'node_trace.1.log');
|
|
|
|
assert(common.fileExists(file));
|
|
fs.readFile(file, common.mustCall((err, data) => {
|
|
const traces = JSON.parse(data.toString()).traceEvents;
|
|
traces.forEach((trace) => {
|
|
assert.strictEqual(trace.pid, proc.pid);
|
|
assert(names.includes(trace.name));
|
|
});
|
|
}));
|
|
}));
|
|
}
|