Make debug easier by naming threads.

This commit is contained in:
JoelKatz
2013-03-20 05:41:08 -07:00
parent f3400d88fc
commit 9ceb380cb8
6 changed files with 50 additions and 2 deletions

View File

@@ -266,6 +266,7 @@ void JobQueue::threadEntry()
boost::mutex::scoped_lock sl(mJobLock);
while (1)
{
NameThread("waiting");
while (mJobSet.empty() && !mShuttingDown)
mJobCond.wait(sl);
@@ -286,6 +287,7 @@ void JobQueue::threadEntry()
++(mJobCounts[type].second);
sl.unlock();
NameThread(Job::toString(type));
cLog(lsTRACE) << "Doing " << Job::toString(type) << " job";
job.doJob();
} // must destroy job without holding lock

View File

@@ -317,6 +317,7 @@ int LoadManager::getUptime()
void LoadManager::threadEntry()
{
NameThread("loadMgr");
boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time();
while (1)
{

View File

@@ -48,6 +48,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
void WSDoor::startListening()
{
NameThread("websocket");
// Generate a single SSL context for use by all connections.
boost::shared_ptr<boost::asio::ssl::context> mCtx;
mCtx = boost::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);

View File

@@ -127,6 +127,7 @@ void printHelp(const po::options_description& desc)
int main(int argc, char* argv[])
{
NameThread("main");
int iResult = 0;
po::variables_map vm; // Map of options.
@@ -248,6 +249,7 @@ int main(int argc, char* argv[])
{
// No arguments. Run server.
setupServer();
NameThread("io");
startServer();
}
else

View File

@@ -1,5 +1,9 @@
#include "utils.h"
#include "uint256.h"
#ifdef __linux__
#include <sys/prctl.h>
#endif
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
@@ -9,6 +13,9 @@
#include <openssl/rand.h>
#include "utils.h"
#include "uint256.h"
void getRand(unsigned char *buf, int num)
{
if (RAND_bytes(buf, num) != 1)
@@ -333,6 +340,39 @@ uint32_t be32toh(uint32_t value)
#endif
#ifdef PR_SET_NAME
#define HAVE_NAME_THREAD
extern void NameThread(const char* n)
{
static std::string pName;
if (pName.empty())
{
std::ifstream cLine("/proc/self/cmdline", std::ios::in);
cLine >> pName;
if (pName.empty())
pName = "rippled";
else
{
size_t zero = pName.find_first_of('\0');
if ((zero != std::string::npos) && (zero != 0))
pName = pName.substr(0, zero - 1);
size_t slash = pName.find_last_of('/');
if (slash != std::string::npos)
pName = pName.substr(slash + 1);
}
pName += " ";
}
prctl(PR_SET_NAME, (pName + n).c_str(), 0, 0, 0);
}
#endif
#ifndef HAVE_NAME_THREAD
extern void NameThread(const char*)
{ ; }
#endif
BOOST_AUTO_TEST_SUITE( Utils)
BOOST_AUTO_TEST_CASE( ParseUrl )

View File

@@ -286,6 +286,8 @@ template<typename T, typename U> T range_check_cast(const U& value, const T& min
bool parseUrl(const std::string& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath);
extern void NameThread(const char *);
#if (!defined(FORCE_NO_C11X) && (__cplusplus > 201100L)) || defined(FORCE_C11X)
#define C11X