From 003cd8fd8f868006723508098b68f5407d8c25a6 Mon Sep 17 00:00:00 2001 From: gladcow Date: Thu, 5 Mar 2020 16:26:07 +0300 Subject: [PATCH] Byte sizes format --- src/metrics.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index 75f8764df..7c1b2c754 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -235,6 +235,24 @@ std::string DisplayDuration(int64_t time, DurationFormat format) return strDuration; } +std::string DisplaySize(size_t value) +{ + double coef = 1.0; + if (value < 1024.0 * coef) + return strprintf(_("%d Bytes"), value); + coef *= 1024.0; + if (value < 1024.0 * coef) + return strprintf(_("%.2f KiB"), value / coef); + coef *= 1024.0; + if (value < 1024.0 * coef) + return strprintf(_("%.2f MiB"), value / coef); + coef *= 1024.0; + if (value < 1024.0 * coef) + return strprintf(_("%.2f GiB"), value / coef); + coef *= 1024.0; + return strprintf(_("%.2f TiB"), value / coef); +} + boost::optional SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight) { auto nextHeight = NextActivationHeight(currentHeight, params); @@ -269,7 +287,7 @@ int printStats(bool mining) if (IsInitialBlockDownload(Params())) { if (fReindex) { int downloadPercent = nSizeReindexed * 100 / nFullSizeToReindex; - std::cout << " " << _("Reindexing blocks") << " | " << nSizeReindexed << " / " << nFullSizeToReindex << " " << _("bytes") << " (" << downloadPercent << "%, " << height << " " << _("blocks") << ")" << std::endl; + std::cout << " " << _("Reindexing blocks") << " | " << DisplaySize(nSizeReindexed) << " / " << DisplaySize(nFullSizeToReindex) << " (" << downloadPercent << "%, " << height << " " << _("blocks") << ")" << std::endl; } else { int netheight = currentHeadersHeight == -1 || currentHeadersTime == 0 ? 0 : EstimateNetHeight(params, currentHeadersHeight, currentHeadersTime);