mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Revert ThreadName due to problems on Windows (#4702)
* Revert "Remove CurrentThreadName.h from RippledCore.cmake (#4697)" This reverts commit3b5fcd5873. * Revert "Introduce replacement for getting and setting thread name: (#4312)" This reverts commit36cb5f90e2.
This commit is contained in:
@@ -24,6 +24,7 @@ add_library(xrpl::libxrpl ALIAS libxrpl)
|
|||||||
#]===============================]
|
#]===============================]
|
||||||
target_sources (xrpl_core PRIVATE
|
target_sources (xrpl_core PRIVATE
|
||||||
src/ripple/beast/clock/basic_seconds_clock.cpp
|
src/ripple/beast/clock/basic_seconds_clock.cpp
|
||||||
|
src/ripple/beast/core/CurrentThreadName.cpp
|
||||||
src/ripple/beast/core/SemanticVersion.cpp
|
src/ripple/beast/core/SemanticVersion.cpp
|
||||||
src/ripple/beast/hash/impl/xxhash.cpp
|
src/ripple/beast/hash/impl/xxhash.cpp
|
||||||
src/ripple/beast/insight/impl/Collector.cpp
|
src/ripple/beast/insight/impl/Collector.cpp
|
||||||
@@ -55,7 +56,6 @@ target_sources (xrpl_core PRIVATE
|
|||||||
src/ripple/basics/impl/Log.cpp
|
src/ripple/basics/impl/Log.cpp
|
||||||
src/ripple/basics/impl/Number.cpp
|
src/ripple/basics/impl/Number.cpp
|
||||||
src/ripple/basics/impl/StringUtilities.cpp
|
src/ripple/basics/impl/StringUtilities.cpp
|
||||||
src/ripple/basics/impl/ThreadUtilities.cpp
|
|
||||||
#[===============================[
|
#[===============================[
|
||||||
main sources:
|
main sources:
|
||||||
subdir: json
|
subdir: json
|
||||||
@@ -203,7 +203,6 @@ install (
|
|||||||
src/ripple/basics/tagged_integer.h
|
src/ripple/basics/tagged_integer.h
|
||||||
src/ripple/basics/SubmitSync.h
|
src/ripple/basics/SubmitSync.h
|
||||||
src/ripple/basics/ThreadSafetyAnalysis.h
|
src/ripple/basics/ThreadSafetyAnalysis.h
|
||||||
src/ripple/basics/ThreadUtilities.h
|
|
||||||
src/ripple/basics/ToString.h
|
src/ripple/basics/ToString.h
|
||||||
src/ripple/basics/UnorderedContainers.h
|
src/ripple/basics/UnorderedContainers.h
|
||||||
src/ripple/basics/UptimeClock.h
|
src/ripple/basics/UptimeClock.h
|
||||||
@@ -315,6 +314,7 @@ install (
|
|||||||
DESTINATION include/ripple/beast/clock)
|
DESTINATION include/ripple/beast/clock)
|
||||||
install (
|
install (
|
||||||
FILES
|
FILES
|
||||||
|
src/ripple/beast/core/CurrentThreadName.h
|
||||||
src/ripple/beast/core/LexicalCast.h
|
src/ripple/beast/core/LexicalCast.h
|
||||||
src/ripple/beast/core/List.h
|
src/ripple/beast/core/List.h
|
||||||
src/ripple/beast/core/SemanticVersion.h
|
src/ripple/beast/core/SemanticVersion.h
|
||||||
@@ -846,7 +846,6 @@ if (tests)
|
|||||||
src/test/basics/Slice_test.cpp
|
src/test/basics/Slice_test.cpp
|
||||||
src/test/basics/StringUtilities_test.cpp
|
src/test/basics/StringUtilities_test.cpp
|
||||||
src/test/basics/TaggedCache_test.cpp
|
src/test/basics/TaggedCache_test.cpp
|
||||||
src/test/basics/ThreadName_test.cpp
|
|
||||||
src/test/basics/XRPAmount_test.cpp
|
src/test/basics/XRPAmount_test.cpp
|
||||||
src/test/basics/base64_test.cpp
|
src/test/basics/base64_test.cpp
|
||||||
src/test/basics/base_uint_test.cpp
|
src/test/basics/base_uint_test.cpp
|
||||||
@@ -864,6 +863,7 @@ if (tests)
|
|||||||
src/test/beast/LexicalCast_test.cpp
|
src/test/beast/LexicalCast_test.cpp
|
||||||
src/test/beast/SemanticVersion_test.cpp
|
src/test/beast/SemanticVersion_test.cpp
|
||||||
src/test/beast/aged_associative_container_test.cpp
|
src/test/beast/aged_associative_container_test.cpp
|
||||||
|
src/test/beast/beast_CurrentThreadName_test.cpp
|
||||||
src/test/beast/beast_Journal_test.cpp
|
src/test/beast/beast_Journal_test.cpp
|
||||||
src/test/beast/beast_PropertyStream_test.cpp
|
src/test/beast/beast_PropertyStream_test.cpp
|
||||||
src/test/beast/beast_Zero_test.cpp
|
src/test/beast/beast_Zero_test.cpp
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include <ripple/app/ledger/LedgerCleaner.h>
|
#include <ripple/app/ledger/LedgerCleaner.h>
|
||||||
#include <ripple/app/ledger/LedgerMaster.h>
|
#include <ripple/app/ledger/LedgerMaster.h>
|
||||||
#include <ripple/app/misc/LoadFeeTrack.h>
|
#include <ripple/app/misc/LoadFeeTrack.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/protocol/jss.h>
|
#include <ripple/protocol/jss.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
@@ -218,7 +218,7 @@ private:
|
|||||||
void
|
void
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
this_thread::set_name("LedgerCleaner");
|
beast::setCurrentThreadName("LedgerCleaner");
|
||||||
JLOG(j_.debug()) << "Started";
|
JLOG(j_.debug()) << "Started";
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/app/main/BasicApp.h>
|
#include <ripple/app/main/BasicApp.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
|
|
||||||
BasicApp::BasicApp(std::size_t numberOfThreads)
|
BasicApp::BasicApp(std::size_t numberOfThreads)
|
||||||
{
|
{
|
||||||
@@ -28,7 +28,7 @@ BasicApp::BasicApp(std::size_t numberOfThreads)
|
|||||||
while (numberOfThreads--)
|
while (numberOfThreads--)
|
||||||
{
|
{
|
||||||
threads_.emplace_back([this, numberOfThreads]() {
|
threads_.emplace_back([this, numberOfThreads]() {
|
||||||
ripple::this_thread::set_name(
|
beast::setCurrentThreadName(
|
||||||
"io svc #" + std::to_string(numberOfThreads));
|
"io svc #" + std::to_string(numberOfThreads));
|
||||||
this->io_service_.run();
|
this->io_service_.run();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <ripple/app/main/GRPCServer.h>
|
#include <ripple/app/main/GRPCServer.h>
|
||||||
#include <ripple/app/reporting/P2pProxy.h>
|
#include <ripple/app/reporting/P2pProxy.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/resource/Fees.h>
|
#include <ripple/resource/Fees.h>
|
||||||
|
|
||||||
#include <ripple/beast/net/IPAddressConversion.h>
|
#include <ripple/beast/net/IPAddressConversion.h>
|
||||||
@@ -692,8 +692,9 @@ GRPCServer::start()
|
|||||||
if (running_ = impl_.start(); running_)
|
if (running_ = impl_.start(); running_)
|
||||||
{
|
{
|
||||||
thread_ = std::thread([this]() {
|
thread_ = std::thread([this]() {
|
||||||
|
beast::setCurrentThreadName("rippled : GRPCServer");
|
||||||
// Start the event loop and begin handling requests
|
// Start the event loop and begin handling requests
|
||||||
this_thread::set_name("rippled: grpc");
|
beast::setCurrentThreadName("rippled: grpc");
|
||||||
this->impl_.handleRpcs();
|
this->impl_.handleRpcs();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
#include <ripple/app/main/LoadManager.h>
|
#include <ripple/app/main/LoadManager.h>
|
||||||
#include <ripple/app/misc/LoadFeeTrack.h>
|
#include <ripple/app/misc/LoadFeeTrack.h>
|
||||||
#include <ripple/app/misc/NetworkOPs.h>
|
#include <ripple/app/misc/NetworkOPs.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/UptimeClock.h>
|
#include <ripple/basics/UptimeClock.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/json/to_string.h>
|
#include <ripple/json/to_string.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -99,7 +99,7 @@ LoadManager::stop()
|
|||||||
void
|
void
|
||||||
LoadManager::run()
|
LoadManager::run()
|
||||||
{
|
{
|
||||||
this_thread::set_name("LoadManager");
|
beast::setCurrentThreadName("LoadManager");
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
using clock_type = std::chrono::steady_clock;
|
using clock_type = std::chrono::steady_clock;
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
#include <ripple/app/rdb/Vacuum.h>
|
#include <ripple/app/rdb/Vacuum.h>
|
||||||
#include <ripple/basics/Log.h>
|
#include <ripple/basics/Log.h>
|
||||||
#include <ripple/basics/StringUtilities.h>
|
#include <ripple/basics/StringUtilities.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/contract.h>
|
#include <ripple/basics/contract.h>
|
||||||
#include <ripple/beast/clock/basic_seconds_clock.h>
|
#include <ripple/beast/clock/basic_seconds_clock.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/core/Config.h>
|
#include <ripple/core/Config.h>
|
||||||
#include <ripple/core/ConfigSections.h>
|
#include <ripple/core/ConfigSections.h>
|
||||||
#include <ripple/core/TimeKeeper.h>
|
#include <ripple/core/TimeKeeper.h>
|
||||||
@@ -348,7 +348,8 @@ run(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
this_thread::set_name("main " + BuildInfo::getVersionString());
|
beast::setCurrentThreadName(
|
||||||
|
"rippled: main " + BuildInfo::getVersionString());
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
|
|
||||||
@@ -826,7 +827,7 @@ run(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We have an RPC command to process:
|
// We have an RPC command to process:
|
||||||
this_thread::set_name("rippled: rpc");
|
beast::setCurrentThreadName("rippled: rpc");
|
||||||
return RPCCall::fromCommandLine(
|
return RPCCall::fromCommandLine(
|
||||||
*config, vm["parameters"].as<std::vector<std::string>>(), *logs);
|
*config, vm["parameters"].as<std::vector<std::string>>(), *logs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include <ripple/app/misc/NetworkOPs.h>
|
#include <ripple/app/misc/NetworkOPs.h>
|
||||||
#include <ripple/app/rdb/State.h>
|
#include <ripple/app/rdb/State.h>
|
||||||
#include <ripple/app/rdb/backend/SQLiteDatabase.h>
|
#include <ripple/app/rdb/backend/SQLiteDatabase.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/core/ConfigSections.h>
|
#include <ripple/core/ConfigSections.h>
|
||||||
#include <ripple/core/Pg.h>
|
#include <ripple/core/Pg.h>
|
||||||
#include <ripple/nodestore/Scheduler.h>
|
#include <ripple/nodestore/Scheduler.h>
|
||||||
@@ -286,7 +286,7 @@ SHAMapStoreImp::run()
|
|||||||
"Reporting does not support online_delete. Remove "
|
"Reporting does not support online_delete. Remove "
|
||||||
"online_delete info from config");
|
"online_delete info from config");
|
||||||
}
|
}
|
||||||
this_thread::set_name("SHAMapStore");
|
beast::setCurrentThreadName("SHAMapStore");
|
||||||
LedgerIndex lastRotated = state_db_.getState().lastRotated;
|
LedgerIndex lastRotated = state_db_.getState().lastRotated;
|
||||||
netOPs_ = &app_.getOPs();
|
netOPs_ = &app_.getOPs();
|
||||||
ledgerMaster_ = &app_.getLedgerMaster();
|
ledgerMaster_ = &app_.getLedgerMaster();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <ripple/app/reporting/ETLSource.h>
|
#include <ripple/app/reporting/ETLSource.h>
|
||||||
#include <ripple/app/reporting/ReportingETL.h>
|
#include <ripple/app/reporting/ReportingETL.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/json/json_reader.h>
|
#include <ripple/json/json_reader.h>
|
||||||
#include <ripple/json/json_writer.h>
|
#include <ripple/json/json_writer.h>
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
#include <ripple/app/rdb/backend/PostgresDatabase.h>
|
#include <ripple/app/rdb/backend/PostgresDatabase.h>
|
||||||
#include <ripple/app/reporting/ReportingETL.h>
|
#include <ripple/app/reporting/ReportingETL.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/json/json_reader.h>
|
#include <ripple/json/json_reader.h>
|
||||||
#include <ripple/json/json_writer.h>
|
#include <ripple/json/json_writer.h>
|
||||||
#include <boost/asio/connect.hpp>
|
#include <boost/asio/connect.hpp>
|
||||||
@@ -509,7 +510,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence)
|
|||||||
&startSequence,
|
&startSequence,
|
||||||
&writeConflict,
|
&writeConflict,
|
||||||
&transformQueue]() {
|
&transformQueue]() {
|
||||||
this_thread::set_name("ETL extract");
|
beast::setCurrentThreadName("rippled: ReportingETL extract");
|
||||||
uint32_t currentSequence = startSequence;
|
uint32_t currentSequence = startSequence;
|
||||||
|
|
||||||
// there are two stopping conditions here.
|
// there are two stopping conditions here.
|
||||||
@@ -561,7 +562,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence)
|
|||||||
&writeConflict,
|
&writeConflict,
|
||||||
&loadQueue,
|
&loadQueue,
|
||||||
&transformQueue]() {
|
&transformQueue]() {
|
||||||
this_thread::set_name("ETL transform");
|
beast::setCurrentThreadName("rippled: ReportingETL transform");
|
||||||
|
|
||||||
assert(parent);
|
assert(parent);
|
||||||
parent = std::make_shared<Ledger>(*parent, NetClock::time_point{});
|
parent = std::make_shared<Ledger>(*parent, NetClock::time_point{});
|
||||||
@@ -600,7 +601,7 @@ ReportingETL::runETLPipeline(uint32_t startSequence)
|
|||||||
&lastPublishedSequence,
|
&lastPublishedSequence,
|
||||||
&loadQueue,
|
&loadQueue,
|
||||||
&writeConflict]() {
|
&writeConflict]() {
|
||||||
this_thread::set_name("ETL load");
|
beast::setCurrentThreadName("rippled: ReportingETL load");
|
||||||
size_t totalTransactions = 0;
|
size_t totalTransactions = 0;
|
||||||
double totalTime = 0;
|
double totalTime = 0;
|
||||||
while (!writeConflict)
|
while (!writeConflict)
|
||||||
@@ -824,7 +825,7 @@ void
|
|||||||
ReportingETL::doWork()
|
ReportingETL::doWork()
|
||||||
{
|
{
|
||||||
worker_ = std::thread([this]() {
|
worker_ = std::thread([this]() {
|
||||||
this_thread::set_name("ETL worker");
|
beast::setCurrentThreadName("rippled: ReportingETL worker");
|
||||||
if (readOnly_)
|
if (readOnly_)
|
||||||
monitorReadOnly();
|
monitorReadOnly();
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
/*
|
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
|
||||||
Copyright (c) 2022 Ripple Labs Inc.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name(std::thread::native_handle_type t)
|
|
||||||
{
|
|
||||||
char buffer[64];
|
|
||||||
if (pthread_getname_np(t, buffer, sizeof(buffer)) != 0)
|
|
||||||
throw std::runtime_error("get_name failed\n");
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace this_thread {
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name()
|
|
||||||
{
|
|
||||||
return ripple::get_name(pthread_self());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_name(std::string s)
|
|
||||||
{
|
|
||||||
s.resize(15);
|
|
||||||
if (pthread_setname_np(s.data()) != 0)
|
|
||||||
throw std::runtime_error("this_thread::set_name failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace this_thread
|
|
||||||
|
|
||||||
#endif // __APPLE__
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name(std::thread::native_handle_type t)
|
|
||||||
{
|
|
||||||
char buffer[64];
|
|
||||||
if (pthread_getname_np(t, buffer, sizeof(buffer)) != 0)
|
|
||||||
throw std::runtime_error("get_name failed\n");
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace this_thread {
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name()
|
|
||||||
{
|
|
||||||
return ripple::get_name(pthread_self());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_name(std::string s)
|
|
||||||
{
|
|
||||||
s.resize(15);
|
|
||||||
if (pthread_setname_np(pthread_self(), s.data()) != 0)
|
|
||||||
throw std::runtime_error("this_thread::set_name failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace this_thread
|
|
||||||
|
|
||||||
#endif // __linux__
|
|
||||||
|
|
||||||
#ifdef _WIN64
|
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <processthreadsapi.h>
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name(std::thread::native_handle_type t)
|
|
||||||
{
|
|
||||||
wchar_t* unhandled_data{};
|
|
||||||
HRESULT r = GetThreadDescription(t, &unhandled_data);
|
|
||||||
std::unique_ptr<wchar_t, HLOCAL (*)(HLOCAL)> data{
|
|
||||||
unhandled_data, LocalFree};
|
|
||||||
if (FAILED(r))
|
|
||||||
throw std::runtime_error("get_name failed\n");
|
|
||||||
std::string s;
|
|
||||||
auto p = data.get();
|
|
||||||
while (*p)
|
|
||||||
s.push_back(static_cast<char>(*p++));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace this_thread {
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name()
|
|
||||||
{
|
|
||||||
return ripple::get_name(GetCurrentThread());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_name(std::string s)
|
|
||||||
{
|
|
||||||
assert(s.size() <= 15);
|
|
||||||
s.resize(15);
|
|
||||||
std::wstring ws;
|
|
||||||
for (auto c : s)
|
|
||||||
ws += c;
|
|
||||||
HRESULT r = SetThreadDescription(GetCurrentThread(), ws.data());
|
|
||||||
if (FAILED(r))
|
|
||||||
throw std::runtime_error("this_thread::set_name failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace this_thread
|
|
||||||
|
|
||||||
#endif // __WINDOWS__
|
|
||||||
|
|
||||||
} // namespace ripple
|
|
||||||
125
src/ripple/beast/core/CurrentThreadName.cpp
Normal file
125
src/ripple/beast/core/CurrentThreadName.cpp
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||||
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
Portions of this file are from JUCE.
|
||||||
|
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||||
|
Please visit http://www.juce.com
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
|
#include <boost/predef.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if BOOST_OS_WINDOWS
|
||||||
|
#include <process.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
namespace beast::detail {
|
||||||
|
|
||||||
|
inline void
|
||||||
|
setCurrentThreadNameImpl(std::string_view name)
|
||||||
|
{
|
||||||
|
#if DEBUG && BOOST_COMP_MSVC
|
||||||
|
// This technique is documented by Microsoft and works for all versions
|
||||||
|
// of Windows and Visual Studio provided that the process is being run
|
||||||
|
// under the Visual Studio debugger. For more details, see:
|
||||||
|
// https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code
|
||||||
|
|
||||||
|
#pragma pack(push, 8)
|
||||||
|
struct THREADNAME_INFO
|
||||||
|
{
|
||||||
|
DWORD dwType;
|
||||||
|
LPCSTR szName;
|
||||||
|
DWORD dwThreadID;
|
||||||
|
DWORD dwFlags;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
THREADNAME_INFO ni;
|
||||||
|
|
||||||
|
ni.dwType = 0x1000;
|
||||||
|
ni.szName = name.data();
|
||||||
|
ni.dwThreadID = GetCurrentThreadId();
|
||||||
|
ni.dwFlags = 0;
|
||||||
|
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 6320 6322)
|
||||||
|
__try
|
||||||
|
{
|
||||||
|
RaiseException(
|
||||||
|
0x406d1388, 0, sizeof(ni) / sizeof(ULONG_PTR), (ULONG_PTR*)&ni);
|
||||||
|
}
|
||||||
|
__except (EXCEPTION_CONTINUE_EXECUTION)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace beast::detail
|
||||||
|
#endif // BOOST_OS_WINDOWS
|
||||||
|
|
||||||
|
#if BOOST_OS_MACOS
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
namespace beast::detail {
|
||||||
|
|
||||||
|
inline void
|
||||||
|
setCurrentThreadNameImpl(std::string_view name)
|
||||||
|
{
|
||||||
|
pthread_setname_np(name.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace beast::detail
|
||||||
|
#endif // BOOST_OS_MACOS
|
||||||
|
|
||||||
|
#if BOOST_OS_LINUX
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
namespace beast::detail {
|
||||||
|
|
||||||
|
inline void
|
||||||
|
setCurrentThreadNameImpl(std::string_view name)
|
||||||
|
{
|
||||||
|
pthread_setname_np(pthread_self(), name.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace beast::detail
|
||||||
|
#endif // BOOST_OS_LINUX
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
thread_local std::string threadName;
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
std::string
|
||||||
|
getCurrentThreadName()
|
||||||
|
{
|
||||||
|
return detail::threadName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
setCurrentThreadName(std::string_view name)
|
||||||
|
{
|
||||||
|
detail::threadName = name;
|
||||||
|
detail::setCurrentThreadNameImpl(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace beast
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/*
|
/*
|
||||||
This file is part of rippled: https://github.com/ripple/rippled
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||||
Copyright (c) 2022 Ripple Labs Inc.
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
Portions of this file are from JUCE.
|
||||||
|
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||||
|
Please visit http://www.juce.com
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -17,34 +21,31 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#ifndef RIPPLE_BASICS_THREADUTILITIES_H_INCLUDED
|
#ifndef BEAST_CORE_CURRENT_THREAD_NAME_H_INCLUDED
|
||||||
#define RIPPLE_BASICS_THREADUTILITIES_H_INCLUDED
|
#define BEAST_CORE_CURRENT_THREAD_NAME_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <string_view>
|
||||||
|
|
||||||
namespace ripple {
|
namespace beast {
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name(std::thread::native_handle_type t);
|
|
||||||
|
|
||||||
template <class Thread>
|
|
||||||
inline auto
|
|
||||||
get_name(Thread& t) -> decltype(t.native_handle(), t.join(), std::string{})
|
|
||||||
{
|
|
||||||
return get_name(t.native_handle());
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace this_thread {
|
|
||||||
|
|
||||||
std::string
|
|
||||||
get_name();
|
|
||||||
|
|
||||||
|
/** Changes the name of the caller thread.
|
||||||
|
Different OSes may place different length or content limits on this name.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
set_name(std::string s);
|
setCurrentThreadName(std::string_view newThreadName);
|
||||||
|
|
||||||
} // namespace this_thread
|
/** Returns the name of the caller thread.
|
||||||
|
|
||||||
} // namespace ripple
|
The name returned is the name as set by a call to setCurrentThreadName().
|
||||||
|
If the thread name is set by an external force, then that name change
|
||||||
|
will not be reported.
|
||||||
|
|
||||||
|
If no name has ever been set, then the empty string is returned.
|
||||||
|
*/
|
||||||
|
std::string
|
||||||
|
getCurrentThreadName();
|
||||||
|
|
||||||
|
} // namespace beast
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/core/Job.h>
|
#include <ripple/core/Job.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ Job::queue_time() const
|
|||||||
void
|
void
|
||||||
Job::doJob()
|
Job::doJob()
|
||||||
{
|
{
|
||||||
this_thread::set_name("doJob: " + mName);
|
beast::setCurrentThreadName("doJob: " + mName);
|
||||||
m_loadEvent->start();
|
m_loadEvent->start();
|
||||||
m_loadEvent->setName(mName);
|
m_loadEvent->setName(mName);
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/basics/Log.h>
|
#include <ripple/basics/Log.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/random.h>
|
#include <ripple/basics/random.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/core/impl/SNTPClock.h>
|
#include <ripple/core/impl/SNTPClock.h>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -193,7 +193,7 @@ public:
|
|||||||
void
|
void
|
||||||
doRun()
|
doRun()
|
||||||
{
|
{
|
||||||
this_thread::set_name("SNTPClock");
|
beast::setCurrentThreadName("rippled: SNTPClock");
|
||||||
io_service_.run();
|
io_service_.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/basics/PerfLog.h>
|
#include <ripple/basics/PerfLog.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/core/impl/Workers.h>
|
#include <ripple/core/impl/Workers.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ Workers::Worker::run()
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
// Put the name back in case the callback changed it
|
// Put the name back in case the callback changed it
|
||||||
this_thread::set_name(threadName_);
|
beast::setCurrentThreadName(threadName_);
|
||||||
|
|
||||||
// Acquire a task or "internal task."
|
// Acquire a task or "internal task."
|
||||||
//
|
//
|
||||||
@@ -259,7 +259,7 @@ Workers::Worker::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set inactive thread name.
|
// Set inactive thread name.
|
||||||
this_thread::set_name("(" + threadName_ + ")");
|
beast::setCurrentThreadName("(" + threadName_ + ")");
|
||||||
|
|
||||||
// [1] We will be here when the paused list is popped
|
// [1] We will be here when the paused list is popped
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
#if RIPPLE_ROCKSDB_AVAILABLE
|
#if RIPPLE_ROCKSDB_AVAILABLE
|
||||||
|
|
||||||
#include <ripple/basics/ByteUtilities.h>
|
#include <ripple/basics/ByteUtilities.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/contract.h>
|
#include <ripple/basics/contract.h>
|
||||||
#include <ripple/basics/safe_cast.h>
|
#include <ripple/basics/safe_cast.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/core/Config.h> // VFALCO Bad dependency
|
#include <ripple/core/Config.h> // VFALCO Bad dependency
|
||||||
#include <ripple/nodestore/Factory.h>
|
#include <ripple/nodestore/Factory.h>
|
||||||
#include <ripple/nodestore/Manager.h>
|
#include <ripple/nodestore/Manager.h>
|
||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
std::size_t const id(++n);
|
std::size_t const id(++n);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "rocksdb #" << id;
|
ss << "rocksdb #" << id;
|
||||||
this_thread::set_name(ss.str());
|
beast::setCurrentThreadName(ss.str());
|
||||||
|
|
||||||
(*f)(a);
|
(*f)(a);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/app/ledger/Ledger.h>
|
#include <ripple/app/ledger/Ledger.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/chrono.h>
|
#include <ripple/basics/chrono.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/json/json_value.h>
|
#include <ripple/json/json_value.h>
|
||||||
#include <ripple/nodestore/Database.h>
|
#include <ripple/nodestore/Database.h>
|
||||||
#include <ripple/protocol/HashPrefix.h>
|
#include <ripple/protocol/HashPrefix.h>
|
||||||
@@ -63,7 +63,8 @@ Database::Database(
|
|||||||
[this](int i) {
|
[this](int i) {
|
||||||
runningThreads_++;
|
runningThreads_++;
|
||||||
|
|
||||||
this_thread::set_name("prefetch " + std::to_string(i));
|
beast::setCurrentThreadName(
|
||||||
|
"db prefetch #" + std::to_string(i));
|
||||||
|
|
||||||
decltype(read_) read;
|
decltype(read_) read;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#include <ripple/perflog/impl/PerfLogImp.h>
|
#include <ripple/perflog/impl/PerfLogImp.h>
|
||||||
|
|
||||||
#include <ripple/basics/BasicConfig.h>
|
#include <ripple/basics/BasicConfig.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/beast/utility/Journal.h>
|
#include <ripple/beast/utility/Journal.h>
|
||||||
#include <ripple/core/JobTypes.h>
|
#include <ripple/core/JobTypes.h>
|
||||||
#include <ripple/json/json_writer.h>
|
#include <ripple/json/json_writer.h>
|
||||||
@@ -255,7 +255,7 @@ PerfLogImp::openLog()
|
|||||||
void
|
void
|
||||||
PerfLogImp::run()
|
PerfLogImp::run()
|
||||||
{
|
{
|
||||||
this_thread::set_name("perflog");
|
beast::setCurrentThreadName("perflog");
|
||||||
lastLog_ = system_clock::now();
|
lastLog_ = system_clock::now();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/basics/Log.h>
|
#include <ripple/basics/Log.h>
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/chrono.h>
|
#include <ripple/basics/chrono.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/beast/net/IPAddressConversion.h>
|
#include <ripple/beast/net/IPAddressConversion.h>
|
||||||
#include <ripple/resource/ResourceManager.h>
|
#include <ripple/resource/ResourceManager.h>
|
||||||
#include <ripple/resource/impl/Logic.h>
|
#include <ripple/resource/impl/Logic.h>
|
||||||
@@ -149,7 +149,7 @@ private:
|
|||||||
void
|
void
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
this_thread::set_name("Resrc::Manager");
|
beast::setCurrentThreadName("Resource::Manager");
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
logic_.periodicActivity();
|
logic_.periodicActivity();
|
||||||
|
|||||||
@@ -17,13 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
class ThreadName_test : public beast::unit_test::suite
|
class CurrentThreadName_test : public beast::unit_test::suite
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static void
|
static void
|
||||||
@@ -32,19 +34,26 @@ private:
|
|||||||
std::atomic<bool>* stop,
|
std::atomic<bool>* stop,
|
||||||
std::atomic<int>* state)
|
std::atomic<int>* state)
|
||||||
{
|
{
|
||||||
|
// Verify that upon creation a thread has no name.
|
||||||
|
auto const initialThreadName = beast::getCurrentThreadName();
|
||||||
|
|
||||||
// Set the new name.
|
// Set the new name.
|
||||||
this_thread::set_name(myName);
|
beast::setCurrentThreadName(myName);
|
||||||
|
|
||||||
// Indicate to caller that the name is set.
|
// Indicate to caller that the name is set.
|
||||||
*state = 1;
|
*state = 1;
|
||||||
|
|
||||||
|
// If there is an initial thread name then we failed.
|
||||||
|
if (!initialThreadName.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
// Wait until all threads have their names.
|
// Wait until all threads have their names.
|
||||||
while (!*stop)
|
while (!*stop)
|
||||||
;
|
;
|
||||||
|
|
||||||
// Make sure the thread name that we set before is still there
|
// Make sure the thread name that we set before is still there
|
||||||
// (not overwritten by, for instance, another thread).
|
// (not overwritten by, for instance, another thread).
|
||||||
if (this_thread::get_name() == myName)
|
if (beast::getCurrentThreadName() == myName)
|
||||||
*state = 2;
|
*state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +86,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(ThreadName, basics, ripple);
|
BEAST_DEFINE_TESTSUITE(CurrentThreadName, core, beast);
|
||||||
|
|
||||||
} // namespace test
|
} // namespace test
|
||||||
} // namespace ripple
|
} // namespace ripple
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <ripple/basics/ThreadUtilities.h>
|
|
||||||
#include <ripple/basics/make_SSLContext.h>
|
#include <ripple/basics/make_SSLContext.h>
|
||||||
|
#include <ripple/beast/core/CurrentThreadName.h>
|
||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
#include <test/jtx/envconfig.h>
|
#include <test/jtx/envconfig.h>
|
||||||
|
|
||||||
@@ -630,7 +630,7 @@ public:
|
|||||||
short_read_test()
|
short_read_test()
|
||||||
: work_(io_context_.get_executor())
|
: work_(io_context_.get_executor())
|
||||||
, thread_(std::thread([this]() {
|
, thread_(std::thread([this]() {
|
||||||
this_thread::set_name("io_context");
|
beast::setCurrentThreadName("io_context");
|
||||||
this->io_context_.run();
|
this->io_context_.run();
|
||||||
}))
|
}))
|
||||||
, context_(make_SSLContext(""))
|
, context_(make_SSLContext(""))
|
||||||
|
|||||||
Reference in New Issue
Block a user