-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
src,lib: use uv_thread_setname to a better multi-thread debugging #56416
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d774d9
src: use a default thread name for inspector
RafaelGSS 7667e8f
src: set worker thread name using worker.name
RafaelGSS f62cfd6
src: set thread name for main thread and v8 worker
RafaelGSS 1a588eb
src: set signal inspector io thread name
RafaelGSS 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1165,6 +1165,7 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args, | |
} | ||
|
||
if (!(flags & ProcessInitializationFlags::kNoInitializeNodeV8Platform)) { | ||
uv_thread_setname("MainThread"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if that's the best place to do it. |
||
per_process::v8_platform.Initialize( | ||
static_cast<int>(per_process::cli_options->v8_thread_pool_size)); | ||
result->platform_ = per_process::v8_platform.Platform(); | ||
|
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,29 @@ | ||
#include <node.h> | ||
#include <uv.h> | ||
#include <v8.h> | ||
|
||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
void GetThreadName(const FunctionCallbackInfo<Value>& args) { | ||
Isolate* isolate = args.GetIsolate(); | ||
uv_thread_t thread; | ||
char thread_name[16]; | ||
#ifdef _WIN32 | ||
/* uv_thread_self isn't defined for the main thread on Windows. */ | ||
thread = GetCurrentThread(); | ||
#else | ||
thread = uv_thread_self(); | ||
#endif | ||
uv_thread_getname(&thread, thread_name, sizeof(thread_name)); | ||
args.GetReturnValue().Set( | ||
String::NewFromUtf8(isolate, thread_name).ToLocalChecked()); | ||
} | ||
|
||
void init(v8::Local<v8::Object> exports) { | ||
NODE_SET_METHOD(exports, "getThreadName", GetThreadName); | ||
} | ||
|
||
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, init) |
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,9 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ], | ||
'includes': ['../common.gypi'], | ||
} | ||
] | ||
} |
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,35 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
|
||
if (common.isAIX) { | ||
common.skip('AIX is not supported by libuv'); | ||
} | ||
|
||
const assert = require('node:assert'); | ||
const { parentPort, Worker, isMainThread } = require('node:worker_threads'); | ||
const bindingPath = require.resolve(`./build/${common.buildType}/binding`); | ||
const binding = require(bindingPath); | ||
|
||
if (isMainThread) { | ||
assert.strictEqual(binding.getThreadName(), 'MainThread'); | ||
|
||
const worker = new Worker(__filename); | ||
worker.on('message', common.mustCall((data) => { | ||
assert.strictEqual(data, 'WorkerThread'); | ||
})); | ||
worker.on('error', common.mustNotCall()); | ||
worker.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
})); | ||
|
||
const namedWorker = new Worker(__filename, { name: 'NamedThread' }); | ||
namedWorker.on('message', common.mustCall((data) => { | ||
assert.strictEqual(data, 'NamedThread'); | ||
})); | ||
namedWorker.on('error', common.mustNotCall()); | ||
namedWorker.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
})); | ||
} else { | ||
parentPort.postMessage(binding.getThreadName()); | ||
} |
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
Oops, something went wrong.
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.