mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
committed by
Node.js GitHub Bot
parent
7ba05b8065
commit
f32054ffde
@@ -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'`
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user