Repository navigation
proxy: Name threads spawned by the event loop #324
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,10 @@ | |
| #include <pthread_np.h> | ||
| #endif // HAVE_PTHREAD_GETTHREADID_NP | ||
|
|
||
| #if __has_include(<sys/prctl.h>) | ||
| #include <sys/prctl.h> | ||
| #endif | ||
|
|
||
| extern "C" char **environ; // NOLINT(readability-redundant-declaration) | ||
|
|
||
| namespace mp { | ||
|
|
@@ -74,6 +78,24 @@ template <std::size_t N> | |
|
|
||
| } // namespace | ||
|
|
||
| // Copied from https://github.com/bitcoin/bitcoin/blob/d3e40af2597/src/util/threadnames.cpp#L21-L36 | ||
| void SetOsThreadName(const char* name) | ||
| { | ||
| #if defined(PR_SET_NAME) | ||
| // Only the first 15 characters are used (16 - NUL terminator) | ||
| ::prctl(PR_SET_NAME, name, 0, 0, 0); | ||
|
Collaborator
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. In commit "proxy: Name threads spawned by the event loop" (648a185) Could be nice for background to mention platforms being used in comments: prctl(PR_SET_NAME, name, 0, 0, 0); // Linux
pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name)); // NetBSD
pthread_set_name_np(pthread_self(), name); // FreeBSD
pthread_setname_np(name); // macOS
Member
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.
Addressed in #396. |
||
| #elif defined(HAVE_PTHREAD_SETNAME_NP_3ARG) | ||
| pthread_setname_np(pthread_self(), "%s", const_cast<char*>(name)); | ||
| #elif defined(HAVE_PTHREAD_GETTHREADID_NP) | ||
|
Collaborator
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. In commit "proxy: Name threads spawned by the event loop" (648a185) Would make sense to introduce a HAVE_PTHREAD_SET_NAME_NP macro here instead of using HAVE_PTHREAD_GETTHREADID_NP (which is for pthread_getthreadid_np) |
||
| pthread_set_name_np(pthread_self(), name); | ||
| #elif defined(__APPLE__) | ||
| pthread_setname_np(name); | ||
| #else | ||
| // Prevent warnings for unused parameters... | ||
| (void)name; | ||
|
Collaborator
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. In commit "proxy: Name threads spawned by the event loop" (61b6cd2) Note for followup probably will want to extend this to windows.
Contributor
Author
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 agree, for Bitcoin Core it would be useful too.
Contributor
Author
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. Opened for bitcoin core: bitcoin/bitcoin#35884 |
||
| #endif | ||
| } | ||
|
|
||
| std::string ThreadName(const char* exe_name) | ||
| { | ||
| char thread_name[16] = {0}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.