Auto merge of #1642 - str4d:add-solver-rate-to-getmininginfo, r=str4d

Add getlocalsolps and getnetworksolps RPC calls, show them in getmininginfo
This commit is contained in:
zkbot
2016-12-09 03:18:23 +00:00
8 changed files with 116 additions and 12 deletions

View File

@@ -19,6 +19,7 @@
CCriticalSection cs_metrics;
boost::synchronized_value<int64_t> nNodeStartTime;
AtomicCounter transactionsValidated;
AtomicCounter ehSolverRuns;
AtomicCounter solutionTargetChecks;
@@ -39,6 +40,26 @@ void TrackMinedBlock(uint256 hash)
trackedBlocks->push_back(hash);
}
void MarkStartTime()
{
*nNodeStartTime = GetTime();
}
int64_t GetUptime()
{
return GetTime() - *nNodeStartTime;
}
double GetLocalSolPS_INTERNAL(int64_t uptime)
{
return uptime > 0 ? (double)solutionTargetChecks.get() / uptime : 0;
}
double GetLocalSolPS()
{
return GetLocalSolPS_INTERNAL(GetUptime());
}
static bool metrics_ThreadSafeMessageBox(const std::string& message,
const std::string& caption,
unsigned int style)
@@ -118,13 +139,13 @@ int printMiningStatus(bool mining)
return lines;
}
int printMetrics(size_t cols, int64_t nStart, bool mining)
int printMetrics(size_t cols, bool mining)
{
// Number of lines that are always displayed
int lines = 3;
// Calculate uptime
int64_t uptime = GetTime() - nStart;
int64_t uptime = GetUptime();
int days = uptime / (24 * 60 * 60);
int hours = (uptime - (days * 24 * 60 * 60)) / (60 * 60);
int minutes = (uptime - (((days * 24) + hours) * 60 * 60)) / 60;
@@ -155,7 +176,7 @@ int printMetrics(size_t cols, int64_t nStart, bool mining)
}
if (mining && loaded) {
double solps = uptime > 0 ? (double)solutionTargetChecks.get() / uptime : 0;
double solps = GetLocalSolPS_INTERNAL(uptime);
std::string strSolps = strprintf("%.4f Sol/s", solps);
std::cout << "- " << strprintf(_("You have contributed %s on average to the network solution rate."), strSolps) << std::endl;
std::cout << "- " << strprintf(_("You have completed %d Equihash solver runs."), ehSolverRuns.get()) << std::endl;
@@ -274,9 +295,6 @@ void ThreadShowMetricsScreen()
std::cout << std::endl;
}
// Count uptime
int64_t nStart = GetTime();
while (true) {
// Number of lines that are always displayed
int lines = 1;
@@ -303,7 +321,7 @@ void ThreadShowMetricsScreen()
lines += printNetworkStats();
}
lines += printMiningStatus(mining);
lines += printMetrics(cols, nStart, mining);
lines += printMetrics(cols, mining);
lines += printMessageBox(cols);
lines += printInitMessage();