diff --git a/src/libxrpl/basics/ThreadUtilities.cpp b/src/libxrpl/basics/ThreadUtilities.cpp index be1745c40a7..7ce68f1f9de 100644 --- a/src/libxrpl/basics/ThreadUtilities.cpp +++ b/src/libxrpl/basics/ThreadUtilities.cpp @@ -17,7 +17,9 @@ */ //============================================================================== -#include +#include + +#include #include namespace ripple { @@ -46,6 +48,7 @@ get_name() void set_name(std::string s) { + assert(s.size() <= 15); s.resize(15); if (pthread_setname_np(s.data()) != 0) throw std::runtime_error("this_thread::set_name failed\n"); @@ -79,6 +82,7 @@ get_name() void set_name(std::string s) { + assert(s.size() <= 15); s.resize(15); if (pthread_setname_np(pthread_self(), s.data()) != 0) throw std::runtime_error("this_thread::set_name failed\n"); @@ -90,11 +94,15 @@ set_name(std::string s) #ifdef _WIN64 +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif +// clang-format off #include -#include #include +#include +// clang-format on std::string get_name(std::thread::native_handle_type t) diff --git a/src/xrpld/app/main/BasicApp.cpp b/src/xrpld/app/main/BasicApp.cpp index f2b3e7c93bc..f65e4df257e 100644 --- a/src/xrpld/app/main/BasicApp.cpp +++ b/src/xrpld/app/main/BasicApp.cpp @@ -29,8 +29,10 @@ BasicApp::BasicApp(std::size_t numberOfThreads) while (numberOfThreads--) { threads_.emplace_back([this, numberOfThreads]() { + // pretty unlikely we'll have 7 digit numbers of threads, but play + // it safe ripple::this_thread::set_name( - "io svc #" + std::to_string(numberOfThreads)); + "io svc #" + std::to_string(numberOfThreads).substr(0, 7)); this->io_service_.run(); }); } diff --git a/src/xrpld/app/main/Main.cpp b/src/xrpld/app/main/Main.cpp index f759893f21a..38ac881537e 100644 --- a/src/xrpld/app/main/Main.cpp +++ b/src/xrpld/app/main/Main.cpp @@ -353,7 +353,8 @@ run(int argc, char** argv) { using namespace std; - this_thread::set_name("main " + BuildInfo::getVersionString()); + this_thread::set_name( + "main " + BuildInfo::getVersionString().substr(0, 10)); po::variables_map vm; diff --git a/src/xrpld/core/detail/Job.cpp b/src/xrpld/core/detail/Job.cpp index 478da846a16..0fb992988df 100644 --- a/src/xrpld/core/detail/Job.cpp +++ b/src/xrpld/core/detail/Job.cpp @@ -62,7 +62,7 @@ Job::queue_time() const void Job::doJob() { - this_thread::set_name("doJob: " + mName); + this_thread::set_name("doJob: " + mName.substr(0, 8)); m_loadEvent->start(); m_loadEvent->setName(mName); diff --git a/src/xrpld/core/detail/Workers.cpp b/src/xrpld/core/detail/Workers.cpp index e2c688e2d42..0d38d07b527 100644 --- a/src/xrpld/core/detail/Workers.cpp +++ b/src/xrpld/core/detail/Workers.cpp @@ -209,7 +209,7 @@ Workers::Worker::run() for (;;) { // Put the name back in case the callback changed it - this_thread::set_name(threadName_); + this_thread::set_name(threadName_.substr(0, 15)); // Acquire a task or "internal task." // @@ -262,7 +262,7 @@ Workers::Worker::run() } // Set inactive thread name. - this_thread::set_name("(" + threadName_ + ")"); + this_thread::set_name("(" + threadName_.substr(0, 13) + ")"); // [1] We will be here when the paused list is popped // diff --git a/src/xrpld/nodestore/backend/RocksDBFactory.cpp b/src/xrpld/nodestore/backend/RocksDBFactory.cpp index 145814a440b..c9100d6755f 100644 --- a/src/xrpld/nodestore/backend/RocksDBFactory.cpp +++ b/src/xrpld/nodestore/backend/RocksDBFactory.cpp @@ -68,7 +68,7 @@ class RocksDBEnv : public rocksdb::EnvWrapper std::size_t const id(++n); std::stringstream ss; ss << "rocksdb #" << id; - this_thread::set_name(ss.str()); + this_thread::set_name(ss.str().substr(0, 15)); (*f)(a); } diff --git a/src/xrpld/nodestore/detail/Database.cpp b/src/xrpld/nodestore/detail/Database.cpp index 3f7bc84e67c..0904f46f925 100644 --- a/src/xrpld/nodestore/detail/Database.cpp +++ b/src/xrpld/nodestore/detail/Database.cpp @@ -57,7 +57,10 @@ Database::Database( [this](int i) { runningThreads_++; - this_thread::set_name("prefetch " + std::to_string(i)); + // pretty unlikely we'll have 6 digit numbers of threads, but + // play it safe + this_thread::set_name( + "prefetch " + std::to_string(i).substr(0, 6)); decltype(read_) read;