Use direct access to hashrate in API.

This commit is contained in:
XMRig 2018-04-17 10:29:37 +07:00
parent b32ec5342e
commit c221bf09f6
8 changed files with 26 additions and 61 deletions

View file

@ -47,6 +47,7 @@
#include "rapidjson/stringbuffer.h"
#include "version.h"
#include "workers/Hashrate.h"
#include "workers/Workers.h"
extern "C"
@ -68,10 +69,6 @@ static inline double normalize(double d)
ApiRouter::ApiRouter(xmrig::Controller *controller) :
m_controller(controller)
{
m_threads = controller->config()->threadsCount();
m_hashrate = new double[m_threads * 3]();
memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
memset(m_workerId, 0, sizeof(m_workerId));
setWorkerId(controller->config()->apiWorkerId());
@ -81,7 +78,6 @@ ApiRouter::ApiRouter(xmrig::Controller *controller) :
ApiRouter::~ApiRouter()
{
delete [] m_hashrate;
}
@ -129,21 +125,6 @@ void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply)
}
void ApiRouter::tick(const Hashrate *hashrate)
{
for (int i = 0; i < m_threads; ++i) {
m_hashrate[i * 3] = hashrate->calc((size_t) i, Hashrate::ShortInterval);
m_hashrate[i * 3 + 1] = hashrate->calc((size_t) i, Hashrate::MediumInterval);
m_hashrate[i * 3 + 2] = hashrate->calc((size_t) i, Hashrate::LargeInterval);
}
m_totalHashrate[0] = hashrate->calc(Hashrate::ShortInterval);
m_totalHashrate[1] = hashrate->calc(Hashrate::MediumInterval);
m_totalHashrate[2] = hashrate->calc(Hashrate::LargeInterval);
m_highestHashrate = hashrate->highest();
}
void ApiRouter::tick(const NetworkState &network)
{
m_network = network;
@ -225,21 +206,23 @@ void ApiRouter::getHashrate(rapidjson::Document &doc) const
rapidjson::Value total(rapidjson::kArrayType);
rapidjson::Value threads(rapidjson::kArrayType);
for (int i = 0; i < 3; ++i) {
total.PushBack(normalize(m_totalHashrate[i]), allocator);
}
const Hashrate *hr = Workers::hashrate();
for (int i = 0; i < m_threads * 3; i += 3) {
total.PushBack(normalize(hr->calc(Hashrate::ShortInterval)), allocator);
total.PushBack(normalize(hr->calc(Hashrate::MediumInterval)), allocator);
total.PushBack(normalize(hr->calc(Hashrate::LargeInterval)), allocator);
for (size_t i = 0; i < Workers::threads(); i++) {
rapidjson::Value thread(rapidjson::kArrayType);
thread.PushBack(normalize(m_hashrate[i]), allocator);
thread.PushBack(normalize(m_hashrate[i + 1]), allocator);
thread.PushBack(normalize(m_hashrate[i + 2]), 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::LargeInterval)), allocator);
threads.PushBack(thread, allocator);
}
hashrate.AddMember("total", total, allocator);
hashrate.AddMember("highest", normalize(m_highestHashrate), allocator);
hashrate.AddMember("total", total, allocator);
hashrate.AddMember("highest", normalize(hr->highest()), allocator);
hashrate.AddMember("threads", threads, allocator);
doc.AddMember("hashrate", hashrate, allocator);
}