From fcb9e25fb1e4ceb68f70d1c940b98bacd9255832 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 25 Aug 2021 11:31:35 +0200 Subject: [PATCH] Print background jobs in status --- src/console_commands.cpp | 1 + src/util.cpp | 23 +++++++++++++++++++++++ src/util.h | 1 + 3 files changed, 25 insertions(+) diff --git a/src/console_commands.cpp b/src/console_commands.cpp index 71b1244..45c648d 100644 --- a/src/console_commands.cpp +++ b/src/console_commands.cpp @@ -100,6 +100,7 @@ static int do_status(p2pool *m_pool, const char * /* args */) if (m_pool->p2p_server()) { m_pool->p2p_server()->print_status(); } + bkg_jobs_tracker.print_status(); return 0; } diff --git a/src/util.cpp b/src/util.cpp index f372ab0..011bd76 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -183,6 +183,24 @@ struct BackgroundJobTracker::Impl } while (1); } + void print_status() + { + MutexLock lock(m_lock); + + if (m_jobs.empty()) { + LOGINFO(0, "no background jobs running"); + return; + } + + char buf[log::Stream::BUF_SIZE + 1]; + log::Stream s(buf); + for (const auto& job : m_jobs) { + s << '\n' << job.first << " (" << job.second << ')'; + } + + LOGINFO(0, "background jobs running:" << log::const_buf(buf, s.m_pos)); + } + uv_mutex_t m_lock; std::map m_jobs; }; @@ -211,6 +229,11 @@ void BackgroundJobTracker::wait() m_impl->wait(); } +void BackgroundJobTracker::print_status() +{ + m_impl->print_status(); +} + BackgroundJobTracker bkg_jobs_tracker; } // namespace p2pool diff --git a/src/util.h b/src/util.h index fe0f96a..bf807c5 100644 --- a/src/util.h +++ b/src/util.h @@ -107,6 +107,7 @@ public: void start(const char* name); void stop(const char* name); void wait(); + void print_status(); private: struct Impl;