Skip to content

Commit 5e7c148

Browse files
committed
Show Clock Time rather than time since start for mining and Test Mode
Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
1 parent f932710 commit 5e7c148

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

Miner.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ void Miner::startThreads() {
336336
for (uint16_t i(0) ; i < _parameters.threads ; i++)
337337
_workerThreads.push_back(std::thread(&Miner::_doTasks, this, i));
338338
std::cout << "-----------------------------------------------------------" << std::endl;
339-
std::cout << Stats::formattedTime(_statManager.timeSinceStart()) << " Started mining at block " << _client->currentHeight() << ", difficulty " << FIXED(3) << _client->currentDifficulty() << std::endl;
339+
if (_mode == "Benchmark" || _mode == "Search")
340+
std::cout << Stats::formattedTime(_statManager.timeSinceStart()) << " Started " << _mode << ", difficulty " << FIXED(3) << _client->currentDifficulty() << std::endl;
341+
else
342+
std::cout << Stats::formattedClockTimeNow() << " Started mining at block " << _client->currentHeight() << ", difficulty " << FIXED(3) << _client->currentDifficulty() << std::endl;
340343
}
341344
}
342345

@@ -787,7 +790,10 @@ void Miner::_doCheckTask(Task task) {
787790
// If tuple long enough or share, submit
788791
if (primeCount >= _works[workIndex].job.primeCountMin || (_mode == "Search" && primeCount >= _parameters.tupleLengthMin)) {
789792
const mpz_class basePrime(candidate - offsetSum);
790-
std::cout << Stats::formattedTime(_statManager.timeSinceStart()) << " " << primeCount;
793+
if (_mode == "Benchmark" || _mode == "Search")
794+
std::cout << Stats::formattedTime(_statManager.timeSinceStart()) << " " << primeCount;
795+
else
796+
std::cout << Stats::formattedClockTimeNow() << " " << primeCount;
791797
if (_mode == "Pool")
792798
std::cout << "-share found by worker thread " << threadId << std::endl;
793799
else {
@@ -867,7 +873,11 @@ void Miner::_manageTasks() {
867873
// Notify when the network found a block
868874
if (isNewHeight && oldHeight != 0) {
869875
_statManager.newBlock();
870-
std::cout << Stats::formattedTime(_statManager.timeSinceStart()) << " Block " << job.height << ", average " << FIXED(1) << _statManager.averageBlockTime() << " s, difficulty " << FIXED(3) << job.difficulty << std::endl;
876+
if (_mode == "Benchmark" || _mode == "Search")
877+
std::cout << Stats::formattedTime(_statManager.timeSinceStart());
878+
else
879+
std::cout << Stats::formattedClockTimeNow();
880+
std::cout << " Block " << job.height << ", average " << FIXED(1) << _statManager.averageBlockTime() << " s, difficulty " << FIXED(3) << job.difficulty << std::endl;
871881
}
872882
_works[_currentWorkIndex].primorialMultipleStart = _works[_currentWorkIndex].job.target + _primorial - (_works[_currentWorkIndex].job.target % _primorial);
873883
// Reset Counts and create Presieve Tasks
@@ -997,9 +1007,13 @@ bool Miner::hasAcceptedPatterns(const std::vector<std::vector<uint64_t>> &accept
9971007

9981008
void Miner::printStats() const {
9991009
Stats statsRecent(_statManager.stats(false)), statsSinceStart(_statManager.stats(true));
1000-
if (_mode == "Benchmark" || _mode == "Search")
1010+
if (_mode == "Benchmark" || _mode == "Search") {
10011011
statsRecent = statsSinceStart;
1002-
std::cout << Stats::formattedTime(_statManager.timeSinceStart()) << " " << FIXED(2) << statsRecent.cps() << " c/s, r " << statsRecent.r();
1012+
std::cout << Stats::formattedTime(_statManager.timeSinceStart());
1013+
}
1014+
else
1015+
std::cout << Stats::formattedClockTimeNow();
1016+
std::cout << " " << FIXED(2) << statsRecent.cps() << " c/s, r " << statsRecent.r();
10031017
if (_mode != "Pool") {
10041018
std::cout << " ; (1-" << _parameters.pattern.size() << "t) = " << statsSinceStart.formattedCounts(1);
10051019
if (statsRecent.count(1) >= 10)

Stats.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ std::string Stats::formattedTime(const double &time) {
4040
oss << "[" << timeInt/86400000 << ":" << leading0s(2) << (timeInt/3600000) % 24 << ":" << leading0s(2) << (timeInt/60000) % 60 << ":" << leading0s(2) << (timeInt/1000) % 60 << "." << (timeInt/100) % 10 << "]";
4141
return oss.str();
4242
}
43+
std::string Stats::formattedClockTimeNow() {
44+
const std::chrono::time_point now(std::chrono::system_clock::now());
45+
const std::chrono::time_point seconds(std::chrono::time_point_cast<std::chrono::seconds>(now));
46+
const std::chrono::duration milliseconds(std::chrono::duration_cast<std::chrono::milliseconds>(now - seconds));
47+
const std::time_t timeT(std::chrono::system_clock::to_time_t(now));
48+
const std::tm *timeTm(std::localtime(&timeT));
49+
std::ostringstream oss;
50+
oss << "[" << std::put_time(timeTm, "%H:%M:%S") << "." << static_cast<uint32_t>(std::floor(milliseconds.count()))/100 << "]";
51+
return oss.str();
52+
}
4353
std::string Stats::formattedDuration(const double &duration) {
4454
std::ostringstream oss;
4555
if (duration < 0.001) oss << std::round(1000000.*duration) << " us";

Stats.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Stats {
2121
std::string formattedRates(const uint64_t = 0) const;
2222
std::string formattedRatios() const;
2323
static std::string formattedTime(const double &time);
24+
static std::string formattedClockTimeNow();
2425
static std::string formattedDuration(const double &duration);
2526
};
2627

0 commit comments

Comments
 (0)