Set thread names for better debugging
This commit is contained in:
@@ -345,6 +345,16 @@ int main(int argc, char* argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}" HAVE_RES_QUERY)
|
}" HAVE_RES_QUERY)
|
||||||
|
|
||||||
|
check_c_source_compiles("
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_setname_np(pthread_self(), \"Main\");
|
||||||
|
return 0;
|
||||||
|
}" HAVE_PTHREAD_SETNAME_NP)
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_LIBRARIES)
|
set(CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
|
||||||
if (HAVE_BUILTIN_CLZLL)
|
if (HAVE_BUILTIN_CLZLL)
|
||||||
@@ -366,6 +376,10 @@ if (HAVE_RES_QUERY)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (HAVE_PTHREAD_SETNAME_NP)
|
||||||
|
add_definitions(/DHAVE_PTHREAD_SETNAME_NP)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_definitions("-DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag")
|
add_definitions("-DRAPIDJSON_PARSE_DEFAULT_FLAGS=kParseTrailingCommasFlag")
|
||||||
|
|
||||||
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES})
|
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES})
|
||||||
|
|||||||
@@ -250,6 +250,8 @@ private:
|
|||||||
|
|
||||||
NOINLINE void run()
|
NOINLINE void run()
|
||||||
{
|
{
|
||||||
|
set_thread_name("Logger");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
uv_mutex_lock(&m_mutex);
|
uv_mutex_lock(&m_mutex);
|
||||||
if (m_readPos == m_writePos.load()) {
|
if (m_readPos == m_writePos.load()) {
|
||||||
|
|||||||
@@ -404,6 +404,8 @@ void MergeMiningClientJSON_RPC::loop(void* data)
|
|||||||
{
|
{
|
||||||
LOGINFO(1, "event loop started");
|
LOGINFO(1, "event loop started");
|
||||||
|
|
||||||
|
set_thread_name("MM JSON RPC");
|
||||||
|
|
||||||
MergeMiningClientJSON_RPC* client = static_cast<MergeMiningClientJSON_RPC*>(data);
|
MergeMiningClientJSON_RPC* client = static_cast<MergeMiningClientJSON_RPC*>(data);
|
||||||
|
|
||||||
int err = uv_run(&client->m_loop, UV_RUN_DEFAULT);
|
int err = uv_run(&client->m_loop, UV_RUN_DEFAULT);
|
||||||
|
|||||||
@@ -1953,6 +1953,8 @@ int p2pool::run()
|
|||||||
loop->data = nullptr;
|
loop->data = nullptr;
|
||||||
GetLoopUserData(loop);
|
GetLoopUserData(loop);
|
||||||
|
|
||||||
|
set_thread_name("Main");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
get_info();
|
get_info();
|
||||||
load_found_blocks();
|
load_found_blocks();
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ void RandomX_Hasher::set_seed(const hash& seed)
|
|||||||
{
|
{
|
||||||
// Background doesn't work very well with xmrig mining on all cores
|
// Background doesn't work very well with xmrig mining on all cores
|
||||||
//make_thread_background();
|
//make_thread_background();
|
||||||
|
set_thread_name("Dataset init");
|
||||||
randomx_init_dataset(m_dataset, m_cache[m_index], a, b - a);
|
randomx_init_dataset(m_dataset, m_cache[m_index], a, b - a);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -426,6 +427,8 @@ void RandomX_Hasher_RPC::loop(void* data)
|
|||||||
{
|
{
|
||||||
LOGINFO(1, "event loop started");
|
LOGINFO(1, "event loop started");
|
||||||
|
|
||||||
|
set_thread_name("RX hash RPC");
|
||||||
|
|
||||||
RandomX_Hasher_RPC* hasher = static_cast<RandomX_Hasher_RPC*>(data);
|
RandomX_Hasher_RPC* hasher = static_cast<RandomX_Hasher_RPC*>(data);
|
||||||
|
|
||||||
int err = uv_run(&hasher->m_loop, UV_RUN_DEFAULT);
|
int err = uv_run(&hasher->m_loop, UV_RUN_DEFAULT);
|
||||||
|
|||||||
@@ -2370,6 +2370,8 @@ void SideChain::launch_precalc(const PoolBlock* block)
|
|||||||
|
|
||||||
void SideChain::precalc_worker()
|
void SideChain::precalc_worker()
|
||||||
{
|
{
|
||||||
|
set_thread_name("Precalc");
|
||||||
|
|
||||||
std::vector<std::pair<size_t, const Wallet*>> wallets;
|
std::vector<std::pair<size_t, const Wallet*>> wallets;
|
||||||
wallets.reserve(m_chainWindowSize);
|
wallets.reserve(m_chainWindowSize);
|
||||||
|
|
||||||
|
|||||||
@@ -615,6 +615,17 @@ void TCPServer::loop(void* data)
|
|||||||
TCPServer* server = static_cast<TCPServer*>(data);
|
TCPServer* server = static_cast<TCPServer*>(data);
|
||||||
|
|
||||||
log_category_prefix = server->get_log_category();
|
log_category_prefix = server->get_log_category();
|
||||||
|
{
|
||||||
|
char buf[64] = {};
|
||||||
|
log::Stream s(buf);
|
||||||
|
s << log_category_prefix;
|
||||||
|
|
||||||
|
if (s.m_pos > 0) {
|
||||||
|
buf[s.m_pos - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
set_thread_name(buf);
|
||||||
|
}
|
||||||
|
|
||||||
LOGINFO(1, "event loop started");
|
LOGINFO(1, "event loop started");
|
||||||
server_event_loop_thread = data;
|
server_event_loop_thread = data;
|
||||||
|
|||||||
@@ -846,4 +846,21 @@ NOINLINE PerfTimer::~PerfTimer()
|
|||||||
LOGINFO(m_level, m_name << " took " << dt.count() << " ms");
|
LOGINFO(m_level, m_name << " took " << dt.count() << " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_thread_name(const char* name)
|
||||||
|
{
|
||||||
|
#if (UV_VERSION_MAJOR > 1) || ((UV_VERSION_MAJOR == 1) && (UV_VERSION_MINOR >= 50))
|
||||||
|
const int err = uv_thread_setname(name);
|
||||||
|
if (err) {
|
||||||
|
LOGERR(1, "uv_thread_setname failed for " << name << ", error " << uv_err_name(err));
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_PTHREAD_SETNAME_NP)
|
||||||
|
const int err = pthread_setname_np(pthread_self(), name);
|
||||||
|
if (err) {
|
||||||
|
LOGERR(1, "pthread_setname_np failed for " << name << ", error " << err);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)name;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace p2pool
|
} // namespace p2pool
|
||||||
|
|||||||
@@ -232,4 +232,6 @@ void parallel_run(uv_loop_t* loop, T&& callback, bool wait = false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_thread_name(const char* name);
|
||||||
|
|
||||||
} // namespace p2pool
|
} // namespace p2pool
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ void ZMQReader::monitor_thread(void* arg)
|
|||||||
{
|
{
|
||||||
LOGINFO(1, "monitor thread ready");
|
LOGINFO(1, "monitor thread ready");
|
||||||
|
|
||||||
|
set_thread_name("ZMQ monitor");
|
||||||
|
|
||||||
ZMQReader* r = reinterpret_cast<ZMQReader*>(arg);
|
ZMQReader* r = reinterpret_cast<ZMQReader*>(arg);
|
||||||
|
|
||||||
do {} while (!r->m_stopped && r->m_monitor->m_connected && r->m_monitor->check_event(-1));
|
do {} while (!r->m_stopped && r->m_monitor->m_connected && r->m_monitor->check_event(-1));
|
||||||
@@ -151,6 +153,8 @@ void ZMQReader::run()
|
|||||||
m_workerThreadRunning = true;
|
m_workerThreadRunning = true;
|
||||||
ON_SCOPE_LEAVE([this]() { m_workerThreadRunning = false; });
|
ON_SCOPE_LEAVE([this]() { m_workerThreadRunning = false; });
|
||||||
|
|
||||||
|
set_thread_name("ZMQ worker");
|
||||||
|
|
||||||
zmq_msg_t message = {};
|
zmq_msg_t message = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user