Restored printable hashrate.

This commit is contained in:
XMRig 2019-07-17 01:28:42 +07:00
parent 27f3008d79
commit 5699147aab
15 changed files with 196 additions and 204 deletions

View file

@ -44,7 +44,6 @@ set(HEADERS
src/Summary.h src/Summary.h
src/version.h src/version.h
src/workers/CpuThreadLegacy.h src/workers/CpuThreadLegacy.h
src/workers/Hashrate.h
src/workers/WorkersLegacy.h src/workers/WorkersLegacy.h
) )
@ -92,7 +91,6 @@ set(SOURCES
src/net/strategies/DonateStrategy.cpp src/net/strategies/DonateStrategy.cpp
src/Summary.cpp src/Summary.cpp
src/workers/CpuThreadLegacy.cpp src/workers/CpuThreadLegacy.cpp
src/workers/Hashrate.cpp
src/workers/WorkersLegacy.cpp src/workers/WorkersLegacy.cpp
src/xmrig.cpp src/xmrig.cpp
) )

View file

@ -36,7 +36,7 @@
#include "core/config/Config.h" #include "core/config/Config.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "version.h" #include "version.h"
#include "workers/Hashrate.h" //#include "workers/Hashrate.h"
#include "workers/WorkersLegacy.h" #include "workers/WorkersLegacy.h"
@ -69,7 +69,7 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
if (request.url() == "/1/summary" || request.url() == "/api.json") { if (request.url() == "/1/summary" || request.url() == "/api.json") {
request.accept(); request.accept();
getMiner(request.reply(), request.doc()); getMiner(request.reply(), request.doc());
getHashrate(request.reply(), request.doc()); // getHashrate(request.reply(), request.doc());
} }
else if (request.url() == "/1/threads") { else if (request.url() == "/1/threads") {
request.accept(); request.accept();
@ -98,35 +98,35 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
} }
void xmrig::ApiRouter::getHashrate(rapidjson::Value &reply, rapidjson::Document &doc) const //void xmrig::ApiRouter::getHashrate(rapidjson::Value &reply, rapidjson::Document &doc) const
{ //{
using namespace rapidjson; // using namespace rapidjson;
auto &allocator = doc.GetAllocator(); // auto &allocator = doc.GetAllocator();
Value hashrate(kObjectType); // Value hashrate(kObjectType);
Value total(kArrayType); // Value total(kArrayType);
Value threads(kArrayType); // Value threads(kArrayType);
const Hashrate *hr = WorkersLegacy::hashrate(); // const Hashrate *hr = WorkersLegacy::hashrate();
total.PushBack(normalize(hr->calc(Hashrate::ShortInterval)), allocator); // total.PushBack(normalize(hr->calc(Hashrate::ShortInterval)), allocator);
total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator); // total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator);
total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator); // total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator);
for (size_t i = 0; i < WorkersLegacy::threads(); i++) { // for (size_t i = 0; i < WorkersLegacy::threads(); i++) {
Value thread(kArrayType); // Value thread(kArrayType);
thread.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator); // thread.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
thread.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator); // thread.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
thread.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator); // thread.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
threads.PushBack(thread, allocator); // threads.PushBack(thread, allocator);
} // }
hashrate.AddMember("total", total, allocator); // hashrate.AddMember("total", total, allocator);
hashrate.AddMember("highest", normalize(hr->highest()), allocator); // hashrate.AddMember("highest", normalize(hr->highest()), allocator);
hashrate.AddMember("threads", threads, allocator); // hashrate.AddMember("threads", threads, allocator);
reply.AddMember("hashrate", hashrate, allocator); // reply.AddMember("hashrate", hashrate, allocator);
} //}
void xmrig::ApiRouter::getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const void xmrig::ApiRouter::getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const
@ -151,29 +151,29 @@ void xmrig::ApiRouter::getMiner(rapidjson::Value &reply, rapidjson::Document &do
void xmrig::ApiRouter::getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const void xmrig::ApiRouter::getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const
{ {
using namespace rapidjson; // using namespace rapidjson;
auto &allocator = doc.GetAllocator(); // auto &allocator = doc.GetAllocator();
const Hashrate *hr = WorkersLegacy::hashrate(); // const Hashrate *hr = WorkersLegacy::hashrate();
WorkersLegacy::threadsSummary(doc); // WorkersLegacy::threadsSummary(doc);
const std::vector<IThread *> &threads = m_base->config()->threads(); // const std::vector<IThread *> &threads = m_base->config()->threads();
Value list(kArrayType); // Value list(kArrayType);
size_t i = 0; // size_t i = 0;
for (const xmrig::IThread *thread : threads) { // for (const xmrig::IThread *thread : threads) {
Value value = thread->toAPI(doc); // Value value = thread->toAPI(doc);
Value hashrate(kArrayType); // Value hashrate(kArrayType);
hashrate.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator); // hashrate.PushBack(normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
hashrate.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator); // hashrate.PushBack(normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
hashrate.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator); // hashrate.PushBack(normalize(hr->calc(i, Hashrate::LargeInterval)), allocator);
i++; // i++;
value.AddMember("hashrate", hashrate, allocator); // value.AddMember("hashrate", hashrate, allocator);
list.PushBack(value, allocator); // list.PushBack(value, allocator);
} // }
reply.AddMember("threads", list, allocator); // reply.AddMember("threads", list, allocator);
} }

