From 460a601e9b266acccb123226a8f26b04ac94e005 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Fri, 17 Jul 2020 13:56:33 +0100 Subject: [PATCH] Metrics screen: display hash rates using SI prefixes rather than as powers of 2. Signed-off-by: Daira Hopwood --- src/metrics.cpp | 27 ++++++++++++++++++++------- src/metrics.h | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index 09f8b113a..0eed99817 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -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 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; diff --git a/src/metrics.h b/src/metrics.h index 2b21e1b6d..a40907ac8 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -74,6 +74,8 @@ double GetLocalSolPS(); int EstimateNetHeight(const Consensus::Params& params, int currentBlockHeight, int64_t currentBlockTime); boost::optional 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();