diff --git a/src/metrics.cpp b/src/metrics.cpp index f54d6e243..7bd447af6 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -64,6 +64,7 @@ AtomicCounter transactionsValidated; AtomicCounter ehSolverRuns; AtomicCounter solutionTargetChecks; AtomicCounter minedBlocks; +AtomicTimer miningTimer; boost::synchronized_value> trackedBlocks; @@ -90,14 +91,9 @@ 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()); + return miningTimer.rate(solutionTargetChecks); } void TriggerRefresh() @@ -240,7 +236,7 @@ int printMetrics(size_t cols, bool mining) } if (mining && loaded) { - double solps = GetLocalSolPS_INTERNAL(uptime); + double solps = GetLocalSolPS(); 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; diff --git a/src/metrics.h b/src/metrics.h index ff1138b99..3e830f823 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -55,6 +55,7 @@ public: extern AtomicCounter transactionsValidated; extern AtomicCounter ehSolverRuns; extern AtomicCounter solutionTargetChecks; +extern AtomicTimer miningTimer; void TrackMinedBlock(uint256 hash); diff --git a/src/miner.cpp b/src/miner.cpp index 5e2811504..6d34a1a9f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -528,12 +528,14 @@ void static BitcoinMiner() cancelSolver = true; } ); + miningTimer.start(); try { while (true) { if (chainparams.MiningRequiresPeers()) { // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. + miningTimer.stop(); do { bool fvNodesEmpty; { @@ -544,6 +546,7 @@ void static BitcoinMiner() break; MilliSleep(1000); } while (true); + miningTimer.start(); } // @@ -721,16 +724,19 @@ void static BitcoinMiner() } catch (const boost::thread_interrupted&) { + miningTimer.stop(); c.disconnect(); LogPrintf("ZcashMiner terminated\n"); throw; } catch (const std::runtime_error &e) { + miningTimer.stop(); c.disconnect(); LogPrintf("ZcashMiner runtime error: %s\n", e.what()); return; } + miningTimer.stop(); c.disconnect(); }