From 3ac200a6f81a741946c486acc0b2a0759378f436 Mon Sep 17 00:00:00 2001 From: Nathan Bass Date: Mon, 14 Dec 2015 11:25:12 -0600 Subject: [PATCH 1/3] Rename threads to better aid with debugging --- src/bitcoinrpc.cpp | 3 +++ src/init.cpp | 4 ++++ src/main.cpp | 3 +++ src/net.cpp | 27 +++++++++++++++++++++++++++ src/util.cpp | 13 +++++++++++++ src/util.h | 4 +--- src/walletdb.cpp | 3 +++ 7 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index cc1fb9b8..8302cfba 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1128,6 +1128,9 @@ static string JSONRPCExecBatch(const Array& vReq) void ThreadRPCServer2(void* parg) { + // Make this thread recognisable as the RPC server + RenameThread("paycoin-rpcserv"); + printf("ThreadRPCServer started\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; diff --git a/src/init.cpp b/src/init.cpp index ae98df8c..7f0b8eb2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -62,6 +62,10 @@ void Shutdown(void* parg) { static CCriticalSection cs_Shutdown; static bool fTaken; + + // Make this thread recognisable as the shutdown thread + RenameThread("paycoin-shutoff"); + bool fFirstThread = false; { TRY_LOCK(cs_Shutdown, lockShutdown); diff --git a/src/main.cpp b/src/main.cpp index 7d9801a4..982a0187 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4109,6 +4109,9 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) printf("CPUMiner started for proof-of-%s\n", fProofOfStake? "stake" : "work"); SetThreadPriority(THREAD_PRIORITY_LOWEST); + // Make this thread recognisable as the mining or staking thread + fProofOfStake ? RenameThread("paycoin [staker]") : RenameThread("paycoin [miner]"); + // Each thread has its own key and counter CReserveKey reservekey(pwallet); unsigned int nExtraNonce = 0; diff --git a/src/net.cpp b/src/net.cpp index 305904e0..e557c752 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -428,6 +428,9 @@ bool GetMyExternalIP(CNetAddr& ipRet) void ThreadGetMyExternalIP(void* parg) { + // Make this thread recognisable as the message handling thread + RenameThread("paycoin-ext-ip"); + CNetAddr addrLocalHost; if (GetMyExternalIP(addrLocalHost)) { @@ -660,6 +663,9 @@ void CNode::copyStats(CNodeStats &stats) void ThreadSocketHandler(void* parg) { + // Make this thread recognisable as the networking thread + RenameThread("paycoin [net]"); + try { vnThreadsRunning[THREAD_SOCKETHANDLER]++; @@ -1021,6 +1027,9 @@ void ThreadSocketHandler2(void* parg) #ifdef USE_UPNP void ThreadMapPort(void* parg) { + // Make this thread recognisable as the UPnP thread + RenameThread("paycoin [UPnP]"); + try { vnThreadsRunning[THREAD_UPNP]++; @@ -1187,6 +1196,9 @@ static const char *strDNSSeed[][2] = { void ThreadDNSAddressSeed(void* parg) { + // Make this thread recognisable as the DNS seeding thread + RenameThread("paycoin-dnsseed"); + try { vnThreadsRunning[THREAD_DNSSEED]++; @@ -1280,6 +1292,9 @@ void ThreadDumpAddress2(void* parg) void ThreadDumpAddress(void* parg) { + // Make this thread recognisable as the address dumping thread + RenameThread("paycoin-adrdump"); + try { ThreadDumpAddress2(parg); @@ -1292,6 +1307,9 @@ void ThreadDumpAddress(void* parg) void ThreadOpenConnections(void* parg) { + // Make this thread recognisable as the connection opening thread + RenameThread("paycoin-opencon"); + try { vnThreadsRunning[THREAD_OPENCONNECTIONS]++; @@ -1451,6 +1469,9 @@ void ThreadOpenConnections2(void* parg) void ThreadOpenAddedConnections(void* parg) { + // Make this thread recognisable as the connection opening thread + RenameThread("paycoin-opencon"); + try { vnThreadsRunning[THREAD_ADDEDCONNECTIONS]++; @@ -1594,6 +1615,9 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu void ThreadMessageHandler(void* parg) { + // Make this thread recognisable as the message handling thread + RenameThread("paycoin-msghand"); + try { vnThreadsRunning[THREAD_MESSAGEHANDLER]++; @@ -1864,6 +1888,9 @@ void static Discover() void StartNode(void* parg) { + // Make this thread recognisable as the startup Thread + RenameThread("paycoin [start]"); + #ifdef USE_UPNP #if USE_UPNP fUseUPnP = GetBoolArg("-upnp", true); diff --git a/src/util.cpp b/src/util.cpp index 7575b098..c8dd9dc3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -53,6 +53,8 @@ namespace boost { #endif #include /* for _commit */ #include "shlobj.h" +#elif defined(__linux__) +#include #endif #ifndef WIN32 @@ -1146,3 +1148,14 @@ bool NewThread(void(*pfn)(void*), void* parg) } return true; } + +void RenameThread(const char* name) +{ +#if defined(__linux__) && defined(PR_SET_NAME) + // Only the first 15 characters are used (16 - NUL terminator) + ::prctl(PR_SET_NAME, name, 0, 0, 0); +#else + // Prevent warnings for unused parameters + (void)name; +#endif +} diff --git a/src/util.h b/src/util.h index 2439beef..407a78dd 100644 --- a/src/util.h +++ b/src/util.h @@ -461,9 +461,7 @@ inline void ExitThread(size_t nExitCode) } #endif - - - +void RenameThread(const char* name); inline uint32_t ByteReverse(uint32_t value) { diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 16fcc041..b1a76ef8 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -328,6 +328,9 @@ int CWalletDB::LoadWallet(CWallet* pwallet) void ThreadFlushWalletDB(void* parg) { + // Make this thread recognisable as the wallet flushing thread + RenameThread("paycoin-wallet"); + const string& strFile = ((const string*)parg)[0]; static bool fOneThread; if (fOneThread) From bed1d3b55560f663a6b3acf805efcd6547aca29c Mon Sep 17 00:00:00 2001 From: Nathan Bass Date: Wed, 16 Dec 2015 11:41:06 -0600 Subject: [PATCH 2/3] Rename missed threads and fix names for consistency --- src/main.cpp | 2 +- src/net.cpp | 6 +++--- src/rpcwallet.cpp | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 982a0187..5e7ce291 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4110,7 +4110,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake) SetThreadPriority(THREAD_PRIORITY_LOWEST); // Make this thread recognisable as the mining or staking thread - fProofOfStake ? RenameThread("paycoin [staker]") : RenameThread("paycoin [miner]"); + fProofOfStake ? RenameThread("paycoin-staker") : RenameThread("paycoin-miner"); // Each thread has its own key and counter CReserveKey reservekey(pwallet); diff --git a/src/net.cpp b/src/net.cpp index e557c752..0a317602 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -664,7 +664,7 @@ void CNode::copyStats(CNodeStats &stats) void ThreadSocketHandler(void* parg) { // Make this thread recognisable as the networking thread - RenameThread("paycoin [net]"); + RenameThread("paycoin-net"); try { @@ -1028,7 +1028,7 @@ void ThreadSocketHandler2(void* parg) void ThreadMapPort(void* parg) { // Make this thread recognisable as the UPnP thread - RenameThread("paycoin [UPnP]"); + RenameThread("paycoin-UPnP"); try { @@ -1889,7 +1889,7 @@ void static Discover() void StartNode(void* parg) { // Make this thread recognisable as the startup Thread - RenameThread("paycoin [start]"); + RenameThread("paycoin-start"); #ifdef USE_UPNP #if USE_UPNP diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 595fe657..a0d91283 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1422,11 +1422,15 @@ Value keypoolrefill(const Array& params, bool fHelp) void ThreadTopUpKeyPool(void* parg) { + // Make this thread recognisable as the key-topping-up thread + RenameThread("paycoin-key-top"); pwalletMain->TopUpKeyPool(); } void ThreadCleanWalletPassphrase(void* parg) { + // Make this thread recognisable as the wallet unlocking thread + RenameThread("paycoin-lock-wa"); int64 nMyWakeTime = GetTimeMillis() + *((int64*)parg) * 1000; ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime); From e09088878db7d3b88cae5c93c2e5d3f4b7fcab6b Mon Sep 17 00:00:00 2001 From: Nathan Bass Date: Thu, 17 Dec 2015 11:30:11 -0600 Subject: [PATCH 3/3] rename more skipped threads and change comment in net --- src/bitcoinrpc.cpp | 3 +++ src/net.cpp | 2 +- src/qt/qtipcserver.cpp | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 8302cfba..631bbe58 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1051,6 +1051,9 @@ class SSLIOStreamDevice : public iostreams::device { void ThreadRPCServer(void* parg) { + // Rename thread to be recognisable as the rpc service runner thread + RenameThread("paycoin-rpcserv-runner"); + // getwork/getblocktemplate mining rewards paid here: pMiningKey = new CReserveKey(pwalletMain); diff --git a/src/net.cpp b/src/net.cpp index 0a317602..ca02adda 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -428,7 +428,7 @@ bool GetMyExternalIP(CNetAddr& ipRet) void ThreadGetMyExternalIP(void* parg) { - // Make this thread recognisable as the message handling thread + // Make this thread recognisable as the external IP detection thread RenameThread("paycoin-ext-ip"); CNetAddr addrLocalHost; diff --git a/src/qt/qtipcserver.cpp b/src/qt/qtipcserver.cpp index 4d201eba..e2d64fb0 100644 --- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -22,6 +22,9 @@ void ipcShutdown() void ipcThread(void* parg) { + // Rename thread to be recognisable as the ipc thread + RenameThread("paycoin-ipc"); + message_queue* mq = (message_queue*)parg; char strBuf[257]; size_t nSize;