Metrics screen: display hash rates using SI prefixes rather than as powers of 2.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2020-07-17 13:56:33 +01:00
parent 976dce7696
commit 460a601e9b
2 changed files with 22 additions and 7 deletions

View File

@ -256,6 +256,24 @@ std::string DisplaySize(size_t value)
return strprintf(_("%.2f TiB"), value / coef);
}
std::string DisplayHashRate(double value)
{
double coef = 1.0;
if (value < 1000.0 * coef)
return strprintf(_("%.3f Sol/s"), value);
coef *= 1000.0;
if (value < 1000.0 * coef)
return strprintf(_("%.3f kSol/s"), value / coef);
coef *= 1000.0;
if (value < 1000.0 * coef)
return strprintf(_("%.3f MSol/s"), value / coef);
coef *= 1000.0;
if (value < 1000.0 * coef)
return strprintf(_("%.3f GSol/s"), value / coef);
coef *= 1000.0;
return strprintf(_("%.3f TSol/s"), value / coef);
}
boost::optional<int64_t> SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight)
{
auto nextHeight = NextActivationHeight(currentHeight, params);
@ -276,7 +294,6 @@ int printStats(bool isScreen, bool mining)
int64_t currentHeadersTime;
size_t connections;
int64_t netsolps;
double netsolpsLog = 1.0;
const Consensus::Params& params = Params().GetConsensus();
{
LOCK2(cs_main, cs_vNodes);
@ -285,12 +302,8 @@ int printStats(bool isScreen, bool mining)
currentHeadersTime = pindexBestHeader ? pindexBestHeader->nTime : 0;
connections = vNodes.size();
netsolps = GetNetworkHashPS(120, -1);
netsolpsLog = std::log2(netsolps);
}
auto localsolps = GetLocalSolPS();
double localsolpsLog = 0.0;
if (localsolps > 0)
localsolpsLog = std::log2(localsolps);
if (IsInitialBlockDownload(Params())) {
if (fReindex) {
@ -347,9 +360,9 @@ int printStats(bool isScreen, bool mining)
}
std::cout << " " << _("Next upgrade") << " | " << strUpgradeTime << std::endl;
std::cout << " " << _("Connections") << " | " << connections << std::endl;
std::cout << " " << _("Network solution rate") << " | " << strprintf("~ 2^%.4f Sol/s", netsolpsLog) << std::endl;
std::cout << " " << _("Network solution rate") << " | " << DisplayHashRate(netsolps) << std::endl;
if (mining && miningTimer.running()) {
std::cout << " " << _("Local solution rate") << " | " << strprintf("~ 2^%.4f Sol/s", localsolpsLog) << std::endl;
std::cout << " " << _("Local solution rate") << " | " << DisplayHashRate(localsolps) << std::endl;
lines++;
}
std::cout << std::endl;

View File

@ -74,6 +74,8 @@ double GetLocalSolPS();
int EstimateNetHeight(const Consensus::Params& params, int currentBlockHeight, int64_t currentBlockTime);
boost::optional<int64_t> SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight);
std::string DisplayDuration(int64_t time, DurationFormat format);
std::string DisplaySize(size_t value);
std::string DisplayHashRate(double value);
void TriggerRefresh();