-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
worker: add support for worker name in inspector and trace_events #46832
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c977783
worker: add support for worker name in inspector and trace_events
debadree25 35811f5
fixup! remove breaking change
debadree25 2680a3e
fixup! add a test
debadree25 b6738e1
fixup! add doc
debadree25 1521950
fixup! lint
debadree25 2b4f742
fixup! lint
debadree25 38be52f
fixup! null check
debadree25 53e7098
fixup! simplify function
debadree25 54286bd
fixup! update name formation
debadree25 2e9c50b
fixup! refactor option name
debadree25 7d7c4e8
fixup! update worker trace name
debadree25 402bc6c
fixup! lint
debadree25 1bd70c2
fixup! lint
debadree25 28f812e
fixup! lint again
debadree25 1dd3e70
fixup! surround with mustcall
debadree25 239c849
fixup!
debadree25 21f8114
fixup! move the session to worker thread
debadree25 e75082d
fixup! keep worker alive
debadree25 48d97d6
fixup! move worker code to a fixture
debadree25 f5090a8
fixup! typo
debadree25 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
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
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
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,17 @@ | ||
const { Session } = require('inspector'); | ||
const { parentPort } = require('worker_threads'); | ||
|
||
const session = new Session(); | ||
|
||
parentPort.once('message', () => {}); // Prevent the worker from exiting. | ||
|
||
session.connectToMainThread(); | ||
|
||
session.on( | ||
'NodeWorker.attachedToWorker', | ||
({ params: { workerInfo } }) => { | ||
// send the worker title to the main thread | ||
parentPort.postMessage(workerInfo.title); | ||
} | ||
); | ||
session.post('NodeWorker.enable', { waitForDebuggerOnStart: false }); |
31 changes: 31 additions & 0 deletions
31
test/parallel/test-trace-events-worker-metadata-with-name.js
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,31 @@ | ||
'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, '/')}', { name: 'foo' })`; | ||
const FILE_NAME = 'node_trace.1.log'; | ||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
process.chdir(tmpdir.path); | ||
|
||
const proc = cp.spawn(process.execPath, | ||
[ '--trace-event-categories', 'node', | ||
'-e', CODE ]); | ||
proc.once('exit', common.mustCall(() => { | ||
assert(fs.existsSync(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 === '[worker 1] foo')); | ||
})); | ||
})); | ||
} else { | ||
// Do nothing here. | ||
} |
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,22 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
common.skipIfWorker(); // This test requires both main and worker threads. | ||
|
||
const assert = require('assert'); | ||
const { Worker, isMainThread } = require('worker_threads'); | ||
|
||
if (isMainThread) { | ||
const name = 'Hello Thread'; | ||
const expectedTitle = `[worker 1] ${name}`; | ||
const worker = new Worker(fixtures.path('worker-name.js'), { | ||
name, | ||
}); | ||
worker.once('message', common.mustCall((message) => { | ||
assert.strictEqual(message, expectedTitle); | ||
worker.postMessage('done'); | ||
})); | ||
} |
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.