Restored printable hashrate.
This commit is contained in:
parent
27f3008d79
commit
5699147aab
15 changed files with 196 additions and 204 deletions
|
@ -1,194 +0,0 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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 <assert.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "workers/Hashrate.h"
|
||||
|
||||
|
||||
inline static const char *format(double h, char *buf, size_t size)
|
||||
{
|
||||
if (isnormal(h)) {
|
||||
snprintf(buf, size, "%03.1f", h);
|
||||
return buf;
|
||||
}
|
||||
|
||||
return "n/a";
|
||||
}
|
||||
|
||||
|
||||
Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) :
|
||||
m_highest(0.0),
|
||||
m_threads(threads),
|
||||
m_timer(nullptr)
|
||||
{
|
||||
m_counts = new uint64_t*[threads];
|
||||
m_timestamps = new uint64_t*[threads];
|
||||
m_top = new uint32_t[threads];
|
||||
|
||||
for (size_t i = 0; i < threads; i++) {
|
||||
m_counts[i] = new uint64_t[kBucketSize]();
|
||||
m_timestamps[i] = new uint64_t[kBucketSize]();
|
||||
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
|
||||
{
|
||||
double result = 0.0;
|
||||
double data;
|
||||
|
||||
for (size_t i = 0; i < m_threads; ++i) {
|
||||
data = calc(i, ms);
|
||||
if (isnormal(data)) {
|
||||
result += data;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
double Hashrate::calc(size_t threadId, size_t ms) const
|
||||
{
|
||||
assert(threadId < m_threads);
|
||||
if (threadId >= m_threads) {
|
||||
return nan("");
|
||||
}
|
||||
|
||||
uint64_t earliestHashCount = 0;
|
||||
uint64_t earliestStamp = 0;
|
||||
uint64_t lastestStamp = 0;
|
||||
uint64_t lastestHashCnt = 0;
|
||||
bool haveFullSet = false;
|
||||
|
||||
for (size_t i = 1; i < kBucketSize; i++) {
|
||||
const size_t idx = (m_top[threadId] - i) & kBucketMask;
|
||||
|
||||
if (m_timestamps[threadId][idx] == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (lastestStamp == 0) {
|
||||
lastestStamp = m_timestamps[threadId][idx];
|
||||
lastestHashCnt = m_counts[threadId][idx];
|
||||
}
|
||||
|
||||
if (xmrig::Chrono::highResolutionMSecs() - m_timestamps[threadId][idx] > ms) {
|
||||
haveFullSet = true;
|
||||
break;
|
||||
}
|
||||
|
||||
earliestStamp = m_timestamps[threadId][idx];
|
||||
earliestHashCount = m_counts[threadId][idx];
|
||||
}
|
||||
|
||||
if (!haveFullSet || earliestStamp == 0 || lastestStamp == 0) {
|
||||
return nan("");
|
||||
}
|
||||
|
||||
if (lastestStamp - earliestStamp == 0) {
|
||||
return nan("");
|
||||
}
|
||||
|
||||
const double hashes = static_cast<double>(lastestHashCnt - earliestHashCount);
|
||||
const double time = static_cast<double>(lastestStamp - earliestStamp) / 1000.0;
|
||||
|
||||
return hashes / time;
|
||||
}
|
||||
|
||||
|
||||
void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp)
|
||||
{
|
||||
const size_t top = m_top[threadId];
|
||||
m_counts[threadId][top] = count;
|
||||
m_timestamps[threadId][top] = timestamp;
|
||||
|
||||
m_top[threadId] = (top + 1) & kBucketMask;
|
||||
}
|
||||
|
||||
|
||||
void Hashrate::print() const
|
||||
{
|
||||
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);
|
||||
if (isnormal(highest) && highest > m_highest) {
|
||||
m_highest = highest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char *Hashrate::format(double h, char *buf, size_t size)
|
||||
{
|
||||
return ::format(h, buf, size);
|
||||
}
|
||||
|
||||
|
||||
void Hashrate::onReport(uv_timer_t *handle)
|
||||
{
|
||||
static_cast<Hashrate*>(handle->data)->print();
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 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_HASHRATE_H
|
||||
#define XMRIG_HASHRATE_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class Hashrate
|
||||
{
|
||||
public:
|
||||
enum Intervals {
|
||||
ShortInterval = 10000,
|
||||
MediumInterval = 60000,
|
||||
LargeInterval = 900000
|
||||
};
|
||||
|
||||
Hashrate(size_t threads, xmrig::Controller *controller);
|
||||
double calc(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 print() const;
|
||||
void stop();
|
||||
void updateHighest();
|
||||
|
||||
inline double highest() const { return m_highest; }
|
||||
inline size_t threads() const { return m_threads; }
|
||||
|
||||
static const char *format(double h, char *buf, size_t size);
|
||||
|
||||
private:
|
||||
static void onReport(uv_timer_t *handle);
|
||||
|
||||
constexpr static size_t kBucketSize = 2 << 11;
|
||||
constexpr static size_t kBucketMask = kBucketSize - 1;
|
||||
|
||||
double m_highest;
|
||||
size_t m_threads;
|
||||
uint32_t* m_top;
|
||||
uint64_t** m_counts;
|
||||
uint64_t** m_timestamps;
|
||||
uv_timer_t *m_timer;
|
||||
};
|
||||
|
||||
|
||||
#endif /* XMRIG_HASHRATE_H */
|
|
@ -40,13 +40,13 @@
|
|||
#include "crypto/rx/RxDataset.h"
|
||||
#include "Mem.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "workers/Hashrate.h"
|
||||
//#include "workers/Hashrate.h"
|
||||
#include "workers/WorkersLegacy.h"
|
||||
|
||||
|
||||
bool WorkersLegacy::m_active = false;
|
||||
bool WorkersLegacy::m_enabled = true;
|
||||
Hashrate *WorkersLegacy::m_hashrate = nullptr;
|
||||
//Hashrate *WorkersLegacy::m_hashrate = nullptr;
|
||||
xmrig::Job WorkersLegacy::m_job;
|
||||
WorkersLegacy::LaunchStatus WorkersLegacy::m_status;
|
||||
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)
|
||||
//{
|
||||
// if (m_enabled == enabled) {
|
||||
|
@ -186,7 +154,7 @@ void WorkersLegacy::start(xmrig::Controller *controller)
|
|||
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_rwlock_init(&m_rwlock);
|
||||
|
@ -238,66 +206,24 @@ void WorkersLegacy::threadsSummary(rapidjson::Document &doc)
|
|||
#endif
|
||||
|
||||
|
||||
//void WorkersLegacy::onReady(void *arg)
|
||||
//void WorkersLegacy::onTick(uv_timer_t *)
|
||||
//{
|
||||
// using namespace xmrig;
|
||||
|
||||
// auto handle = static_cast<Thread<CpuLaunchData>* >(arg);
|
||||
// for (Thread<CpuLaunchData> *handle : m_workers) {
|
||||
// if (!handle->worker()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// xmrig::IWorker *worker = nullptr;
|
||||
|
||||
// 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;
|
||||
// m_hashrate->add(handle->index(), handle->worker()->hashCount(), handle->worker()->timestamp());
|
||||
// }
|
||||
|
||||
// handle->setWorker(worker);
|
||||
|
||||
// if (!worker->selfTest()) {
|
||||
// LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
|
||||
|
||||
// return;
|
||||
// if ((m_ticks++ & 0xF) == 0) {
|
||||
// m_hashrate->updateHighest();
|
||||
// }
|
||||
|
||||
// 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)
|
||||
{
|
||||
// const Worker *w = static_cast<const Worker *>(worker);
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
class Hashrate;
|
||||
//class Hashrate;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
// static xmrig::Job job();
|
||||
|
||||
// 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
|
||||
static void threadsSummary(rapidjson::Document &doc);
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
|
||||
private:
|
||||
// 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);
|
||||
|
||||
class LaunchStatus
|
||||
|
@ -98,7 +98,7 @@ private:
|
|||
|
||||
static bool m_active;
|
||||
static bool m_enabled;
|
||||
static Hashrate *m_hashrate;
|
||||
// static Hashrate *m_hashrate;
|
||||
static xmrig::Job m_job;
|
||||
static LaunchStatus m_status;
|
||||
static std::vector<xmrig::Thread<xmrig::CpuLaunchData>* > m_workers;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue