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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
RafaelGSS
2024-12-30 16:19:36 -03:00
committed by Node.js GitHub Bot
parent 7ba05b8065
commit f32054ffde
4 changed files with 13 additions and 5 deletions

View File

@@ -1229,9 +1229,16 @@ changes:
used for generated code.
* `stackSizeMb` {number} The default maximum stack size for the thread.
Small values may lead to unusable Worker instances. **Default:** `4`.
* `name` {string} An optional `name` to be appended to the worker title
for debugging/identification purposes, making the final title as
`[worker ${id}] ${name}`. **Default:** `''`.
* `name` {string} An optional `name` to be replaced in the thread name
and to the worker title for debugging/identification purposes,
making the final title as `[worker ${id}] ${name}`.
This parameter has a maximum allowed size, depending on the operating
system. If the provided name exceeds the limit, it will be truncated
* Maximum sizes:
* Windows: 32,767 characters
* macOS: 64 characters
* Other systems: 16 characters
**Default:** `'WorkerThread'`.
### Event: `'error'`

View File

@@ -204,7 +204,7 @@ class Worker extends EventEmitter {
options.env);
}
let name = '';
let name = 'WorkerThread';
if (options.name) {
validateString(options.name, 'options.name');
name = StringPrototypeTrim(options.name);

View File

@@ -740,6 +740,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
Worker* w = static_cast<Worker*>(arg);
const uintptr_t stack_top = reinterpret_cast<uintptr_t>(&arg);
uv_thread_setname(w->name_.c_str());
// Leave a few kilobytes just to make sure we're within limits and have
// some space to do work in C++ land.
w->stack_base_ = stack_top - (w->stack_size_ - kStackBufferSize);

View File

@@ -23,7 +23,7 @@ if (isMainThread) {
assert(traces.length > 0);
assert(traces.some((trace) =>
trace.cat === '__metadata' && trace.name === 'thread_name' &&
trace.args.name === '[worker 1]'));
trace.args.name === '[worker 1] WorkerThread'));
}));
}));
} else {