Merge pull request #5959 from str4d/improve-thread-names

Improve thread names
This commit is contained in:
str4d 2022-05-14 02:27:24 +01:00 committed by GitHub
commit 202203a3fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 50 additions and 9 deletions

1
Cargo.lock generated
View File

@ -982,6 +982,7 @@ dependencies = [
"orchard",
"rand 0.8.5",
"rand_core 0.6.3",
"rayon",
"secp256k1",
"secrecy",
"subtle",

View File

@ -57,6 +57,9 @@ zcash_proofs = "0.6"
ed25519-zebra = "3"
zeroize = "1.4.2"
# Rust threading
rayon = "1.5"
# Metrics
ipnet = "2"
metrics = "0.17"

View File

@ -3,6 +3,7 @@
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
#include "asyncrpcqueue.h"
#include "util.h"
static std::atomic<size_t> workerCounter(0);
@ -26,6 +27,8 @@ AsyncRPCQueue::~AsyncRPCQueue() {
* A worker will execute this method on a new thread
*/
void AsyncRPCQueue::run(size_t workerId) {
std::string s = strprintf("zc-asyncrpc-%s", workerId);
RenameThread(s.c_str());
while (true) {
AsyncRPCOperationId key;

View File

@ -43,6 +43,10 @@ static bool fDaemon;
void WaitForShutdown(boost::thread_group* threadGroup)
{
// This is the main process thread, but after this point, all we do here is wait for
// shutdown, and then shut down the node.
RenameThread("zc-wait-to-stop");
bool fShutdown = ShutdownRequested();
// Tell the main threads to shutdown.
while (!fShutdown)

View File

@ -289,7 +289,7 @@ static void http_reject_request_cb(struct evhttp_request* req, void*)
/** Event dispatcher thread */
static bool ThreadHTTP(struct event_base* base, struct evhttp* http)
{
RenameThread("zcash-http");
RenameThread("zc-http-server");
LogPrint("http", "Entering http event loop\n");
event_base_dispatch(base);
// Event loop will be interrupted by InterruptHTTPServer()
@ -339,7 +339,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
/** Simple wrapper to set thread name and run work queue */
static void HTTPWorkQueueRun(WorkQueue<HTTPClosure>* queue)
{
RenameThread("zcash-httpworker");
RenameThread("zc-http-worker");
queue->Run();
}

View File

@ -66,6 +66,7 @@
#include "zmq/zmqnotificationinterface.h"
#endif
#include <rust/init.h>
#include <rust/metrics.h>
#include "librustzcash.h"
@ -1071,6 +1072,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
std::set_new_handler(new_handler_terminate);
// Set up global Rayon threadpool.
zcashd_init_rayon_threadpool();
// ********************************************************* Step 2: parameter interactions
const CChainParams& chainparams = Params();
@ -1438,7 +1442,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
!fPrintToConsole && !GetBoolArg("-daemon", false)) {
// Start the persistent metrics interface
ConnectMetricsScreen();
threadGroup.create_thread(&ThreadShowMetricsScreen);
threadGroup.create_thread(
boost::bind(&TraceThread<void (*)()>, "metrics-ui", &ThreadShowMetricsScreen)
);
}
// Initialize Zcash circuit parameters

View File

@ -3029,7 +3029,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
static CCheckQueue<CScriptCheck> scriptcheckqueue(128);
void ThreadScriptCheck() {
RenameThread("zcash-scriptch");
RenameThread("zc-scriptcheck");
scriptcheckqueue.Thread();
}

View File

@ -601,9 +601,6 @@ bool enableVTMode()
void ThreadShowMetricsScreen()
{
// Make this thread recognisable as the metrics screen thread
RenameThread("zcash-metrics-screen");
// Determine whether we should render a persistent UI or rolling metrics
bool isTTY = isatty(STDOUT_FILENO);
bool isScreen = GetBoolArg("-metricsui", isTTY);

View File

@ -0,0 +1,19 @@
// Copyright (c) 2022 The Zcash developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
#ifndef ZCASH_RUST_INCLUDE_RUST_INIT_H
#define ZCASH_RUST_INCLUDE_RUST_INIT_H
#ifdef __cplusplus
extern "C" {
#endif
/// Initializes the global Rayon threadpool.
void zcashd_init_rayon_threadpool();
#ifdef __cplusplus
}
#endif
#endif // ZCASH_RUST_INCLUDE_RUST_INIT_H

7
src/rust/src/init_ffi.rs Normal file
View File

@ -0,0 +1,7 @@
#[no_mangle]
pub extern "C" fn zcashd_init_rayon_threadpool() {
rayon::ThreadPoolBuilder::new()
.thread_name(|i| format!("zc-rayon-{}", i))
.build_global()
.expect("Only initialized once");
}

View File

@ -77,6 +77,7 @@ mod builder_ffi;
mod history_ffi;
mod incremental_merkle_tree;
mod incremental_merkle_tree_ffi;
mod init_ffi;
mod orchard_ffi;
mod orchard_keys_ffi;
mod transaction_ffi;

View File

@ -192,7 +192,7 @@ void RenameThread(const char* name);
*/
template <typename Callable> void TraceThread(const char* name, Callable func)
{
std::string s = strprintf("zcash-%s", name);
std::string s = strprintf("zc-%s", name);
RenameThread(s.c_str());
try
{

View File

@ -1134,7 +1134,7 @@ DBErrors CWalletDB::ZapWalletTx(CWallet* pwallet, vector<CWalletTx>& vWtx)
void ThreadFlushWalletDB(const string& strFile)
{
// Make this thread recognisable as the wallet flushing thread
RenameThread("zcash-wallet");
RenameThread("zc-wallet-flush");
static bool fOneThread;
if (fOneThread)