-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
console: add trace-events for time and count
Add the `node.console` trace event category to capture `console.count()`, `console.countReset()`, `console.time()`, `console.timeLog()`, and `console.timeEnd()` to the trace event log. PR-URL: #23703 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]>
- Loading branch information
1 parent
47046aa
commit a9c11c9
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'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'); | ||
|
||
// Tests that node.console trace events for counters and time methods are | ||
// emitted as expected. | ||
|
||
const names = [ | ||
'time::foo', | ||
'count::bar' | ||
]; | ||
const expectedCounts = [ 1, 2, 0 ]; | ||
const expectedTimeTypes = [ 'b', 'n', 'e' ]; | ||
|
||
if (process.argv[2] === 'child') { | ||
// The following console outputs exercise the test, causing node.console | ||
// trace events to be emitted for the counter and time calls. | ||
console.count('bar'); | ||
console.count('bar'); | ||
console.countReset('bar'); | ||
console.time('foo'); | ||
setImmediate(() => { | ||
console.timeLog('foo'); | ||
setImmediate(() => { | ||
console.timeEnd('foo'); | ||
}); | ||
}); | ||
} else { | ||
tmpdir.refresh(); | ||
|
||
const proc = cp.fork(__filename, | ||
[ 'child' ], { | ||
cwd: tmpdir.path, | ||
execArgv: [ | ||
'--trace-event-categories', | ||
'node.console' | ||
] | ||
}); | ||
|
||
proc.once('exit', common.mustCall(async () => { | ||
const file = path.join(tmpdir.path, 'node_trace.1.log'); | ||
|
||
assert(fs.existsSync(file)); | ||
const data = await fs.promises.readFile(file, { encoding: 'utf8' }); | ||
JSON.parse(data).traceEvents | ||
.filter((trace) => trace.cat !== '__metadata') | ||
.forEach((trace) => { | ||
assert.strictEqual(trace.pid, proc.pid); | ||
assert(names.includes(trace.name)); | ||
if (trace.name === 'count::bar') | ||
assert.strictEqual(trace.args.data, expectedCounts.shift()); | ||
else if (trace.name === 'time::foo') | ||
assert.strictEqual(trace.ph, expectedTimeTypes.shift()); | ||
}); | ||
assert.strictEqual(expectedCounts.length, 0); | ||
assert.strictEqual(expectedTimeTypes.length, 0); | ||
})); | ||
} |