Auto merge of #1878 - str4d:1875-non-tty-metrics-usability, r=str4d
Improve non-TTY metrics usability Closes #1875.
This commit is contained in:
@@ -450,6 +450,11 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||||||
strUsage += HelpMessageOpt("-min", _("Start minimized"));
|
strUsage += HelpMessageOpt("-min", _("Start minimized"));
|
||||||
strUsage += HelpMessageOpt("-rootcertificates=<file>", _("Set SSL root certificates for payment request (default: -system-)"));
|
strUsage += HelpMessageOpt("-rootcertificates=<file>", _("Set SSL root certificates for payment request (default: -system-)"));
|
||||||
strUsage += HelpMessageOpt("-splash", _("Show splash screen on startup (default: 1)"));
|
strUsage += HelpMessageOpt("-splash", _("Show splash screen on startup (default: 1)"));
|
||||||
|
} else if (mode == HMM_BITCOIND) {
|
||||||
|
strUsage += HelpMessageGroup(_("Metrics Options (only if -daemon and -printtoconsole are not set):"));
|
||||||
|
strUsage += HelpMessageOpt("-showmetrics", _("Show metrics on stdout (default: 1 if running in a console, 0 otherwise)"));
|
||||||
|
strUsage += HelpMessageOpt("-metricsui", _("Set to 1 for a persistent metrics screen, 0 for sequential metrics output (default: 1 if running in a console, 0 otherwise)"));
|
||||||
|
strUsage += HelpMessageOpt("-metricsrefreshtime", strprintf(_("Number of seconds between metrics refreshes (default: %u if running in a console, %u otherwise)"), 1, 600));
|
||||||
}
|
}
|
||||||
|
|
||||||
return strUsage;
|
return strUsage;
|
||||||
@@ -980,7 +985,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
|
threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
|
||||||
|
|
||||||
if ((chainparams.NetworkIDString() != "regtest") &&
|
if ((chainparams.NetworkIDString() != "regtest") &&
|
||||||
GetBoolArg("-showmetrics", true) &&
|
GetBoolArg("-showmetrics", isatty(STDOUT_FILENO)) &&
|
||||||
!fPrintToConsole && !GetBoolArg("-daemon", false)) {
|
!fPrintToConsole && !GetBoolArg("-daemon", false)) {
|
||||||
// Start the persistent metrics interface
|
// Start the persistent metrics interface
|
||||||
ConnectMetricsScreen();
|
ConnectMetricsScreen();
|
||||||
|
|||||||
@@ -255,17 +255,24 @@ void ThreadShowMetricsScreen()
|
|||||||
// Make this thread recognisable as the metrics screen thread
|
// Make this thread recognisable as the metrics screen thread
|
||||||
RenameThread("zcash-metrics-screen");
|
RenameThread("zcash-metrics-screen");
|
||||||
|
|
||||||
// Clear screen
|
// Determine whether we should render a persistent UI or rolling metrics
|
||||||
std::cout << "\e[2J";
|
bool isTTY = isatty(STDOUT_FILENO);
|
||||||
|
bool isScreen = GetBoolArg("-metricsui", isTTY);
|
||||||
|
int64_t nRefresh = GetArg("-metricsrefreshtime", isTTY ? 1 : 600);
|
||||||
|
|
||||||
// Print art
|
if (isScreen) {
|
||||||
std::cout << METRICS_ART << std::endl;
|
// Clear screen
|
||||||
std::cout << std::endl;
|
std::cout << "\e[2J";
|
||||||
|
|
||||||
// Thank you text
|
// Print art
|
||||||
std::cout << _("Thank you for running a Zcash node!") << std::endl;
|
std::cout << METRICS_ART << std::endl;
|
||||||
std::cout << _("You're helping to strengthen the network and contributing to a social good :)") << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << std::endl;
|
|
||||||
|
// Thank you text
|
||||||
|
std::cout << _("Thank you for running a Zcash node!") << std::endl;
|
||||||
|
std::cout << _("You're helping to strengthen the network and contributing to a social good :)") << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Count uptime
|
// Count uptime
|
||||||
int64_t nStart = GetTime();
|
int64_t nStart = GetTime();
|
||||||
@@ -276,7 +283,7 @@ void ThreadShowMetricsScreen()
|
|||||||
int cols = 80;
|
int cols = 80;
|
||||||
|
|
||||||
// Get current window size
|
// Get current window size
|
||||||
if (isatty(STDOUT_FILENO)) {
|
if (isTTY) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
w.ws_col = 0;
|
w.ws_col = 0;
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 && w.ws_col != 0) {
|
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 && w.ws_col != 0) {
|
||||||
@@ -284,8 +291,10 @@ void ThreadShowMetricsScreen()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erase below current position
|
if (isScreen) {
|
||||||
std::cout << "\e[J";
|
// Erase below current position
|
||||||
|
std::cout << "\e[J";
|
||||||
|
}
|
||||||
|
|
||||||
// Miner status
|
// Miner status
|
||||||
bool mining = GetBoolArg("-gen", false);
|
bool mining = GetBoolArg("-gen", false);
|
||||||
@@ -298,13 +307,23 @@ void ThreadShowMetricsScreen()
|
|||||||
lines += printMessageBox(cols);
|
lines += printMessageBox(cols);
|
||||||
lines += printInitMessage();
|
lines += printInitMessage();
|
||||||
|
|
||||||
// Explain how to exit
|
if (isScreen) {
|
||||||
std::cout << "[" << _("Press Ctrl+C to exit") << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl;;
|
// Explain how to exit
|
||||||
|
std::cout << "[" << _("Press Ctrl+C to exit") << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl;
|
||||||
|
} else {
|
||||||
|
// Print delineator
|
||||||
|
std::cout << "----------------------------------------" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
boost::this_thread::interruption_point();
|
int64_t nWaitEnd = GetTime() + nRefresh;
|
||||||
MilliSleep(1000);
|
while (GetTime() < nWaitEnd) {
|
||||||
|
boost::this_thread::interruption_point();
|
||||||
|
MilliSleep(200);
|
||||||
|
}
|
||||||
|
|
||||||
// Return to the top of the updating section
|
if (isScreen) {
|
||||||
std::cout << "\e[" << lines << "A";
|
// Return to the top of the updating section
|
||||||
|
std::cout << "\e[" << lines << "A";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user