Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3579143

Browse filesBrowse files
RafaelGSStargos
authored andcommitted
src: set worker thread name using worker.name
Set the worker thread name using worker.name value and changing the default to "WorkerThread" PR-URL: #56416 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 736ff5d commit 3579143
Copy full SHA for 3579143

File tree

Expand file treeCollapse file tree

4 files changed

+13
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+13
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/worker_threads.md‎

Copy file name to clipboardExpand all lines: doc/api/worker_threads.md
+10-3Lines changed: 10 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,16 @@ changes:
12271227
used for generated code.
12281228
* `stackSizeMb` {number} The default maximum stack size for the thread.
12291229
Small values may lead to unusable Worker instances. **Default:** `4`.
1230-
* `name` {string} An optional `name` to be appended to the worker title
1231-
for debugging/identification purposes, making the final title as
1232-
`[worker ${id}] ${name}`. **Default:** `''`.
1230+
* `name` {string} An optional `name` to be replaced in the thread name
1231+
and to the worker title for debugging/identification purposes,
1232+
making the final title as `[worker ${id}] ${name}`.
1233+
This parameter has a maximum allowed size, depending on the operating
1234+
system. If the provided name exceeds the limit, it will be truncated
1235+
* Maximum sizes:
1236+
* Windows: 32,767 characters
1237+
* macOS: 64 characters
1238+
* Other systems: 16 characters
1239+
**Default:** `'WorkerThread'`.
12331240

12341241
### Event: `'error'`
12351242

Collapse file

‎lib/internal/worker.js‎

Copy file name to clipboardExpand all lines: lib/internal/worker.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class Worker extends EventEmitter {
204204
options.env);
205205
}
206206

207-
let name = '';
207+
let name = 'WorkerThread';
208208
if (options.name) {
209209
validateString(options.name, 'options.name');
210210
name = StringPrototypeTrim(options.name);
Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
740740
Worker* w = static_cast<Worker*>(arg);
741741
const uintptr_t stack_top = reinterpret_cast<uintptr_t>(&arg);
742742

743+
uv_thread_setname(w->name_.c_str());
743744
// Leave a few kilobytes just to make sure we're within limits and have
744745
// some space to do work in C++ land.
745746
w->stack_base_ = stack_top - (w->stack_size_ - kStackBufferSize);
Collapse file

‎test/parallel/test-trace-events-worker-metadata.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-trace-events-worker-metadata.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (isMainThread) {
2323
assert(traces.length > 0);
2424
assert(traces.some((trace) =>
2525
trace.cat === '__metadata' && trace.name === 'thread_name' &&
26-
trace.args.name === '[worker 1]'));
26+
trace.args.name === '[worker 1] WorkerThread'));
2727
}));
2828
}));
2929
} else {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.