mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-11 13:24:40 +00:00
Added Benchmark class.
This commit is contained in:
parent
7fc7b976bf
commit
328f985e07
14 changed files with 346 additions and 156 deletions
103
src/backend/common/Benchmark.cpp
Normal file
103
src/backend/common/Benchmark.cpp
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "backend/common/Benchmark.h"
|
||||||
|
#include "backend/common/interfaces/IWorker.h"
|
||||||
|
#include "base/io/log/Log.h"
|
||||||
|
#include "base/io/log/Tags.h"
|
||||||
|
#include "base/tools/Chrono.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
static uint64_t hashCheck[2][10] = {
|
||||||
|
{ 0x898B6E0431C28A6BULL, 0xEE9468F8B40926BCULL, 0xC2BC5D11724813C0ULL, 0x3A2C7B285B87F941ULL, 0x3B5BD2C3A16B450EULL, 0x5CD0602F20C5C7C4ULL, 0x101DE939474B6812ULL, 0x52B765A1B156C6ECULL, 0x323935102AB6B45CULL, 0xB5231262E2792B26ULL },
|
||||||
|
{ 0x0F3E5400B39EA96AULL, 0x85944CCFA2752D1FULL, 0x64AFFCAE991811BAULL, 0x3E4D0B836D3B13BAULL, 0xEB7417D621271166ULL, 0x97FFE10C0949FFA5ULL, 0x84CAC0F8879A4BA1ULL, 0xA1B79F031DA2459FULL, 0x9B65226DA873E65DULL, 0x0F9E00C5A511C200ULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
bool xmrig::Benchmark::finish(uint64_t totalHashCount)
|
||||||
|
{
|
||||||
|
m_reset = true;
|
||||||
|
m_current = totalHashCount;
|
||||||
|
|
||||||
|
if (m_done < m_workers) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const double dt = (m_doneTime - m_startTime) / 1000.0;
|
||||||
|
uint64_t checkData = 0;
|
||||||
|
const uint32_t N = (m_end / 1000000) - 1;
|
||||||
|
|
||||||
|
if (((m_algo == Algorithm::RX_0) || (m_algo == Algorithm::RX_WOW)) && ((m_end % 1000000) == 0) && (N < 10)) {
|
||||||
|
checkData = hashCheck[(m_algo == Algorithm::RX_0) ? 0 : 1][N];
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *color = checkData ? ((m_data == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
|
||||||
|
|
||||||
|
LOG_NOTICE("%s " WHITE_BOLD("benchmark finished in ") CYAN_BOLD("%.3f seconds") WHITE_BOLD_S " hash sum = " CLEAR "%s%016" PRIX64 CLEAR, Tags::bench(), dt, color, m_data);
|
||||||
|
LOG_INFO("%s " WHITE_BOLD("press ") MAGENTA_BOLD("Ctrl+C") WHITE_BOLD(" to exit"), Tags::bench());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Benchmark::start()
|
||||||
|
{
|
||||||
|
m_startTime = Chrono::steadyMSecs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Benchmark::printProgress() const
|
||||||
|
{
|
||||||
|
if (!m_startTime || !m_current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const double dt = (Chrono::steadyMSecs() - m_startTime) / 1000.0;
|
||||||
|
const double percent = static_cast<double>(m_current) / m_end * 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::Benchmark::tick(IWorker *worker)
|
||||||
|
{
|
||||||
|
if (m_reset) {
|
||||||
|
m_data = 0;
|
||||||
|
m_done = 0;
|
||||||
|
m_reset = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint64_t doneTime = worker->benchDoneTime();
|
||||||
|
if (!doneTime) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
++m_done;
|
||||||
|
m_data ^= worker->benchData();
|
||||||
|
m_doneTime = std::max(doneTime, m_doneTime);
|
||||||
|
}
|
62
src/backend/common/Benchmark.h
Normal file
62
src/backend/common/Benchmark.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
|
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_BENCHMARK_H
|
||||||
|
#define XMRIG_BENCHMARK_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/tools/Object.h"
|
||||||
|
#include "base/crypto/Algorithm.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class IWorker;
|
||||||
|
|
||||||
|
|
||||||
|
class Benchmark
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Benchmark)
|
||||||
|
|
||||||
|
Benchmark(uint32_t end, const Algorithm &algo, size_t workers) : m_algo(algo), m_workers(workers), m_end(end) {}
|
||||||
|
~Benchmark() = default;
|
||||||
|
|
||||||
|
bool finish(uint64_t totalHashCount);
|
||||||
|
void printProgress() const;
|
||||||
|
void start();
|
||||||
|
void tick(IWorker *worker);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_reset = false;
|
||||||
|
const Algorithm m_algo = Algorithm::RX_0;
|
||||||
|
const size_t m_workers = 0;
|
||||||
|
const uint64_t m_end = 0;
|
||||||
|
uint32_t m_done = 0;
|
||||||
|
uint64_t m_current = 0;
|
||||||
|
uint64_t m_data = 0;
|
||||||
|
uint64_t m_doneTime = 0;
|
||||||
|
uint64_t m_startTime = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_BENCHMARK_H */
|
|
@ -6,8 +6,8 @@
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -46,6 +46,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
# include "backend/common/Benchmark.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,23 +60,12 @@ public:
|
||||||
XMRIG_DISABLE_COPY_MOVE(WorkersPrivate)
|
XMRIG_DISABLE_COPY_MOVE(WorkersPrivate)
|
||||||
|
|
||||||
|
|
||||||
WorkersPrivate() = default;
|
WorkersPrivate() = default;
|
||||||
|
~WorkersPrivate() = default;
|
||||||
|
|
||||||
|
IBackend *backend = nullptr;
|
||||||
inline ~WorkersPrivate()
|
std::shared_ptr<Benchmark> benchmark;
|
||||||
{
|
std::shared_ptr<Hashrate> hashrate;
|
||||||
delete hashrate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Hashrate *hashrate = nullptr;
|
|
||||||
IBackend *backend = nullptr;
|
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
|
||||||
Algorithm benchAlgo = Algorithm::RX_0;
|
|
||||||
uint32_t bench = 0;
|
|
||||||
uint64_t startTime = 0;
|
|
||||||
# endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,67 +88,9 @@ xmrig::Workers<T>::~Workers()
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
const xmrig::Hashrate *xmrig::Workers<T>::hashrate() const
|
xmrig::Benchmark *xmrig::Workers<T>::benchmark() const
|
||||||
{
|
{
|
||||||
return d_ptr->hashrate;
|
return d_ptr->benchmark.get();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void xmrig::Workers<T>::setBackend(IBackend *backend)
|
|
||||||
{
|
|
||||||
d_ptr->backend = backend;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void xmrig::Workers<T>::start(const std::vector<T> &data)
|
|
||||||
{
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
|
||||||
if (!data.empty()) {
|
|
||||||
d_ptr->bench = data.front().benchSize;
|
|
||||||
d_ptr->benchAlgo = data.front().algorithm;
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
|
|
||||||
for (const T &item : data) {
|
|
||||||
m_workers.push_back(new Thread<T>(d_ptr->backend, m_workers.size(), item));
|
|
||||||
}
|
|
||||||
|
|
||||||
d_ptr->hashrate = new Hashrate(m_workers.size());
|
|
||||||
Nonce::touch(T::backend());
|
|
||||||
|
|
||||||
for (Thread<T> *worker : m_workers) {
|
|
||||||
worker->start(Workers<T>::onReady);
|
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
|
||||||
if (!d_ptr->bench)
|
|
||||||
# endif
|
|
||||||
{
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
|
||||||
d_ptr->startTime = Chrono::steadyMSecs();
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void xmrig::Workers<T>::stop()
|
|
||||||
{
|
|
||||||
Nonce::stop(T::backend());
|
|
||||||
|
|
||||||
for (Thread<T> *worker : m_workers) {
|
|
||||||
delete worker;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_workers.clear();
|
|
||||||
Nonce::touch(T::backend());
|
|
||||||
|
|
||||||
delete d_ptr->hashrate;
|
|
||||||
d_ptr->hashrate = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,14 +119,8 @@ bool xmrig::Workers<T>::tick(uint64_t)
|
||||||
bool totalAvailable = true;
|
bool totalAvailable = true;
|
||||||
uint64_t totalHashCount = 0;
|
uint64_t totalHashCount = 0;
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
|
||||||
uint32_t benchDone = 0;
|
|
||||||
uint64_t benchData = 0;
|
|
||||||
uint64_t benchDoneTime = 0;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
for (Thread<T> *handle : m_workers) {
|
for (Thread<T> *handle : m_workers) {
|
||||||
IWorker* worker = handle->worker();
|
IWorker *worker = handle->worker();
|
||||||
if (worker) {
|
if (worker) {
|
||||||
uint64_t hashCount;
|
uint64_t hashCount;
|
||||||
getHashrateData<T>(worker, hashCount, ts);
|
getHashrateData<T>(worker, hashCount, ts);
|
||||||
|
@ -203,12 +133,8 @@ bool xmrig::Workers<T>::tick(uint64_t)
|
||||||
totalHashCount += n;
|
totalHashCount += n;
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
if (d_ptr->bench && worker->benchDoneTime()) {
|
if (d_ptr->benchmark) {
|
||||||
++benchDone;
|
d_ptr->benchmark->tick(worker);
|
||||||
benchData ^= worker->benchData();
|
|
||||||
if (worker->benchDoneTime() > benchDoneTime) {
|
|
||||||
benchDoneTime = worker->benchDoneTime();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
@ -219,33 +145,8 @@ bool xmrig::Workers<T>::tick(uint64_t)
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
if (d_ptr->bench) {
|
if (d_ptr->benchmark && d_ptr->benchmark->finish(totalHashCount)) {
|
||||||
Pool::benchProgress = std::min<uint32_t>(static_cast<uint32_t>((totalHashCount * 100U) / d_ptr->bench), 100U);
|
return false;
|
||||||
|
|
||||||
if (benchDone == m_workers.size()) {
|
|
||||||
const double dt = (benchDoneTime - d_ptr->startTime) / 1000.0;
|
|
||||||
|
|
||||||
uint64_t checkData = 0;
|
|
||||||
|
|
||||||
const Algorithm::Id algo = d_ptr->benchAlgo.id();
|
|
||||||
const uint32_t N = (d_ptr->bench / 1000000) - 1;
|
|
||||||
|
|
||||||
if (((algo == Algorithm::RX_0) || (algo == Algorithm::RX_WOW)) && ((d_ptr->bench % 1000000) == 0) && (N < 10)) {
|
|
||||||
static uint64_t hashCheck[2][10] = {
|
|
||||||
{ 0x898B6E0431C28A6BULL, 0xEE9468F8B40926BCULL, 0xC2BC5D11724813C0ULL, 0x3A2C7B285B87F941ULL, 0x3B5BD2C3A16B450EULL, 0x5CD0602F20C5C7C4ULL, 0x101DE939474B6812ULL, 0x52B765A1B156C6ECULL, 0x323935102AB6B45CULL, 0xB5231262E2792B26ULL },
|
|
||||||
{ 0x0F3E5400B39EA96AULL, 0x85944CCFA2752D1FULL, 0x64AFFCAE991811BAULL, 0x3E4D0B836D3B13BAULL, 0xEB7417D621271166ULL, 0x97FFE10C0949FFA5ULL, 0x84CAC0F8879A4BA1ULL, 0xA1B79F031DA2459FULL, 0x9B65226DA873E65DULL, 0x0F9E00C5A511C200ULL },
|
|
||||||
};
|
|
||||||
|
|
||||||
checkData = hashCheck[(algo == Algorithm::RX_0) ? 0 : 1][N];
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* color = checkData ? ((benchData == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
|
|
||||||
|
|
||||||
LOG_INFO("%s " WHITE_BOLD("benchmark finished in ") CYAN_BOLD("%.3f seconds") WHITE_BOLD_S " hash sum = " CLEAR "%s%016" PRIX64 CLEAR,
|
|
||||||
Tags::bench(), dt, color, benchData);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
@ -253,6 +154,71 @@ bool xmrig::Workers<T>::tick(uint64_t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
const xmrig::Hashrate *xmrig::Workers<T>::hashrate() const
|
||||||
|
{
|
||||||
|
return d_ptr->hashrate.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void xmrig::Workers<T>::setBackend(IBackend *backend)
|
||||||
|
{
|
||||||
|
d_ptr->backend = backend;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void xmrig::Workers<T>::start(const std::vector<T> &data)
|
||||||
|
{
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
if (!data.empty() && data.front().benchSize) {
|
||||||
|
d_ptr->benchmark = std::make_shared<Benchmark>(data.front().benchSize, data.front().algorithm, data.size());
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
for (const T &item : data) {
|
||||||
|
m_workers.push_back(new Thread<T>(d_ptr->backend, m_workers.size(), item));
|
||||||
|
}
|
||||||
|
|
||||||
|
d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size());
|
||||||
|
Nonce::touch(T::backend());
|
||||||
|
|
||||||
|
for (Thread<T> *worker : m_workers) {
|
||||||
|
worker->start(Workers<T>::onReady);
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
if (!d_ptr->benchmark)
|
||||||
|
# endif
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
if (d_ptr->benchmark) {
|
||||||
|
d_ptr->benchmark->start();
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void xmrig::Workers<T>::stop()
|
||||||
|
{
|
||||||
|
Nonce::stop(T::backend());
|
||||||
|
|
||||||
|
for (Thread<T> *worker : m_workers) {
|
||||||
|
delete worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_workers.clear();
|
||||||
|
Nonce::touch(T::backend());
|
||||||
|
|
||||||
|
d_ptr->hashrate.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
xmrig::IWorker *xmrig::Workers<T>::create(Thread<T> *)
|
xmrig::IWorker *xmrig::Workers<T>::create(Thread<T> *)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -47,6 +47,7 @@ namespace xmrig {
|
||||||
class Hashrate;
|
class Hashrate;
|
||||||
class WorkersPrivate;
|
class WorkersPrivate;
|
||||||
class Job;
|
class Job;
|
||||||
|
class Benchmark;
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -58,12 +59,13 @@ public:
|
||||||
Workers();
|
Workers();
|
||||||
~Workers();
|
~Workers();
|
||||||
|
|
||||||
|
Benchmark *benchmark() const;
|
||||||
|
bool tick(uint64_t ticks);
|
||||||
const Hashrate *hashrate() const;
|
const Hashrate *hashrate() const;
|
||||||
|
void jobEarlyNotification(const Job&);
|
||||||
void setBackend(IBackend *backend);
|
void setBackend(IBackend *backend);
|
||||||
void start(const std::vector<T> &data);
|
void start(const std::vector<T> &data);
|
||||||
void stop();
|
void stop();
|
||||||
bool tick(uint64_t ticks);
|
|
||||||
void jobEarlyNotification(const Job&);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static IWorker *create(Thread<T> *handle);
|
static IWorker *create(Thread<T> *handle);
|
||||||
|
|
|
@ -21,3 +21,8 @@ set(SOURCES_BACKEND_COMMON
|
||||||
src/backend/common/Worker.cpp
|
src/backend/common/Worker.cpp
|
||||||
src/backend/common/Workers.cpp
|
src/backend/common/Workers.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (WITH_RANDOMX AND WITH_BENCHMARK)
|
||||||
|
list(APPEND HEADERS_BACKEND_COMMON src/backend/common/Benchmark.h)
|
||||||
|
list(APPEND SOURCES_BACKEND_COMMON src/backend/common/Benchmark.cpp)
|
||||||
|
endif()
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Algorithm;
|
class Algorithm;
|
||||||
|
class Benchmark;
|
||||||
class Hashrate;
|
class Hashrate;
|
||||||
class IApiRequest;
|
class IApiRequest;
|
||||||
class IWorker;
|
class IWorker;
|
||||||
|
@ -66,6 +67,11 @@ public:
|
||||||
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;
|
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;
|
||||||
virtual void handleRequest(IApiRequest &request) = 0;
|
virtual void handleRequest(IApiRequest &request) = 0;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
virtual Benchmark *benchmark() const = 0;
|
||||||
|
virtual void printBenchProgress() const = 0;
|
||||||
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
# include "backend/common/Benchmark.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -459,3 +464,20 @@ void xmrig::CpuBackend::handleRequest(IApiRequest &request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
xmrig::Benchmark *xmrig::CpuBackend::benchmark() const
|
||||||
|
{
|
||||||
|
return d_ptr->workers.benchmark();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::CpuBackend::printBenchProgress() const
|
||||||
|
{
|
||||||
|
auto benchmark = d_ptr->workers.benchmark();
|
||||||
|
if (benchmark) {
|
||||||
|
benchmark->printProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -70,6 +70,11 @@ protected:
|
||||||
void handleRequest(IApiRequest &request) override;
|
void handleRequest(IApiRequest &request) override;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
Benchmark *benchmark() const override;
|
||||||
|
void printBenchProgress() const override;
|
||||||
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CpuBackendPrivate *d_ptr;
|
CpuBackendPrivate *d_ptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,6 +70,11 @@ protected:
|
||||||
void handleRequest(IApiRequest &request) override;
|
void handleRequest(IApiRequest &request) override;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
inline Benchmark *benchmark() const override { return nullptr; }
|
||||||
|
inline void printBenchProgress() const override {}
|
||||||
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CudaBackendPrivate *d_ptr;
|
CudaBackendPrivate *d_ptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -70,6 +70,11 @@ protected:
|
||||||
void handleRequest(IApiRequest &request) override;
|
void handleRequest(IApiRequest &request) override;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
inline Benchmark *benchmark() const override { return nullptr; }
|
||||||
|
inline void printBenchProgress() const override {}
|
||||||
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OclBackendPrivate *d_ptr;
|
OclBackendPrivate *d_ptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -75,7 +75,7 @@ const char *xmrig::Tags::randomx()
|
||||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
const char *xmrig::Tags::bench()
|
const char *xmrig::Tags::bench()
|
||||||
{
|
{
|
||||||
static const char *tag = RED_BG_BOLD(WHITE_BOLD_S " bench ");
|
static const char *tag = GREEN_BG_BOLD(WHITE_BOLD_S " bench ");
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,9 +89,6 @@ const char *Pool::kBenchmark = "benchmark";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
uint32_t Pool::benchProgress = 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,6 @@ public:
|
||||||
void print() const;
|
void print() const;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
static uint32_t benchProgress;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Flags {
|
enum Flags {
|
||||||
FLAG_ENABLED,
|
FLAG_ENABLED,
|
||||||
|
|
|
@ -242,30 +242,8 @@ public:
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
void printHashrate(bool details)
|
static inline void printProfile()
|
||||||
{
|
{
|
||||||
char num[16 * 4] = { 0 };
|
|
||||||
double speed[3] = { 0.0 };
|
|
||||||
|
|
||||||
for (auto backend : backends) {
|
|
||||||
const auto hashrate = backend->hashrate();
|
|
||||||
if (hashrate) {
|
|
||||||
speed[0] += hashrate->calc(Hashrate::ShortInterval);
|
|
||||||
speed[1] += hashrate->calc(Hashrate::MediumInterval);
|
|
||||||
speed[2] += hashrate->calc(Hashrate::LargeInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
backend->printHashrate(details);
|
|
||||||
}
|
|
||||||
|
|
||||||
double scale = 1.0;
|
|
||||||
const char* h = "H/s";
|
|
||||||
|
|
||||||
if ((speed[0] >= 1e6) || (speed[1] >= 1e6) || (speed[2] >= 1e6) || (maxHashrate[algorithm] >= 1e6)) {
|
|
||||||
scale = 1e-6;
|
|
||||||
h = "MH/s";
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_PROFILING
|
# ifdef XMRIG_FEATURE_PROFILING
|
||||||
ProfileScopeData* data[ProfileScopeData::MAX_DATA_COUNT];
|
ProfileScopeData* data[ProfileScopeData::MAX_DATA_COUNT];
|
||||||
|
|
||||||
|
@ -303,19 +281,55 @@ public:
|
||||||
i = n1;
|
i = n1;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
char benchProgress[8] = {};
|
|
||||||
if (Pool::benchProgress) {
|
void printHashrate(bool details)
|
||||||
sprintf(benchProgress, "%3u%% ", Pool::benchProgress);
|
{
|
||||||
|
char num[16 * 4] = { 0 };
|
||||||
|
double speed[3] = { 0.0 };
|
||||||
|
uint32_t count = 0;
|
||||||
|
|
||||||
|
for (auto backend : backends) {
|
||||||
|
const auto hashrate = backend->hashrate();
|
||||||
|
if (hashrate) {
|
||||||
|
++count;
|
||||||
|
|
||||||
|
speed[0] += hashrate->calc(Hashrate::ShortInterval);
|
||||||
|
speed[1] += hashrate->calc(Hashrate::MediumInterval);
|
||||||
|
speed[2] += hashrate->calc(Hashrate::LargeInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
backend->printHashrate(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("%s %s" WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("%s") " max " CYAN_BOLD("%s %s"),
|
if (!count) {
|
||||||
Tags::miner(), benchProgress,
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printProfile();
|
||||||
|
|
||||||
|
double scale = 1.0;
|
||||||
|
const char* h = "H/s";
|
||||||
|
|
||||||
|
if ((speed[0] >= 1e6) || (speed[1] >= 1e6) || (speed[2] >= 1e6) || (maxHashrate[algorithm] >= 1e6)) {
|
||||||
|
scale = 1e-6;
|
||||||
|
h = "MH/s";
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO("%s " WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("%s") " max " CYAN_BOLD("%s %s"),
|
||||||
|
Tags::miner(),
|
||||||
Hashrate::format(speed[0] * scale, num, sizeof(num) / 4),
|
Hashrate::format(speed[0] * scale, num, sizeof(num) / 4),
|
||||||
Hashrate::format(speed[1] * scale, num + 16, sizeof(num) / 4),
|
Hashrate::format(speed[1] * scale, num + 16, sizeof(num) / 4),
|
||||||
Hashrate::format(speed[2] * scale, num + 16 * 2, sizeof(num) / 4), h,
|
Hashrate::format(speed[2] * scale, num + 16 * 2, sizeof(num) / 4), h,
|
||||||
Hashrate::format(maxHashrate[algorithm] * scale, num + 16 * 3, sizeof(num) / 4), h
|
Hashrate::format(maxHashrate[algorithm] * scale, num + 16 * 3, sizeof(num) / 4), h
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||||
|
for (auto backend : backends) {
|
||||||
|
backend->printBenchProgress();
|
||||||
|
}
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue