diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bce386cf..d301b6ef1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,8 @@ set(HEADERS src/version.h src/workers/DoubleWorker.h src/workers/Handle.h + src/workers/Hashrate.h src/workers/SingleWorker.h - src/workers/Telemetry.h src/workers/Worker.h src/workers/Workers.h ) @@ -55,8 +55,8 @@ set(SOURCES src/Summary.cpp src/workers/DoubleWorker.cpp src/workers/Handle.cpp + src/workers/Hashrate.cpp src/workers/SingleWorker.cpp - src/workers/Telemetry.cpp src/workers/Worker.cpp src/workers/Workers.cpp src/xmrig.cpp diff --git a/src/Console.cpp b/src/Console.cpp index 2ce56ee19..558c1e8d4 100644 --- a/src/Console.cpp +++ b/src/Console.cpp @@ -28,9 +28,9 @@ #include - #ifdef WIN32 # include +# include # include "3rdparty/winansi.h" #endif diff --git a/src/workers/Telemetry.cpp b/src/workers/Hashrate.cpp similarity index 86% rename from src/workers/Telemetry.cpp rename to src/workers/Hashrate.cpp index b1a36633e..3a6cbda22 100644 --- a/src/workers/Telemetry.cpp +++ b/src/workers/Hashrate.cpp @@ -23,14 +23,14 @@ #include -#include +#include #include #include "Console.h" -#include "workers/Telemetry.h" +#include "workers/Hashrate.h" -Telemetry::Telemetry(int threads) : +Hashrate::Hashrate(int threads) : m_threads(threads) { m_counts = new uint64_t*[threads]; @@ -48,7 +48,23 @@ Telemetry::Telemetry(int threads) : } -double Telemetry::calc(size_t threadId, size_t ms) const +double Hashrate::calc(size_t ms) const +{ + double result = .0; + double data; + + for (int i = 0; i < m_threads; ++i) { + data = calc(i, ms); + if (std::isnormal(data)) { + result += data; + } + } + + return result; +} + + +double Hashrate::calc(size_t threadId, size_t ms) const { using namespace std::chrono; const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); @@ -97,7 +113,7 @@ double Telemetry::calc(size_t threadId, size_t ms) const } -void Telemetry::add(size_t threadId, uint64_t count, uint64_t timestamp) +void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) { const size_t top = m_top[threadId]; m_counts[threadId][top] = count; diff --git a/src/workers/Telemetry.h b/src/workers/Hashrate.h similarity index 90% rename from src/workers/Telemetry.h rename to src/workers/Hashrate.h index 007ba536e..b225e1ca8 100644 --- a/src/workers/Telemetry.h +++ b/src/workers/Hashrate.h @@ -21,17 +21,18 @@ * along with this program. If not, see . */ -#ifndef __TELEMETRY_H__ -#define __TELEMETRY_H__ +#ifndef __HASHRATE_H__ +#define __HASHRATE_H__ #include -class Telemetry +class Hashrate { public: - Telemetry(int threads); + Hashrate(int threads); + double calc(size_t ms) const; double calc(size_t threadId, size_t ms) const; void add(size_t threadId, uint64_t count, uint64_t timestamp); @@ -46,4 +47,4 @@ private: }; -#endif /* __TELEMETRY_H__ */ +#endif /* __HASHRATE_H__ */ diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index b512d282f..592bc17d2 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -29,18 +29,18 @@ #include "Mem.h" #include "workers/DoubleWorker.h" #include "workers/Handle.h" +#include "workers/Hashrate.h" #include "workers/SingleWorker.h" -#include "workers/Telemetry.h" #include "workers/Workers.h" +Hashrate *Workers::m_hashrate = nullptr; IJobResultListener *Workers::m_listener = nullptr; Job Workers::m_job; std::atomic Workers::m_paused; std::atomic Workers::m_sequence; std::list Workers::m_queue; std::vector Workers::m_workers; -Telemetry *Workers::m_telemetry = nullptr; uint64_t Workers::m_ticks = 0; uv_async_t Workers::m_async; uv_mutex_t Workers::m_mutex; @@ -72,7 +72,7 @@ void Workers::setJob(const Job &job) void Workers::start(int64_t affinity, bool nicehash) { const int threads = Mem::threads(); - m_telemetry = new Telemetry(threads); + m_hashrate = new Hashrate(threads); uv_mutex_init(&m_mutex); uv_rwlock_init(&m_rwlock); @@ -139,29 +139,14 @@ void Workers::onResult(uv_async_t *handle) void Workers::onTick(uv_timer_t *handle) { for (Handle *handle : m_workers) { - if (handle->worker()) { - m_telemetry->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp()); + if (!handle->worker()) { + return; } + + m_hashrate->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp()); } if ((m_ticks++ & 0xF) == 0) { - double hps = 0.0; - double telem; - bool normal = true; - - for (Handle *handle : m_workers) { - telem = m_telemetry->calc(handle->threadId(), 2500); - if (!std::isnormal(telem)) { - normal = false; - break; - } - else { - hps += telem; - } - } - - if (normal) { - LOG_NOTICE("%03.1f H/s", hps); - } + LOG_NOTICE("%03.1f H/s", m_hashrate->calc(2500)); } } diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 6cf17de4b..0990fc45e 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -35,8 +35,8 @@ class Handle; +class Hashrate; class IJobResultListener; -class Telemetry; class Workers @@ -58,13 +58,13 @@ private: static void onResult(uv_async_t *handle); static void onTick(uv_timer_t *handle); + static Hashrate *m_hashrate; static IJobResultListener *m_listener; static Job m_job; static std::atomic m_paused; static std::atomic m_sequence; static std::list m_queue; static std::vector m_workers; - static Telemetry *m_telemetry; static uint64_t m_ticks; static uv_async_t m_async; static uv_mutex_t m_mutex;