From 978c577412b42a116dccfb1d5e315cd59e570c4d Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 17 Dec 2018 04:02:43 -0500 Subject: [PATCH] status: report number of active worker threads in status output This is especially useful when dynamic load management allocates more worker threads than active tasks, so the extra threads are effectively invisible. Signed-off-by: Zygo Blaxell --- include/crucible/task.h | 3 +++ lib/task.cc | 8 ++++++++ src/bees-context.cc | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/crucible/task.h b/include/crucible/task.h index 9279490..3f806a1 100644 --- a/include/crucible/task.h +++ b/include/crucible/task.h @@ -88,6 +88,9 @@ namespace crucible { /// Gets the current number of queued Tasks static size_t get_queue_count(); + /// Gets the current number of active workers + static size_t get_thread_count(); + /// Drop the current queue and discard new Tasks without /// running them. Currently executing tasks are not /// affected (use set_thread_count(0) to wait for those diff --git a/lib/task.cc b/lib/task.cc index cd37d4f..5c033de 100644 --- a/lib/task.cc +++ b/lib/task.cc @@ -128,6 +128,7 @@ namespace crucible { static void push_back(shared_ptr task); static void push_front(shared_ptr task); size_t get_queue_count(); + size_t get_thread_count(); }; class TaskConsumer : public enable_shared_from_this { @@ -324,6 +325,13 @@ namespace crucible { return s_tms->m_queue.size(); } + size_t + TaskMaster::get_thread_count() + { + unique_lock lock(s_tms->m_mutex); + return s_tms->m_threads.size(); + } + ostream & TaskMaster::print_queue(ostream &os) { diff --git a/src/bees-context.cc b/src/bees-context.cc index 85418ab..554dc00 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -99,7 +99,7 @@ BeesContext::dump_status() ofs << "RATES:\n"; ofs << "\t" << avg_rates << "\n"; - ofs << "THREADS (work queue " << TaskMaster::get_queue_count() << " tasks):\n"; + ofs << "THREADS (work queue " << TaskMaster::get_queue_count() << " tasks, " << TaskMaster::get_thread_count() << " workers):\n"; for (auto t : BeesNote::get_status()) { ofs << "\ttid " << t.first << ": " << t.second << "\n"; }