Skip to content
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

Rename threads to better aid with debugging #424

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,9 @@ class SSLIOStreamDevice : public iostreams::device<iostreams::bidirectional> {

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);

Expand Down Expand Up @@ -1128,6 +1131,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"];
Expand Down
4 changes: 4 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ bool GetMyExternalIP(CNetAddr& ipRet)

void ThreadGetMyExternalIP(void* parg)
{
// Make this thread recognisable as the external IP detection thread
RenameThread("paycoin-ext-ip");

CNetAddr addrLocalHost;
if (GetMyExternalIP(addrLocalHost))
{
Expand Down Expand Up @@ -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]++;
Expand Down Expand Up @@ -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]++;
Expand Down Expand Up @@ -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]++;
Expand Down Expand Up @@ -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);
Expand All @@ -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]++;
Expand Down Expand Up @@ -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]++;
Expand Down Expand Up @@ -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]++;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/qt/qtipcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace boost {
#endif
#include <io.h> /* for _commit */
#include "shlobj.h"
#elif defined(__linux__)
#include <sys/prctl.h>
#endif

#ifndef WIN32
Expand Down Expand Up @@ -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
}
4 changes: 1 addition & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,7 @@ inline void ExitThread(size_t nExitCode)
}
#endif




void RenameThread(const char* name);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everyone loves fixing excess whitespace.


inline uint32_t ByteReverse(uint32_t value)
{
Expand Down
3 changes: 3 additions & 0 deletions src/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down