From 3a1b1a2fa2d7b56fb90518c2f1506c6f85cba948 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 28 May 2020 20:45:25 +1200 Subject: [PATCH 1/5] metrics: Fix indents --- src/metrics.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index df4a127b0..8c37d9f68 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -287,22 +287,22 @@ int printStats(bool mining) auto localsolps = GetLocalSolPS(); if (IsInitialBlockDownload(Params())) { - if (fReindex) { - int downloadPercent = nSizeReindexed * 100 / nFullSizeToReindex; - std::cout << " " << _("Reindexing blocks") << " | " << DisplaySize(nSizeReindexed) << " / " << DisplaySize(nFullSizeToReindex) << " (" << downloadPercent << "%, " << height << " " << _("blocks") << ")" << std::endl; - } else { - int nHeaders = currentHeadersHeight; - if (nHeaders < 0) - nHeaders = 0; - int netheight = currentHeadersHeight == -1 || currentHeadersTime == 0 ? - 0 : EstimateNetHeight(params, currentHeadersHeight, currentHeadersTime); - if (netheight < nHeaders) - netheight = nHeaders; - if (netheight <= 0) - netheight = 1; - int downloadPercent = height * 100 / netheight; - std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl; - } + if (fReindex) { + int downloadPercent = nSizeReindexed * 100 / nFullSizeToReindex; + std::cout << " " << _("Reindexing blocks") << " | " << DisplaySize(nSizeReindexed) << " / " << DisplaySize(nFullSizeToReindex) << " (" << downloadPercent << "%, " << height << " " << _("blocks") << ")" << std::endl; + } else { + int nHeaders = currentHeadersHeight; + if (nHeaders < 0) + nHeaders = 0; + int netheight = currentHeadersHeight == -1 || currentHeadersTime == 0 ? + 0 : EstimateNetHeight(params, currentHeadersHeight, currentHeadersTime); + if (netheight < nHeaders) + netheight = nHeaders; + if (netheight <= 0) + netheight = 1; + int downloadPercent = height * 100 / netheight; + std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl; + } } else { std::cout << " " << _("Block height") << " | " << height << std::endl; } From eb4ada98d2bbabbdecb066bea3639fa64c73a239 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 28 May 2020 21:10:19 +1200 Subject: [PATCH 2/5] metrics: Draw IBD progress bar showing headers and blocks --- src/metrics.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/metrics.cpp b/src/metrics.cpp index 8c37d9f68..b7e49b8bd 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -14,6 +14,7 @@ #include "utilmoneystr.h" #include "utilstrencodings.h" +#include #include #include #include @@ -302,6 +303,22 @@ int printStats(bool mining) netheight = 1; int downloadPercent = height * 100 / netheight; std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl; + + // Draw 50-character progress bar, which will fit into a 79-character line. + int blockChars = downloadPercent / 2; + int headerChars = (nHeaders * 50) / netheight; + std::cout << " | ["; + for (auto i : boost::irange(0, 50)) { + if (i < blockChars) { + std::cout << "█"; + } else if (i < headerChars) { + std::cout << "▄"; + } else { + std::cout << " "; + } + } + std::cout << "]" << std::endl; + lines++; } } else { std::cout << " " << _("Block height") << " | " << height << std::endl; From 96681695c957354e1a60fb623db443dccefc9f97 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 28 May 2020 21:11:49 +1200 Subject: [PATCH 3/5] metrics: Don't show "not mining" text for mainnet Mining with the zcashd built-in CPU miner is not useful work on mainnet at the current network difficulty. --- src/metrics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index b7e49b8bd..30bd88322 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -373,7 +373,7 @@ int printMiningStatus(bool mining) } } lines++; - } else { + } else if (Params().NetworkIDString() != "main") { 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; lines += 2; From a79337c3ee6d93f83ac8b98db50666d41ab16b7f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 2 Jun 2020 14:20:55 +1200 Subject: [PATCH 4/5] metrics: Switch to ANSI colour codes for progress bar We already assume that ANSI colour codes work for the metrics art, whereas the block characters have inconsistent support in fonts. --- src/metrics.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index 30bd88322..dc7e721d4 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -307,17 +307,20 @@ int printStats(bool mining) // Draw 50-character progress bar, which will fit into a 79-character line. int blockChars = downloadPercent / 2; int headerChars = (nHeaders * 50) / netheight; - std::cout << " | ["; + // Start with background colour reversed for "full" bar. + std::cout << " | ["; for (auto i : boost::irange(0, 50)) { - if (i < blockChars) { - std::cout << "█"; - } else if (i < headerChars) { - std::cout << "▄"; - } else { - std::cout << " "; + if (i == headerChars) { + // Switch to normal background colour for "empty" bar. + std::cout << ""; + } else if (i == blockChars) { + // Switch to distinct colour for "headers" bar. + std::cout << ""; } + std::cout << " "; } - std::cout << "]" << std::endl; + // Ensure that colour is reset after the progress bar is printed. + std::cout << "]" << std::endl; lines++; } } else { From 12e169d09ff61fabe58ef0e053bb97098e42be4f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 2 Jun 2020 14:23:03 +1200 Subject: [PATCH 5/5] metrics: Only print IBD progress bar on TTY Now that it is created from space characters, it is meaningless to print it to a log file. --- src/metrics.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/metrics.cpp b/src/metrics.cpp index dc7e721d4..e04a473c6 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -266,7 +266,7 @@ boost::optional SecondsLeftToNextEpoch(const Consensus::Params& params, } } -int printStats(bool mining) +int printStats(bool isScreen, bool mining) { // Number of lines that are always displayed int lines = 5; @@ -304,24 +304,26 @@ int printStats(bool mining) int downloadPercent = height * 100 / netheight; std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl; - // 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 << " | ["; - for (auto i : boost::irange(0, 50)) { - if (i == headerChars) { - // Switch to normal background colour for "empty" bar. - std::cout << ""; - } else if (i == blockChars) { - // Switch to distinct colour for "headers" bar. - std::cout << ""; + 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 << " | ["; + for (auto i : boost::irange(0, 50)) { + if (i == headerChars) { + // Switch to normal background colour for "empty" bar. + std::cout << ""; + } else if (i == blockChars) { + // Switch to distinct colour for "headers" bar. + std::cout << ""; + } + std::cout << " "; } - std::cout << " "; + // Ensure that colour is reset after the progress bar is printed. + std::cout << "]" << std::endl; + lines++; } - // Ensure that colour is reset after the progress bar is printed. - std::cout << "]" << std::endl; - lines++; } } else { std::cout << " " << _("Block height") << " | " << height << std::endl; @@ -604,7 +606,7 @@ void ThreadShowMetricsScreen() #endif if (loaded) { - lines += printStats(mining); + lines += printStats(isScreen, mining); lines += printMiningStatus(mining); } lines += printMetrics(cols, mining);