Auto merge of #4545 - str4d:metrics-ibd-progress-bar, r=str4d
metrics: Add a progress bar when in Initial Block Download mode The progress bar shows both headers (in green) and blocks (in white / inverse of background colour). It is only printed for TTY output. Additionally, the "not mining" message is no longer shown on mainnet, as the built-in CPU miner is not effective at the current network difficulty.
This commit is contained in:
commit
7275bc7f3f
|
@ -14,6 +14,7 @@
|
||||||
#include "utilmoneystr.h"
|
#include "utilmoneystr.h"
|
||||||
#include "utilstrencodings.h"
|
#include "utilstrencodings.h"
|
||||||
|
|
||||||
|
#include <boost/range/irange.hpp>
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#include <boost/thread/synchronized_value.hpp>
|
#include <boost/thread/synchronized_value.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -265,7 +266,7 @@ boost::optional<int64_t> SecondsLeftToNextEpoch(const Consensus::Params& params,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int printStats(bool mining)
|
int printStats(bool isScreen, bool mining)
|
||||||
{
|
{
|
||||||
// Number of lines that are always displayed
|
// Number of lines that are always displayed
|
||||||
int lines = 5;
|
int lines = 5;
|
||||||
|
@ -302,6 +303,27 @@ int printStats(bool mining)
|
||||||
netheight = 1;
|
netheight = 1;
|
||||||
int downloadPercent = height * 100 / netheight;
|
int downloadPercent = height * 100 / netheight;
|
||||||
std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl;
|
std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl;
|
||||||
|
|
||||||
|
if (isScreen) {
|
||||||
|
// Draw 50-character progress bar, which will fit into a 79-character line.
|
||||||
|
int blockChars = downloadPercent / 2;
|
||||||
|
int headerChars = (nHeaders * 50) / netheight;
|
||||||
|
// Start with background colour reversed for "full" bar.
|
||||||
|
std::cout << " | [[7m";
|
||||||
|
for (auto i : boost::irange(0, 50)) {
|
||||||
|
if (i == headerChars) {
|
||||||
|
// Switch to normal background colour for "empty" bar.
|
||||||
|
std::cout << "[0m";
|
||||||
|
} else if (i == blockChars) {
|
||||||
|
// Switch to distinct colour for "headers" bar.
|
||||||
|
std::cout << "[0;43m";
|
||||||
|
}
|
||||||
|
std::cout << " ";
|
||||||
|
}
|
||||||
|
// Ensure that colour is reset after the progress bar is printed.
|
||||||
|
std::cout << "[0m]" << std::endl;
|
||||||
|
lines++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cout << " " << _("Block height") << " | " << height << std::endl;
|
std::cout << " " << _("Block height") << " | " << height << std::endl;
|
||||||
|
@ -356,7 +378,7 @@ int printMiningStatus(bool mining)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines++;
|
lines++;
|
||||||
} else {
|
} else if (Params().NetworkIDString() != "main") {
|
||||||
std::cout << _("You are currently not mining.") << std::endl;
|
std::cout << _("You are currently not mining.") << std::endl;
|
||||||
std::cout << _("To enable mining, add 'gen=1' to your zcash.conf and restart.") << std::endl;
|
std::cout << _("To enable mining, add 'gen=1' to your zcash.conf and restart.") << std::endl;
|
||||||
lines += 2;
|
lines += 2;
|
||||||
|
@ -584,7 +606,7 @@ void ThreadShowMetricsScreen()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
lines += printStats(mining);
|
lines += printStats(isScreen, mining);
|
||||||
lines += printMiningStatus(mining);
|
lines += printMiningStatus(mining);
|
||||||
}
|
}
|
||||||
lines += printMetrics(cols, mining);
|
lines += printMetrics(cols, mining);
|
||||||
|
|
Loading…
Reference in New Issue