Code cleanup.

This commit is contained in:
XMRig 2020-05-05 01:55:00 +07:00
parent 4326ba3c38
commit c828e6b793
No known key found for this signature in database
GPG key ID: 446A53638BE94409
7 changed files with 61 additions and 69 deletions

View file

@ -40,7 +40,6 @@
#include "base/tools/Timer.h"
#include "core/config/Config.h"
#include "core/Controller.h"
#include "crypto/astrobwt/AstroBWT.h"
#include "crypto/common/Nonce.h"
#include "crypto/rx/Rx.h"
#include "version.h"
@ -67,6 +66,11 @@
#endif
#ifdef XMRIG_ALGO_ASTROBWT
# include "crypto/astrobwt/AstroBWT.h"
#endif
namespace xmrig {
@ -238,15 +242,36 @@ public:
# endif
void printHashrate(bool details)
{
char num[8 * 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);
}
LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"),
Hashrate::format(speed[0], num, sizeof(num) / 4),
Hashrate::format(speed[1], num + 8, sizeof(num) / 4),
Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ),
Hashrate::format(maxHashrate[algorithm], num + 8 * 3, sizeof(num) / 4)
);
}
# ifdef XMRIG_ALGO_RANDOMX
inline bool initRX() { return Rx::init(job, controller->config()->rx(), controller->config()->cpu()); }
# endif
# ifdef XMRIG_ALGO_ASTROBWT
inline bool initAstroBWT() { return astrobwt::init(job); }
# endif
Algorithm algorithm;
Algorithms algorithms;
bool active = false;
@ -279,6 +304,10 @@ xmrig::Miner::Miner(Controller *controller)
Rx::init(this);
# endif
# ifdef XMRIG_ALGO_ASTROBWT
astrobwt::init();
# endif
controller->addListener(this);
# ifdef XMRIG_FEATURE_API
@ -345,7 +374,7 @@ void xmrig::Miner::execCommand(char command)
switch (command) {
case 'h':
case 'H':
printHashrate(true);
d_ptr->printHashrate(true);
break;
case 'p':
@ -384,31 +413,6 @@ void xmrig::Miner::pause()
}
void xmrig::Miner::printHashrate(bool details)
{
char num[8 * 4] = { 0 };
double speed[3] = { 0.0 };
for (IBackend *backend : d_ptr->backends) {
const Hashrate *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);
}
LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"),
Hashrate::format(speed[0], num, sizeof(num) / 4),
Hashrate::format(speed[1], num + 8, sizeof(num) / 4),
Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ),
Hashrate::format(d_ptr->maxHashrate[d_ptr->algorithm], num + 8 * 3, sizeof(num) / 4)
);
}
void xmrig::Miner::setEnabled(bool enabled)
{
if (d_ptr->enabled == enabled) {
@ -459,14 +463,10 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
d_ptr->userJobId = job.id();
}
bool ready = true;
# ifdef XMRIG_ALGO_RANDOMX
ready &= d_ptr->initRX();
# endif
# ifdef XMRIG_ALGO_ASTROBWT
ready &= d_ptr->initAstroBWT();
const bool ready = d_ptr->initRX();
# else
constexpr const bool ready = true;
# endif
mutex.unlock();
@ -524,7 +524,7 @@ void xmrig::Miner::onTimer(const Timer *)
const auto printTime = d_ptr->controller->config()->printTime();
if (printTime && d_ptr->ticks && (d_ptr->ticks % (printTime * 2)) == 0) {
printHashrate(false);
d_ptr->printHashrate(false);
}
d_ptr->ticks++;

View file

@ -61,7 +61,6 @@ public:
Job job() const;
void execCommand(char command);
void pause();
void printHashrate(bool details);
void setEnabled(bool enabled);
void setJob(const Job &job, bool donate);
void stop();