-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
console: add trace-events for time and count #23703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+76
−1
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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); | ||
| })); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.