From fed163568e71a386e9fbd37d9c13007cec844e44 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 16 Jun 2017 11:08:10 +0300 Subject: [PATCH] Add option "--print-time". --- src/Options.cpp | 13 +++++++++++++ src/Options.h | 2 ++ src/workers/Hashrate.cpp | 15 +++++++++++++++ src/workers/Hashrate.h | 4 ++++ src/workers/Workers.cpp | 3 +-- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 111543ec..4da75923 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -72,6 +72,7 @@ Options:\n\ --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\ --safe safe adjust threads and av settings for current CPU\n\ --nicehash enable nicehash support\n\ + --print-time=N print hashrate report every N seconds\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ "; @@ -94,6 +95,7 @@ static struct option const options[] = { { "nicehash", 0, nullptr, 1006 }, { "no-color", 0, nullptr, 1002 }, { "pass", 1, nullptr, 'p' }, + { "print-time", 1, nullptr, 1007 }, { "retries", 1, nullptr, 'r' }, { "retry-pause", 1, nullptr, 'R' }, { "safe", 0, nullptr, 1005 }, @@ -144,6 +146,7 @@ Options::Options(int argc, char **argv) : m_algoVariant(0), m_donateLevel(kDonateLevel), m_maxCpuUsage(75), + m_printTime(60), m_retries(5), m_retryPause(5), m_threads(0), @@ -360,6 +363,16 @@ bool Options::parseArg(int key, char *arg) m_nicehash = true; break; + case 1007: /* --print-time */ + v = strtol(arg, nullptr, 10); + if (v < 0 || v > 1000) { + showUsage(1); + return false; + } + + m_printTime = v; + break; + default: showUsage(1); return false; diff --git a/src/Options.h b/src/Options.h index d8d6e4ae..c100f6d6 100644 --- a/src/Options.h +++ b/src/Options.h @@ -64,6 +64,7 @@ public: inline int algo() const { return m_algo; } inline int algoVariant() const { return m_algoVariant; } inline int donateLevel() const { return m_donateLevel; } + inline int printTime() const { return m_printTime; } inline int retries() const { return m_retries; } inline int retryPause() const { return m_retryPause; } inline int threads() const { return m_threads; } @@ -103,6 +104,7 @@ private: int m_algoVariant; int m_donateLevel; int m_maxCpuUsage; + int m_printTime; int m_retries; int m_retryPause; int m_threads; diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 53443c95..7f2f7ee1 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -58,6 +58,15 @@ Hashrate::Hashrate(int threads) : memset(m_counts[0], 0, sizeof(uint64_t) * kBucketSize); memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize); } + + const int printTime = Options::i()->printTime(); + + if (printTime > 0) { + uv_timer_init(uv_default_loop(), &m_timer); + m_timer.data = this; + + uv_timer_start(&m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000); + } } @@ -159,3 +168,9 @@ void Hashrate::updateHighest() m_highest = highest; } } + + +void Hashrate::onReport(uv_timer_t *handle) +{ + static_cast(handle->data)->print(); +} diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index c6f3cf27..9ba0b0bf 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -26,6 +26,7 @@ #include +#include class Hashrate @@ -41,6 +42,8 @@ public: inline double highest() const { return m_highest; } private: + static void onReport(uv_timer_t *handle); + constexpr static size_t kBucketSize = 2 << 11; constexpr static size_t kBucketMask = kBucketSize - 1; @@ -49,6 +52,7 @@ private: uint32_t* m_top; uint64_t** m_counts; uint64_t** m_timestamps; + uv_timer_t m_timer; }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index de3f7a0e..433bdcd8 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -27,6 +27,7 @@ #include "Console.h" #include "interfaces/IJobResultListener.h" #include "Mem.h" +#include "Options.h" #include "workers/DoubleWorker.h" #include "workers/Handle.h" #include "workers/Hashrate.h" @@ -102,7 +103,6 @@ void Workers::submit(const JobResult &result) } - void Workers::onReady(void *arg) { auto handle = static_cast(arg); @@ -148,6 +148,5 @@ void Workers::onTick(uv_timer_t *handle) if ((m_ticks++ & 0xF) == 0) { m_hashrate->updateHighest(); - m_hashrate->print(); } }