View file

@ -49,7 +49,7 @@ protected:
void onRequest(IApiRequest &request) override; void onRequest(IApiRequest &request) override;
private: private:
void getHashrate(rapidjson::Value &reply, rapidjson::Document &doc) const; // void getHashrate(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const; void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const; void getThreads(rapidjson::Value &reply, rapidjson::Document &doc) const;

View file

@ -29,12 +29,9 @@
#include <stdio.h> #include <stdio.h>
#include "base/io/log/Log.h"
#include "base/tools/Chrono.h" #include "base/tools/Chrono.h"
#include "base/tools/Handle.h" #include "base/tools/Handle.h"
#include "core/config/Config.h" #include "backend/common/Hashrate.h"
#include "core/Controller.h"
#include "workers/Hashrate.h"
inline static const char *format(double h, char *buf, size_t size) inline static const char *format(double h, char *buf, size_t size)
@ -48,10 +45,9 @@ inline static const char *format(double h, char *buf, size_t size)
} }
Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) : xmrig::Hashrate::Hashrate(size_t threads) :
m_highest(0.0), m_highest(0.0),
m_threads(threads), m_threads(threads)
m_timer(nullptr)
{ {
m_counts = new uint64_t*[threads]; m_counts = new uint64_t*[threads];
m_timestamps = new uint64_t*[threads]; m_timestamps = new uint64_t*[threads];
@ -62,20 +58,23 @@ Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) :
m_timestamps[i] = new uint64_t[kBucketSize](); m_timestamps[i] = new uint64_t[kBucketSize]();
m_top[i] = 0; m_top[i] = 0;
} }
const int printTime = controller->config()->printTime();
if (printTime > 0) {
m_timer = new uv_timer_t;
uv_timer_init(uv_default_loop(), m_timer);
m_timer->data = this;
uv_timer_start(m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000);
}
} }
double Hashrate::calc(size_t ms) const xmrig::Hashrate::~Hashrate()
{
for (size_t i = 0; i < m_threads; i++) {
delete [] m_counts[i];
delete [] m_timestamps[i];
}
delete [] m_counts;
delete [] m_timestamps;
delete [] m_top;
}
double xmrig::Hashrate::calc(size_t ms) const
{ {
double result = 0.0; double result = 0.0;
double data; double data;
@ -91,7 +90,7 @@ double Hashrate::calc(size_t ms) const
} }
double Hashrate::calc(size_t threadId, size_t ms) const double xmrig::Hashrate::calc(size_t threadId, size_t ms) const
{ {
assert(threadId < m_threads); assert(threadId < m_threads);
if (threadId >= m_threads) { if (threadId >= m_threads) {
@ -140,7 +139,7 @@ double Hashrate::calc(size_t threadId, size_t ms) const
} }
void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) void xmrig::Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp)
{ {
const size_t top = m_top[threadId]; const size_t top = m_top[threadId];
m_counts[threadId][top] = count; m_counts[threadId][top] = count;
@ -150,30 +149,7 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp)
} }
void Hashrate::print() const void xmrig::Hashrate::updateHighest()
{
char num1[8] = { 0 };
char num2[8] = { 0 };
char num3[8] = { 0 };
char num4[8] = { 0 };
LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"),
format(calc(ShortInterval), num1, sizeof(num1)),
format(calc(MediumInterval), num2, sizeof(num2)),
format(calc(LargeInterval), num3, sizeof(num3)),
format(m_highest, num4, sizeof(num4))
);
}
void Hashrate::stop()
{
xmrig::Handle::close(m_timer);
m_timer = nullptr;
}
void Hashrate::updateHighest()
{ {
double highest = calc(ShortInterval); double highest = calc(ShortInterval);
if (isnormal(highest) && highest > m_highest) { if (isnormal(highest) && highest > m_highest) {
@ -182,13 +158,7 @@ void Hashrate::updateHighest()
} }
const char *Hashrate::format(double h, char *buf, size_t size) const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
{ {
return ::format(h, buf, size); return ::format(h, buf, size);
} }
void Hashrate::onReport(uv_timer_t *handle)
{
static_cast<Hashrate*>(handle->data)->print();
}

View file

@ -27,12 +27,9 @@
#include <stdint.h> #include <stdint.h>
#include <uv.h>
namespace xmrig { namespace xmrig {
class Controller;
}
class Hashrate class Hashrate
@ -44,12 +41,11 @@ public:
LargeInterval = 900000 LargeInterval = 900000
}; };
Hashrate(size_t threads, xmrig::Controller *controller); Hashrate(size_t threads);
~Hashrate();
double calc(size_t ms) const; double calc(size_t ms) const;
double calc(size_t threadId, size_t ms) const; double calc(size_t threadId, size_t ms) const;
void add(size_t threadId, uint64_t count, uint64_t timestamp); void add(size_t threadId, uint64_t count, uint64_t timestamp);
void print() const;
void stop();
void updateHighest(); void updateHighest();
inline double highest() const { return m_highest; } inline double highest() const { return m_highest; }
@ -58,8 +54,6 @@ public:
static const char *format(double h, char *buf, size_t size); static const char *format(double h, char *buf, size_t size);
private: private:
static void onReport(uv_timer_t *handle);
constexpr static size_t kBucketSize = 2 << 11; constexpr static size_t kBucketSize = 2 << 11;
constexpr static size_t kBucketMask = kBucketSize - 1; constexpr static size_t kBucketMask = kBucketSize - 1;
@ -68,8 +62,10 @@ private:
uint32_t* m_top; uint32_t* m_top;
uint64_t** m_counts; uint64_t** m_counts;
uint64_t** m_timestamps; uint64_t** m_timestamps;
uv_timer_t *m_timer;
}; };
} // namespace xmrig
#endif /* XMRIG_HASHRATE_H */ #endif /* XMRIG_HASHRATE_H */

