-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workers,trace_events: set thread name for workers
Set the thread name for workers in trace events. Also, use uint64_t for thread_id_ because there's really no reason for those to be doubles PR-URL: #21246 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
- Loading branch information
Showing
5 changed files
with
51 additions
and
9 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
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,33 @@ | ||
// Flags: --experimental-worker | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const fs = require('fs'); | ||
const { isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const CODE = 'const { Worker } = require(\'worker_threads\'); ' + | ||
`new Worker('${__filename.replace(/\\/g, '/')}')`; | ||
const FILE_NAME = 'node_trace.1.log'; | ||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
process.chdir(tmpdir.path); | ||
|
||
const proc = cp.spawn(process.execPath, | ||
[ '--experimental-worker', | ||
'--trace-event-categories', 'node', | ||
'-e', CODE ]); | ||
proc.once('exit', common.mustCall(() => { | ||
assert(common.fileExists(FILE_NAME)); | ||
fs.readFile(FILE_NAME, common.mustCall((err, data) => { | ||
const traces = JSON.parse(data.toString()).traceEvents; | ||
assert(traces.length > 0); | ||
assert(traces.some((trace) => | ||
trace.cat === '__metadata' && trace.name === 'thread_name' && | ||
trace.args.name === 'WorkerThread 1')); | ||
})); | ||
})); | ||
} else { | ||
// Do nothing here. | ||
} |