2016-09-03 09:39:45 -07:00
|
|
|
|
// Copyright (c) 2016 The Zcash developers
|
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2016-09-03 09:39:45 -07:00
|
|
|
|
|
2016-10-30 14:36:36 -07:00
|
|
|
|
#include "uint256.h"
|
2019-07-31 14:16:25 -07:00
|
|
|
|
#include "consensus/params.h"
|
2016-10-30 14:36:36 -07:00
|
|
|
|
|
2016-09-03 09:39:45 -07:00
|
|
|
|
#include <atomic>
|
2017-03-22 16:35:44 -07:00
|
|
|
|
#include <mutex>
|
2016-09-03 09:39:45 -07:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
struct AtomicCounter {
|
2016-11-02 12:50:00 -07:00
|
|
|
|
std::atomic<uint64_t> value;
|
2016-09-03 09:39:45 -07:00
|
|
|
|
|
|
|
|
|
AtomicCounter() : value {0} { }
|
|
|
|
|
|
|
|
|
|
void increment(){
|
|
|
|
|
++value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void decrement(){
|
|
|
|
|
--value;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 16:35:44 -07:00
|
|
|
|
int get() const {
|
2016-09-03 09:39:45 -07:00
|
|
|
|
return value.load();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-22 16:35:44 -07:00
|
|
|
|
class AtomicTimer {
|
|
|
|
|
private:
|
|
|
|
|
std::mutex mtx;
|
|
|
|
|
uint64_t threads;
|
|
|
|
|
int64_t start_time;
|
|
|
|
|
int64_t total_time;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
AtomicTimer() : threads(0), start_time(0), total_time(0) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starts timing on first call, and counts the number of calls.
|
|
|
|
|
*/
|
|
|
|
|
void start();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Counts number of calls, and stops timing after it has been called as
|
|
|
|
|
* many times as start().
|
|
|
|
|
*/
|
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
|
|
bool running();
|
|
|
|
|
|
2017-02-14 14:06:35 -08:00
|
|
|
|
uint64_t threadCount();
|
|
|
|
|
|
2017-03-22 16:35:44 -07:00
|
|
|
|
double rate(const AtomicCounter& count);
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-03 03:35:10 -08:00
|
|
|
|
enum DurationFormat {
|
2019-10-30 11:19:22 -07:00
|
|
|
|
FULL,
|
|
|
|
|
REDUCED
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-03 09:39:45 -07:00
|
|
|
|
extern AtomicCounter transactionsValidated;
|
|
|
|
|
extern AtomicCounter ehSolverRuns;
|
2016-09-04 15:54:15 -07:00
|
|
|
|
extern AtomicCounter solutionTargetChecks;
|
2017-03-22 16:37:22 -07:00
|
|
|
|
extern AtomicTimer miningTimer;
|
2020-03-05 05:38:22 -08:00
|
|
|
|
extern std::atomic<size_t> nSizeReindexed; // valid only during reindex
|
|
|
|
|
extern std::atomic<size_t> nFullSizeToReindex; // valid only during reindex
|
2016-10-30 14:36:36 -07:00
|
|
|
|
|
|
|
|
|
void TrackMinedBlock(uint256 hash);
|
2016-09-03 09:39:45 -07:00
|
|
|
|
|
2016-10-25 13:11:41 -07:00
|
|
|
|
void MarkStartTime();
|
|
|
|
|
double GetLocalSolPS();
|
2019-07-31 14:16:25 -07:00
|
|
|
|
int EstimateNetHeight(const Consensus::Params& params, int currentBlockHeight, int64_t currentBlockTime);
|
2019-11-03 03:35:10 -08:00
|
|
|
|
boost::optional<int64_t> SecondsLeftToNextEpoch(const Consensus::Params& params, int currentHeight);
|
|
|
|
|
std::string DisplayDuration(int64_t time, DurationFormat format);
|
2016-10-25 13:11:41 -07:00
|
|
|
|
|
2017-01-03 01:21:00 -08:00
|
|
|
|
void TriggerRefresh();
|
|
|
|
|
|
2016-09-03 10:51:54 -07:00
|
|
|
|
void ConnectMetricsScreen();
|
2016-09-03 09:39:45 -07:00
|
|
|
|
void ThreadShowMetricsScreen();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Heart image: https://commons.wikimedia.org/wiki/File:Heart_coraz%C3%B3n.svg
|
|
|
|
|
* License: CC BY-SA 3.0
|
|
|
|
|
*
|
|
|
|
|
* Rendering options:
|
2016-09-03 20:01:01 -07:00
|
|
|
|
* Zcash: img2txt -W 40 -H 20 -f utf8 -d none -g 0.7 Z-yellow.orange-logo.png
|
|
|
|
|
* Heart: img2txt -W 40 -H 20 -f utf8 -d none 2000px-Heart_corazón.svg.png
|
2016-09-03 09:39:45 -07:00
|
|
|
|
*/
|
|
|
|
|
const std::string METRICS_ART =
|
2016-09-03 20:01:01 -07:00
|
|
|
|
" [0;34;40m [0m \n"
|
|
|
|
|
" [0;34;40m [0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m:8[0;33;5;40;100m8[0;1;30;90;43mSX@888@@X[0;31;5;40;100m8[0;31;40m:[0;34;40m [0m [0;31;5;41;101m8; %[0;1;31;91;41mX[0m [0;1;31;91;41mX[0;31;5;41;101m% ;8[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m%[0;1;30;90;43m%X[0;1;33;93;43mt[0;33;5;43;103m%tt%[0;1;30;90;43mSSSS[0;33;5;43;103mS:[0;37;5;43;103mXXX[0;1;33;93;43mt[0;1;30;90;43m@[0;31;40m@[0;34;40m [0m [0;1;31;91;41mX[0;31;5;41;101m :[0;1;31;91;41m:[0m [0;1;31;91;41m:[0;31;5;41;101m: [0;1;31;91;41mX[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m@[0;1;30;90;43mS[0;1;33;93;43m;;tt%%[0;33;5;43;103m%[0;1;33;93;43mt[0;34;40m [0;1;33;93;43m;[0;33;5;43;103m;::[0;37;5;43;103mXXXX[0;37;43mS[0;31;5;40;100mX[0;34;40m [0m [0;31;5;41;101m% SS %[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m.[0;1;30;90;43mt[0;1;33;93;43m:::;;[0;1;30;90;43m%[0;31;40m8888[0;34;40m [0;31;40m8[0;30;41m8888[0;1;33;93;43mt[0;37;5;43;103mXXXX[0;1;30;90;43m8[0;31;40m;[0;34;40m [0m [0;1;31;91;41mS[0;31;5;41;101m [0;1;31;91;41mS[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m.[0;1;30;90;43m%[0;1;33;93;43m...:::[0;31;40m8[0;34;40m [0;1;30;90;43m8[0;33;5;43;103m::[0;37;5;43;103mXXX[0;1;33;93;43m%[0;31;40m;[0;34;40m [0m [0;31;5;41;101mX X[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;43m8[0;1;31;91;43m888[0;1;33;93;43m...:[0;1;30;90;43mt[0;1;30;90;41m888888[0;31;40mX[0;34;40m [0;33;5;40;100m8[0;33;5;43;103mt;;::[0;37;5;43;103mXX[0;1;30;90;43m8[0;31;40m [0;34;40m [0m [0;31;5;41;101m8 8[0m \n"
|
|
|
|
|
"[0;34;40m [0;31;40m%[0;1;31;91;43m888888[0;1;33;93;43m...:::;:[0;1;30;90;41m8[0;31;40m [0;34;40m [0;31;40m:[0;1;30;90;43mX[0;33;5;43;103mttt;;;::[0;37;5;43;103mX[0;31;5;40;100m@[0;34;40m [0m [0;31;5;41;101m [0m \n"
|
|
|
|
|
"[0;34;40m [0;1;30;90;41m8[0;1;31;91;43m88888888[0;1;33;93;43m...:[0;1;30;90;43mS[0;31;40mt[0;34;40m [0;1;30;90;41m8[0;1;33;93;43m:%[0;33;5;43;103m%tttt;;;:[0;1;30;90;43mX[0;34;40m [0m [0;31;5;41;101mX X[0m \n"
|
|
|
|
|
"[0;34;40m [0;1;30;90;41m8[0;1;31;91;43m8888888888[0;1;30;90;43mS[0;1;30;90;41m8[0;31;40m [0;34;40m [0;31;40m:[0;1;30;90;43m%[0;1;33;93;43m;ttt%[0;33;5;43;103m%tttt;;[0;1;30;90;43mX[0;34;40m [0m [0;31;5;41;101m8 8[0m \n"
|
|
|
|
|
"[0;34;40m [0;31;40m%[0;1;31;91;43m888888888[0;1;30;90;43m%[0;31;40mt[0;34;40m [0;30;41m8[0;1;30;90;43mS[0;1;33;93;43m:;;;tt%%[0;33;5;43;103m%ttt;[0;1;30;90;41m8[0;34;40m [0m [0;31;5;41;101m: :[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;43m8t[0;1;31;91;43m888888[0;33;41m8[0;31;40m [0;34;40m [0;31;40mS[0;33;41m888[0;31;43m8888[0;1;30;90;43mS[0;1;33;93;43mtt%%[0;33;5;43;103m%t[0;1;30;90;43m@[0;31;40m [0;34;40m [0m [0;1;31;91;41m:[0;31;5;41;101m: :[0;1;31;91;41m:[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m.[0;31;43m@tt[0;1;31;91;43m888[0;31;43m@[0;34;40m [0;1;30;90;41m8[0;1;33;93;43m;;ttt[0;1;30;90;43m@[0;31;40m;[0;34;40m [0m [0;31;5;41;101mt t[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m.[0;31;43m8ttt[0;1;31;91;43m8[0;31;43m@[0;31;40mSSSSS[0;34;40m [0;31;40mSXXXX[0;1;30;90;43m%[0;1;33;93;43m:;;;[0;1;30;90;43mX[0;31;40m;[0;34;40m [0m [0;31;5;41;101m8 8[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40mX[0;31;43m8ttt[0;1;31;91;43m8888[0;1;30;90;43m%[0;34;40m [0;1;30;90;43m%[0;1;31;91;43m88[0;1;33;93;43m...::[0;1;30;90;43mX[0;30;41m8[0;31;40m [0;34;40m [0m [0;1;31;91;41mX[0;31;5;41;101m. .[0;1;31;91;41mX[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m%[0;1;30;90;41m8[0;31;43m@tt[0;1;31;91;43m88[0;31;43m;[0;33;41m8888[0;1;30;90;43m%[0;1;31;91;43m8888[0;1;30;90;43m%[0;31;43m8[0;31;40mX[0;32;40m [0;34;40m [0m [0;1;31;91;41m:[0;31;5;41;101m; ;[0;1;31;91;41m:[0m \n"
|
|
|
|
|
" [0;34;40m [0;31;40m:@[0;1;30;90;41m8[0;33;41m8[0;31;43m8@XXX@8[0;1;30;90;41m8[0;31;40m8:[0;34;40m [0m [0;31;5;41;101mtt[0m \n"
|
|
|
|
|
" [0;34;40m [0m \n"
|
|
|
|
|
" [0;34;40m [0m ";
|