diff --git a/src/backend/common/benchmark/BenchState.cpp b/src/backend/common/benchmark/BenchState.cpp index ae063571c..230435146 100644 --- a/src/backend/common/benchmark/BenchState.cpp +++ b/src/backend/common/benchmark/BenchState.cpp @@ -42,6 +42,7 @@ static uint64_t result = 0; IBenchListener *BenchState::m_listener = nullptr; +uint32_t BenchState::m_size = 0; } // namespace xmrig diff --git a/src/backend/common/benchmark/BenchState.h b/src/backend/common/benchmark/BenchState.h index 035d12338..0f4890a96 100644 --- a/src/backend/common/benchmark/BenchState.h +++ b/src/backend/common/benchmark/BenchState.h @@ -41,10 +41,13 @@ public: static void destroy(); static void done(uint64_t data, uint64_t ts); + inline static uint32_t size() { return m_size; } inline static void setListener(IBenchListener *listener) { m_listener = listener; } + inline static void setSize(uint32_t size) { m_size = size; } private: static IBenchListener *m_listener; + static uint32_t m_size; }; diff --git a/src/backend/common/benchmark/Benchmark.cpp b/src/backend/common/benchmark/Benchmark.cpp index 1e8e3a351..d94ab584d 100644 --- a/src/backend/common/benchmark/Benchmark.cpp +++ b/src/backend/common/benchmark/Benchmark.cpp @@ -21,14 +21,15 @@ #include "backend/common/benchmark/BenchState.h" #include "base/io/log/Log.h" #include "base/io/log/Tags.h" -#include "base/net/stratum/Job.h" #include "base/tools/Chrono.h" -xmrig::Benchmark::Benchmark(const Job &job, size_t workers, const IBackend *backend) : +#include + + +xmrig::Benchmark::Benchmark(size_t workers, const IBackend *backend) : m_backend(backend), - m_workers(workers), - m_end(job.benchSize()) + m_workers(workers) { } @@ -54,7 +55,7 @@ void xmrig::Benchmark::printProgress() const } const double dt = static_cast(Chrono::steadyMSecs() - m_startTime) / 1000.0; - const double percent = static_cast(m_current) / m_end * 100.0; + const double percent = static_cast(m_current) / BenchState::size() * 100.0; - LOG_NOTICE("%s " MAGENTA_BOLD("%5.2f%% ") CYAN_BOLD("%" PRIu64) CYAN("/%" PRIu64) BLACK_BOLD(" (%.3fs)"), Tags::bench(), percent, m_current, m_end, dt); + LOG_NOTICE("%s " MAGENTA_BOLD("%5.2f%% ") CYAN_BOLD("%" PRIu64) CYAN("/%" PRIu64) BLACK_BOLD(" (%.3fs)"), Tags::bench(), percent, m_current, BenchState::size(), dt); } diff --git a/src/backend/common/benchmark/Benchmark.h b/src/backend/common/benchmark/Benchmark.h index b558cd1a5..df0e4f9ca 100644 --- a/src/backend/common/benchmark/Benchmark.h +++ b/src/backend/common/benchmark/Benchmark.h @@ -27,7 +27,6 @@ namespace xmrig { class IBackend; -class Job; class Benchmark @@ -35,7 +34,7 @@ class Benchmark public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(Benchmark) - Benchmark(const Job &job, size_t workers, const IBackend *backend); + Benchmark(size_t workers, const IBackend *backend); ~Benchmark() = default; bool finish(uint64_t totalHashCount); @@ -45,7 +44,6 @@ public: private: const IBackend *m_backend; const size_t m_workers; - const uint64_t m_end; uint64_t m_current = 0; uint64_t m_startTime = 0; }; diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index f5ff86acd..a00b26536 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -57,6 +57,7 @@ #ifdef XMRIG_FEATURE_BENCHMARK # include "backend/common/benchmark/Benchmark.h" +# include "backend/common/benchmark/BenchState.h" #endif @@ -347,7 +348,7 @@ void xmrig::CpuBackend::setJob(const Job &job) const auto &cpu = d_ptr->controller->config()->cpu(); # ifdef XMRIG_FEATURE_BENCHMARK - uint32_t benchSize = job.benchSize(); + const uint32_t benchSize = BenchState::size(); # else constexpr uint32_t benchSize = 0; # endif @@ -370,7 +371,7 @@ void xmrig::CpuBackend::setJob(const Job &job) # ifdef XMRIG_FEATURE_BENCHMARK if (benchSize) { - d_ptr->benchmark = std::make_shared(job, threads.size(), this); + d_ptr->benchmark = std::make_shared(threads.size(), this); } # endif diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 203454143..fc17b5102 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -174,10 +174,6 @@ void xmrig::Job::copy(const Job &other) memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob)); memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget)); # endif - -# ifdef XMRIG_FEATURE_BENCHMARK - m_benchSize = other.m_benchSize; -# endif } @@ -209,8 +205,4 @@ void xmrig::Job::move(Job &&other) memcpy(m_rawBlob, other.m_rawBlob, sizeof(m_rawBlob)); memcpy(m_rawTarget, other.m_rawTarget, sizeof(m_rawTarget)); # endif - -# ifdef XMRIG_FEATURE_BENCHMARK - m_benchSize = other.m_benchSize; -# endif } diff --git a/src/base/net/stratum/Job.h b/src/base/net/stratum/Job.h index 5621cbc7f..761b5af22 100644 --- a/src/base/net/stratum/Job.h +++ b/src/base/net/stratum/Job.h @@ -111,11 +111,6 @@ public: inline Job &operator=(const Job &other) { copy(other); return *this; } inline Job &operator=(Job &&other) noexcept { move(std::move(other)); return *this; } -# ifdef XMRIG_FEATURE_BENCHMARK - inline uint32_t benchSize() const { return m_benchSize; } - inline void setBenchSize(uint32_t size) { m_benchSize = size; } -# endif - private: void copy(const Job &other); void move(Job &&other); @@ -140,10 +135,6 @@ private: char m_rawTarget[24]{}; String m_rawSeedHash; # endif - -# ifdef XMRIG_FEATURE_BENCHMARK - uint32_t m_benchSize = 0; -# endif }; diff --git a/src/base/net/stratum/benchmark/BenchClient.cpp b/src/base/net/stratum/benchmark/BenchClient.cpp index 2f5a11a61..1005ec668 100644 --- a/src/base/net/stratum/benchmark/BenchClient.cpp +++ b/src/base/net/stratum/benchmark/BenchClient.cpp @@ -46,9 +46,9 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr &benchmark, I m_job.setAlgorithm(m_benchmark->algorithm()); m_job.setDiff(std::numeric_limits::max()); m_job.setHeight(1); - m_job.setBenchSize(m_benchmark->size()); BenchState::setListener(this); + BenchState::setSize(m_benchmark->size()); # ifdef XMRIG_FEATURE_HTTP if (m_benchmark->isSubmit()) { @@ -221,7 +221,7 @@ uint64_t xmrig::BenchClient::referenceHash() const return m_hash; } - return BenchState::referenceHash(m_job.algorithm(), m_job.benchSize(), m_threads); + return BenchState::referenceHash(m_job.algorithm(), BenchState::size(), m_threads); } @@ -303,7 +303,8 @@ void xmrig::BenchClient::startVerify(const rapidjson::Value &value) m_job.setAlgorithm(Json::getString(value, BenchConfig::kAlgo)); m_job.setSeedHash(Json::getString(value, BenchConfig::kSeed)); - m_job.setBenchSize(Json::getUint(value, BenchConfig::kSize)); + + BenchState::setSize(Json::getUint(value, BenchConfig::kSize)); start(); } diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 0995d62b0..3715244a5 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -51,6 +51,11 @@ #endif +#ifdef XMRIG_FEATURE_BENCHMARK +# include "backend/common/benchmark/BenchState.h" +#endif + + #include #include #include @@ -264,7 +269,7 @@ void xmrig::Network::setJob(IClient *client, const Job &job, bool donate) const char *scale = NetworkState::scaleDiff(diff); # ifdef XMRIG_FEATURE_BENCHMARK - const uint32_t size = job.benchSize(); + const uint32_t size = BenchState::size(); if (size) { LOG_NOTICE("%s " MAGENTA_BOLD("start benchmark ") "hashes " CYAN_BOLD("%u%s") " algo " WHITE_BOLD("%s") " print_time " CYAN_BOLD("%us"), Tags::bench(),