From 83561c9cb314a677172c8038a25a3265f4991ba8 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 3 Jan 2017 10:21:00 +0100 Subject: [PATCH 1/3] Trigger metrics UI refresh on new messages --- src/metrics.cpp | 15 +++++++++++++-- src/metrics.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index 053538660..2803a3130 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,6 +61,13 @@ 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) @@ -85,6 +93,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) @@ -333,8 +344,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(); From e698459ec882a77dab8257e17a95f6e2630e5217 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 3 Jan 2017 10:26:49 +0100 Subject: [PATCH 2/3] Strip out the SECURE flag in metrics UI so message style is detected --- src/metrics.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/metrics.cpp b/src/metrics.cpp index 2803a3130..df0016113 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -72,6 +72,9 @@ 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) { From b6e439b2610b7d78d58ed566473f8c291bd0384c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 5 Jan 2017 08:38:35 +0100 Subject: [PATCH 3/3] Handle newlines in UI messages --- src/metrics.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index df0016113..9f3795e00 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -261,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;