|
17 | 17 | #include <algorithm> |
18 | 18 | #include <limits> |
19 | 19 |
|
| 20 | +using interfaces::MemoryLoad; |
| 21 | + |
20 | 22 | // Allow a few seconds for clients to submit a block or to request transactions |
21 | 23 | constexpr size_t STALE_TEMPLATE_GRACE_PERIOD{10}; |
22 | 24 |
|
@@ -110,6 +112,8 @@ bool Sv2TemplateProvider::Start(const Sv2TemplateProviderOptions& options) |
110 | 112 | } |
111 | 113 |
|
112 | 114 | m_thread_sv2_handler = std::thread(&util::TraceThread, "sv2", [this] { ThreadSv2Handler(); }); |
| 115 | + m_thread_memory_handler = std::thread(&util::TraceThread, "memory", [this] { ThreadMemoryHandler(); }); |
| 116 | + |
113 | 117 | return true; |
114 | 118 | } |
115 | 119 |
|
@@ -154,6 +158,9 @@ void Sv2TemplateProvider::StopThreads() |
154 | 158 | if (m_thread_sv2_handler.joinable()) { |
155 | 159 | m_thread_sv2_handler.join(); |
156 | 160 | } |
| 161 | + if (m_thread_memory_handler.joinable()) { |
| 162 | + m_thread_memory_handler.join(); |
| 163 | + } |
157 | 164 | } |
158 | 165 |
|
159 | 166 | class Timer { |
@@ -249,6 +256,26 @@ void Sv2TemplateProvider::ThreadSv2Handler() |
249 | 256 |
|
250 | 257 | } |
251 | 258 |
|
| 259 | +void Sv2TemplateProvider::ThreadMemoryHandler() |
| 260 | +{ |
| 261 | + size_t seconds{0}; |
| 262 | + while (!m_flag_interrupt_sv2) { |
| 263 | + std::this_thread::sleep_for(1000ms); |
| 264 | + if (++seconds % 60 != 0) continue; |
| 265 | + if (m_mining.isInitialBlockDownload()) continue; |
| 266 | + try { |
| 267 | + MemoryLoad memory_load{m_mining.getMemoryLoad()}; |
| 268 | + const double usage_mib{static_cast<double>(memory_load.usage) / (1024.0 * 1024.0)}; |
| 269 | + const std::string usage_mib_str{strprintf("%.3f", usage_mib)}; |
| 270 | + LogTrace(BCLog::SV2, "Template memory footprint %s MiB", usage_mib_str); |
| 271 | + } catch (const ipc::Exception& e) { |
| 272 | + LogTrace(BCLog::SV2, "getMemoryLoad() not implemented on the node"); |
| 273 | + // Nothing to do for this thread |
| 274 | + break; |
| 275 | + } |
| 276 | + } |
| 277 | +} |
| 278 | + |
252 | 279 | void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id) |
253 | 280 | { |
254 | 281 | try { |
|
0 commit comments