Browse Source

Auto merge of #1972 - str4d:1950-ensure-messages-are-rendered, r=ebfull

Ensure messages are rendered in the metrics UI

Part of #1950.
pull/4/head
zkbot 8 years ago
parent
commit
2a18730417
  1. 35
      src/metrics.cpp
  2. 2
      src/metrics.h

35
src/metrics.cpp

@ -20,6 +20,7 @@
CCriticalSection cs_metrics;
boost::synchronized_value<int64_t> nNodeStartTime;
boost::synchronized_value<int64_t> 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);
}

2
src/metrics.h

@ -34,6 +34,8 @@ void TrackMinedBlock(uint256 hash);
void MarkStartTime();
double GetLocalSolPS();
void TriggerRefresh();
void ConnectMetricsScreen();
void ThreadShowMetricsScreen();

Loading…
Cancel
Save