From 2377cb05b6c9dc8d9ec9b16171895dae249c76b1 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Mon, 14 Aug 2023 17:51:41 -0500 Subject: [PATCH] Add thread names for easier debugging --- libfuse/lib/bounded_thread_pool.hpp | 26 ++++++++++++++++---------- libfuse/lib/fuse.c | 2 ++ libfuse/lib/fuse_loop.cpp | 6 ++++-- src/fuse_readdir_cor.cpp | 2 +- src/fuse_readdir_cosr.cpp | 2 +- src/unbounded_thread_pool.hpp | 29 ++++++++++++++++++++++------- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/libfuse/lib/bounded_thread_pool.hpp b/libfuse/lib/bounded_thread_pool.hpp index 5a31bfcc..707fa1d8 100644 --- a/libfuse/lib/bounded_thread_pool.hpp +++ b/libfuse/lib/bounded_thread_pool.hpp @@ -3,17 +3,17 @@ #include "bounded_queue.hpp" #include "make_unique.hpp" -#include - -#include #include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include #include +#include +#include class BoundedThreadPool @@ -25,8 +25,9 @@ private: public: explicit - BoundedThreadPool(const std::size_t thread_count_ = std::thread::hardware_concurrency(), - const std::size_t queue_depth_ = 1) + BoundedThreadPool(std::size_t const thread_count_ = std::thread::hardware_concurrency(), + std::size_t const queue_depth_ = 1, + std::string const name_ = {}) : _queues(), _count(thread_count_) { @@ -61,6 +62,11 @@ public: _threads.reserve(thread_count_); for(std::size_t i = 0; i < thread_count_; ++i) _threads.emplace_back(worker, i); + if(!name_.empty()) + { + for(auto &t : _threads) + pthread_setname_np(t.native_handle(),name_.c_str()); + } pthread_sigmask(SIG_SETMASK,&oldset,NULL); } diff --git a/libfuse/lib/fuse.c b/libfuse/lib/fuse.c index e2b9e3ba..2ddd1674 100644 --- a/libfuse/lib/fuse.c +++ b/libfuse/lib/fuse.c @@ -3948,6 +3948,8 @@ fuse_maintenance_loop(void *fuse_) int sleep_time; struct fuse *f = (struct fuse*)fuse_; + pthread_setname_np(pthread_self(),"fuse.maint"); + loops = 0; sleep_time = 60; while(1) diff --git a/libfuse/lib/fuse_loop.cpp b/libfuse/lib/fuse_loop.cpp index 2b5c0b12..d4356569 100644 --- a/libfuse/lib/fuse_loop.cpp +++ b/libfuse/lib/fuse_loop.cpp @@ -482,9 +482,11 @@ fuse_session_loop_mt(struct fuse_session *se_, &process_thread_queue_depth); if(process_thread_count > 0) - process_tp = std::make_shared(process_thread_count,process_thread_queue_depth); + process_tp = std::make_shared(process_thread_count, + process_thread_queue_depth, + "fuse.process"); - read_tp = std::make_unique(read_thread_count); + read_tp = std::make_unique(read_thread_count,1,"fuse.read"); if(process_tp) { for(auto i = 0; i < read_thread_count; i++) diff --git a/src/fuse_readdir_cor.cpp b/src/fuse_readdir_cor.cpp index 9036cd4a..4e82fcda 100644 --- a/src/fuse_readdir_cor.cpp +++ b/src/fuse_readdir_cor.cpp @@ -32,7 +32,7 @@ FUSE::ReadDirCOR::ReadDirCOR(unsigned concurrency_) - : _tp(concurrency_) + : _tp(concurrency_,"readdir.cor") { } diff --git a/src/fuse_readdir_cosr.cpp b/src/fuse_readdir_cosr.cpp index f0750f56..6edbf7b0 100644 --- a/src/fuse_readdir_cosr.cpp +++ b/src/fuse_readdir_cosr.cpp @@ -34,7 +34,7 @@ FUSE::ReadDirCOSR::ReadDirCOSR(unsigned concurrency_) - : _tp(concurrency_) + : _tp(concurrency_,"readdir.cosr") { } diff --git a/src/unbounded_thread_pool.hpp b/src/unbounded_thread_pool.hpp index 4905853c..6f02e1b3 100644 --- a/src/unbounded_thread_pool.hpp +++ b/src/unbounded_thread_pool.hpp @@ -2,22 +2,24 @@ #include "unbounded_queue.hpp" -#include #include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include #include +#include +#include class ThreadPool { public: explicit - ThreadPool(const std::size_t thread_count_ = std::thread::hardware_concurrency()) + ThreadPool(std::size_t const thread_count_ = std::thread::hardware_concurrency(), + std::string const name_ = {}) : _queues(thread_count_), _count(thread_count_) { @@ -40,9 +42,22 @@ public: } }; + sigset_t oldset; + sigset_t newset; + + sigfillset(&newset); + pthread_sigmask(SIG_BLOCK,&newset,&oldset); + _threads.reserve(thread_count_); for(std::size_t i = 0; i < thread_count_; ++i) _threads.emplace_back(worker, i); + if(!name_.empty()) + { + for(auto &t : _threads) + pthread_setname_np(t.native_handle(),name_.c_str()); + } + + pthread_sigmask(SIG_SETMASK,&oldset,NULL); } ~ThreadPool()