View file

@ -24,6 +24,7 @@
*/ */
#include "backend/common/Hashrate.h"
#include "backend/common/Workers.h" #include "backend/common/Workers.h"
#include "backend/cpu/CpuWorker.h" #include "backend/cpu/CpuWorker.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
@ -37,13 +38,16 @@ class WorkersPrivate
public: public:
inline WorkersPrivate() inline WorkersPrivate()
{ {
} }
inline ~WorkersPrivate() inline ~WorkersPrivate()
{ {
delete hashrate;
} }
Hashrate *hashrate = nullptr;
}; };
@ -65,6 +69,13 @@ xmrig::Workers<T>::~Workers()
} }
template<class T>
const xmrig::Hashrate *xmrig::Workers<T>::hashrate() const
{
return d_ptr->hashrate;
}
template<class T> template<class T>
void xmrig::Workers<T>::add(const T &data) void xmrig::Workers<T>::add(const T &data)
{ {
@ -75,6 +86,8 @@ void xmrig::Workers<T>::add(const T &data)
template<class T> template<class T>
void xmrig::Workers<T>::start() void xmrig::Workers<T>::start()
{ {
d_ptr->hashrate = new Hashrate(m_workers.size());
for (Thread<T> *worker : m_workers) { for (Thread<T> *worker : m_workers) {
worker->start(Workers<T>::onReady); worker->start(Workers<T>::onReady);
} }
@ -92,13 +105,34 @@ void xmrig::Workers<T>::stop()
m_workers.clear(); m_workers.clear();
Nonce::touch(T::backend()); Nonce::touch(T::backend());
delete d_ptr->hashrate;
d_ptr->hashrate = nullptr;
} }
template<class T> template<class T>
void xmrig::Workers<T>::onReady(void *arg) void xmrig::Workers<T>::tick(uint64_t)
{
if (!d_ptr->hashrate) {
return;
}
for (Thread<T> *handle : m_workers) {
if (!handle->worker()) {
return;
}
d_ptr->hashrate->add(handle->index(), handle->worker()->hashCount(), handle->worker()->timestamp());
}
d_ptr->hashrate->updateHighest();
}
template<class T>
void xmrig::Workers<T>::onReady(void *)
{ {
printf("ON READY\n");
} }

View file

@ -34,6 +34,7 @@
namespace xmrig { namespace xmrig {
class Hashrate;
class WorkersPrivate; class WorkersPrivate;
@ -44,9 +45,11 @@ public:
Workers(); Workers();
~Workers(); ~Workers();
const Hashrate *hashrate() const;
void add(const T &data); void add(const T &data);
void start(); void start();
void stop(); void stop();
void tick(uint64_t ticks);
private: private:
static void onReady(void *arg); static void onReady(void *arg);

View file

@ -2,6 +2,7 @@ set(HEADERS_BACKEND_COMMON
src/backend/common/interfaces/IBackend.h src/backend/common/interfaces/IBackend.h
src/backend/common/interfaces/IThread.h src/backend/common/interfaces/IThread.h
src/backend/common/interfaces/IWorker.h src/backend/common/interfaces/IWorker.h
src/backend/common/Hashrate.h
src/backend/common/Thread.h src/backend/common/Thread.h
src/backend/common/Threads.h src/backend/common/Threads.h
src/backend/common/Worker.h src/backend/common/Worker.h
@ -10,6 +11,7 @@ set(HEADERS_BACKEND_COMMON
) )
set(SOURCES_BACKEND_COMMON set(SOURCES_BACKEND_COMMON
src/backend/common/Hashrate.cpp
src/backend/common/Threads.cpp src/backend/common/Threads.cpp
src/backend/common/Worker.cpp src/backend/common/Worker.cpp
src/backend/common/Workers.cpp src/backend/common/Workers.cpp

View file

@ -32,6 +32,7 @@
namespace xmrig { namespace xmrig {
class Hashrate;
class Job; class Job;
class String; class String;
@ -41,6 +42,7 @@ class IBackend
public: public:
virtual ~IBackend() = default; virtual ~IBackend() = default;
virtual const Hashrate *hashrate() const = 0;
virtual const String &profileName() const = 0; virtual const String &profileName() const = 0;
virtual void printHashrate(bool details) = 0; virtual void printHashrate(bool details) = 0;
virtual void setJob(const Job &job) = 0; virtual void setJob(const Job &job) = 0;

View file

@ -23,17 +23,16 @@
*/ */
#include "backend/common/Hashrate.h"
#include "backend/common/Workers.h" #include "backend/common/Workers.h"
#include "backend/cpu/CpuBackend.h" #include "backend/cpu/CpuBackend.h"
#include "base/io/log/Log.h"
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
#include "base/tools/String.h" #include "base/tools/String.h"
#include "core/config/Config.h" #include "core/config/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "base/io/log/Log.h"
namespace xmrig { namespace xmrig {
@ -98,6 +97,12 @@ xmrig::CpuBackend::~CpuBackend()
} }
const xmrig::Hashrate *xmrig::CpuBackend::hashrate() const
{
return d_ptr->workers.hashrate();
}
const xmrig::String &xmrig::CpuBackend::profileName() const const xmrig::String &xmrig::CpuBackend::profileName() const
{ {
return d_ptr->profileName; return d_ptr->profileName;
@ -106,7 +111,26 @@ const xmrig::String &xmrig::CpuBackend::profileName() const
void xmrig::CpuBackend::printHashrate(bool details) void xmrig::CpuBackend::printHashrate(bool details)
{ {
if (!details || !hashrate()) {
return;
}
char num[8 * 3] = { 0 };
Log::print(WHITE_BOLD_S "| CPU THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
size_t i = 0;
for (const CpuThread &thread : d_ptr->threads) {
Log::print("| %13zu | %8" PRId64 " | %7s | %7s | %7s |",
i,
thread.affinity(),
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval), num + 8, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
);
i++;
}
} }
@ -147,5 +171,5 @@ void xmrig::CpuBackend::stop()
void xmrig::CpuBackend::tick(uint64_t ticks) void xmrig::CpuBackend::tick(uint64_t ticks)
{ {
d_ptr->workers.tick(ticks);
} }

View file

@ -44,6 +44,7 @@ public:
~CpuBackend() override; ~CpuBackend() override;
protected: protected:
const Hashrate *hashrate() const override;
const String &profileName() const override; const String &profileName() const override;
void printHashrate(bool details) override; void printHashrate(bool details) override;
void setJob(const Job &job) override; void setJob(const Job &job) override;

View file

@ -26,6 +26,7 @@
#include <uv.h> #include <uv.h>
#include "backend/common/Hashrate.h"
#include "backend/cpu/CpuBackend.h" #include "backend/cpu/CpuBackend.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
@ -35,8 +36,6 @@
#include "core/Miner.h" #include "core/Miner.h"
#include "crypto/common/Nonce.h" #include "crypto/common/Nonce.h"
#include "base/tools/Chrono.h"
namespace xmrig { namespace xmrig {
@ -83,6 +82,7 @@ public:
bool active = false; bool active = false;
bool enabled = true; bool enabled = true;
Controller *controller; Controller *controller;
double maxHashrate = 0.0;
Job job; Job job;
std::vector<IBackend *> backends; std::vector<IBackend *> backends;
Timer *timer = nullptr; Timer *timer = nullptr;
@ -116,6 +116,12 @@ bool xmrig::Miner::isEnabled() const
} }
const std::vector<xmrig::IBackend *> &xmrig::Miner::backends() const
{
return d_ptr->backends;
}
xmrig::Job xmrig::Miner::job() const xmrig::Job xmrig::Miner::job() const
{ {
uv_rwlock_rdlock(&d_ptr->rwlock); uv_rwlock_rdlock(&d_ptr->rwlock);
@ -137,9 +143,26 @@ void xmrig::Miner::pause()
void xmrig::Miner::printHashrate(bool details) void xmrig::Miner::printHashrate(bool details)
{ {
char num[8 * 4] = { 0 };
double speed[3] = { 0.0 };
for (IBackend *backend : d_ptr->backends) { 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); 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, num + 8 * 3, sizeof(num) / 4)
);
} }
@ -203,10 +226,18 @@ void xmrig::Miner::stop()
void xmrig::Miner::onTimer(const Timer *) void xmrig::Miner::onTimer(const Timer *)
{ {
double maxHashrate = 0.0;
for (IBackend *backend : d_ptr->backends) { for (IBackend *backend : d_ptr->backends) {
backend->tick(d_ptr->ticks); backend->tick(d_ptr->ticks);
if (backend->hashrate()) {
maxHashrate += backend->hashrate()->calc(Hashrate::ShortInterval);
}
} }
d_ptr->maxHashrate = std::max(d_ptr->maxHashrate, maxHashrate);
if ((d_ptr->ticks % (d_ptr->controller->config()->printTime() * 2)) == 0) { if ((d_ptr->ticks % (d_ptr->controller->config()->printTime() * 2)) == 0) {
printHashrate(false); printHashrate(false);
} }

View file

@ -26,6 +26,9 @@
#define XMRIG_MINER_H #define XMRIG_MINER_H
#include <vector>
#include "base/kernel/interfaces/ITimerListener.h" #include "base/kernel/interfaces/ITimerListener.h"
@ -35,6 +38,7 @@ namespace xmrig {
class Controller; class Controller;
class Job; class Job;
class MinerPrivate; class MinerPrivate;
class IBackend;
class Miner : public ITimerListener class Miner : public ITimerListener
@ -44,6 +48,7 @@ public:
~Miner() override; ~Miner() override;
bool isEnabled() const; bool isEnabled() const;
const std::vector<IBackend *> &backends() const;
Job job() const; Job job() const;
void pause(); void pause();
void printHashrate(bool details); void printHashrate(bool details);

View file

@ -40,13 +40,13 @@
#include "crypto/rx/RxDataset.h" #include "crypto/rx/RxDataset.h"
#include "Mem.h" #include "Mem.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "workers/Hashrate.h" //#include "workers/Hashrate.h"
#include "workers/WorkersLegacy.h" #include "workers/WorkersLegacy.h"
bool WorkersLegacy::m_active = false; bool WorkersLegacy::m_active = false;
bool WorkersLegacy::m_enabled = true; bool WorkersLegacy::m_enabled = true;
Hashrate *WorkersLegacy::m_hashrate = nullptr; //Hashrate *WorkersLegacy::m_hashrate = nullptr;
xmrig::Job WorkersLegacy::m_job; xmrig::Job WorkersLegacy::m_job;
WorkersLegacy::LaunchStatus WorkersLegacy::m_status; WorkersLegacy::LaunchStatus WorkersLegacy::m_status;
std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > WorkersLegacy::m_workers; std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > WorkersLegacy::m_workers;
@ -96,38 +96,6 @@ size_t WorkersLegacy::threads()
//} //}
//void Workers::printHashrate(bool detail)
//{
// assert(m_controller != nullptr);
// if (!m_controller) {
// return;
// }
// if (detail) {
// char num1[8] = { 0 };
// char num2[8] = { 0 };
// char num3[8] = { 0 };
// xmrig::Log::print(WHITE_BOLD_S "| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |");
// size_t i = 0;
// for (const xmrig::IThread *thread : m_controller->config()->threads()) {
// xmrig::Log::print("| %6zu | %8" PRId64 " | %7s | %7s | %7s |",
// thread->index(),
// thread->affinity(),
// Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
// Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::MediumInterval), num2, sizeof num2),
// Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::LargeInterval), num3, sizeof num3)
// );
// i++;
// }
// }
// m_hashrate->print();
//}
//void Workers::setEnabled(bool enabled) //void Workers::setEnabled(bool enabled)
//{ //{
// if (m_enabled == enabled) { // if (m_enabled == enabled) {
@ -186,7 +154,7 @@ void WorkersLegacy::start(xmrig::Controller *controller)
m_status.ways += thread.intensity(); m_status.ways += thread.intensity();
} }
m_hashrate = new Hashrate(threads.size(), controller); // m_hashrate = new Hashrate(threads.size(), controller);
uv_mutex_init(&m_mutex); uv_mutex_init(&m_mutex);
uv_rwlock_init(&m_rwlock); uv_rwlock_init(&m_rwlock);
@ -238,66 +206,24 @@ void WorkersLegacy::threadsSummary(rapidjson::Document &doc)
#endif #endif
//void WorkersLegacy::onReady(void *arg) //void WorkersLegacy::onTick(uv_timer_t *)
//{ //{
// using namespace xmrig; // using namespace xmrig;
// auto handle = static_cast<Thread<CpuLaunchData>* >(arg); // for (Thread<CpuLaunchData> *handle : m_workers) {
// if (!handle->worker()) {
// return;
// }
// xmrig::IWorker *worker = nullptr; // m_hashrate->add(handle->index(), handle->worker()->hashCount(), handle->worker()->timestamp());
// switch (handle->config().intensity) {
// case 1:
// worker = new CpuWorker<1>(handle->index(), handle->config());
// break;
// case 2:
// worker = new CpuWorker<2>(handle->index(), handle->config());
// break;
// case 3:
// worker = new CpuWorker<3>(handle->index(), handle->config());
// break;
// case 4:
// worker = new CpuWorker<4>(handle->index(), handle->config());
// break;
// case 5:
// worker = new CpuWorker<5>(handle->index(), handle->config());
// break;
// } // }
// handle->setWorker(worker); // if ((m_ticks++ & 0xF) == 0) {
// m_hashrate->updateHighest();
// if (!worker->selfTest()) {
// LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
// return;
// } // }
// start(worker);
//} //}
void WorkersLegacy::onTick(uv_timer_t *)
{
using namespace xmrig;
for (Thread<CpuLaunchData> *handle : m_workers) {
if (!handle->worker()) {
return;
}
m_hashrate->add(handle->index(), handle->worker()->hashCount(), handle->worker()->timestamp());
}
if ((m_ticks++ & 0xF) == 0) {
m_hashrate->updateHighest();
}
}
void WorkersLegacy::start(xmrig::IWorker *worker) void WorkersLegacy::start(xmrig::IWorker *worker)
{ {
// const Worker *w = static_cast<const Worker *>(worker); // const Worker *w = static_cast<const Worker *>(worker);

View file

@ -42,7 +42,7 @@
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
class Hashrate; //class Hashrate;
namespace xmrig { namespace xmrig {
@ -66,7 +66,7 @@ public:
// static xmrig::Job job(); // static xmrig::Job job();
// static inline bool isEnabled() { return m_enabled; } // static inline bool isEnabled() { return m_enabled; }
static inline Hashrate *hashrate() { return m_hashrate; } // static inline Hashrate *hashrate() { return m_hashrate; }
# ifdef XMRIG_FEATURE_API # ifdef XMRIG_FEATURE_API
static void threadsSummary(rapidjson::Document &doc); static void threadsSummary(rapidjson::Document &doc);
@ -74,7 +74,7 @@ public:
private: private:
// static void onReady(void *arg); // static void onReady(void *arg);
static void onTick(uv_timer_t *handle); // static void onTick(uv_timer_t *handle);
static void start(xmrig::IWorker *worker); static void start(xmrig::IWorker *worker);
class LaunchStatus class LaunchStatus
@ -98,7 +98,7 @@ private:
static bool m_active; static bool m_active;
static bool m_enabled; static bool m_enabled;
static Hashrate *m_hashrate; // static Hashrate *m_hashrate;
static xmrig::Job m_job; static xmrig::Job m_job;
static LaunchStatus m_status; static LaunchStatus m_status;
static std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > m_workers; static std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > m_workers;