diff --git a/src/metrics.cpp b/src/metrics.cpp index 053538660..9f3795e00 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -20,6 +20,7 @@ CCriticalSection cs_metrics; boost::synchronized_value nNodeStartTime; +boost::synchronized_value nNextRefresh; AtomicCounter transactionsValidated; AtomicCounter ehSolverRuns; AtomicCounter solutionTargetChecks; @@ -60,10 +61,20 @@ double GetLocalSolPS() return GetLocalSolPS_INTERNAL(GetUptime()); } +void TriggerRefresh() +{ + *nNextRefresh = GetTime(); + // Ensure that the refresh has started before we return + MilliSleep(200); +} + static bool metrics_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) { + // The SECURE flag has no effect in the metrics UI. + style &= ~CClientUIInterface::SECURE; + std::string strCaption; // Check for usage of predefined caption switch (style) { @@ -85,6 +96,9 @@ static bool metrics_ThreadSafeMessageBox(const std::string& message, if (u->size() > 5) { u->pop_back(); } + + TriggerRefresh(); + return false; } static void metrics_InitMessage(const std::string& message) @@ -247,8 +261,21 @@ int printMessageBox(size_t cols) std::cout << _("Messages:") << std::endl; for (auto it = u->cbegin(); it != u->cend(); ++it) { std::cout << *it << std::endl; - // Handle wrapped lines - lines += (it->size() / cols); + // Handle newlines and wrapped lines + size_t i = 0; + size_t j = 0; + while (j < it->size()) { + i = it->find('\n', j); + if (i == std::string::npos) { + i = it->size(); + } else { + // Newline + lines++; + } + // Wrapped lines + lines += ((i-j) / cols); + j = i + 1; + } } std::cout << std::endl; return lines; @@ -333,8 +360,8 @@ void ThreadShowMetricsScreen() std::cout << "----------------------------------------" << std::endl; } - int64_t nWaitEnd = GetTime() + nRefresh; - while (GetTime() < nWaitEnd) { + *nNextRefresh = GetTime() + nRefresh; + while (GetTime() < *nNextRefresh) { boost::this_thread::interruption_point(); MilliSleep(200); } diff --git a/src/metrics.h b/src/metrics.h index 2851178b6..57264a7b5 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -34,6 +34,8 @@ void TrackMinedBlock(uint256 hash); void MarkStartTime(); double GetLocalSolPS(); +void TriggerRefresh(); + void ConnectMetricsScreen(); void ThreadShowMetricsScreen();