From 4e4c54314bcb36cbb68f88ec515b597fd29a006f Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 16 Jun 2017 10:19:14 +0300 Subject: [PATCH] New hashtable report. --- src/net/Network.cpp | 12 ++++++++--- src/workers/Hashrate.cpp | 44 +++++++++++++++++++++++++++++++++++++--- src/workers/Hashrate.h | 5 +++++ src/workers/Workers.cpp | 3 ++- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 448f1ebb..20480eca 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -107,7 +107,13 @@ void Network::onJobReceived(Client *client, const Job &job) void Network::onJobResult(const JobResult &result) { - LOG_NOTICE("SHARE FOUND"); + if (m_options->colors()) { + LOG_NOTICE("\x1B[01;32mSHARE FOUND"); + } + else { + LOG_NOTICE("SHARE FOUND"); + } + m_pools[result.poolId]->submit(result); } @@ -156,8 +162,8 @@ void Network::addPool(const Url *url) void Network::setJob(Client *client, const Job &job) { - if (m_options->colors()){ - LOG_INFO("\x1B[01;33mnew job\x1B[0m from \"%s:%d\", diff: %d", client->host(), client->port(), job.diff()); + if (m_options->colors()) { + LOG_INFO("\x1B[01;35mnew job\x1B[0m from \"%s:%d\", diff: %d", client->host(), client->port(), job.diff()); } else { diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 3a6cbda2..53443c95 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -22,15 +22,28 @@ */ -#include -#include #include +#include +#include #include "Console.h" +#include "Options.h" #include "workers/Hashrate.h" +inline const char *format(double h, char* buf, size_t size) +{ + if (std::isnormal(h)) { + snprintf(buf, size, "%03.1f", h); + return buf; + } + + return "n/a"; +} + + Hashrate::Hashrate(int threads) : + m_highest(0.0), m_threads(threads) { m_counts = new uint64_t*[threads]; @@ -50,7 +63,7 @@ Hashrate::Hashrate(int threads) : double Hashrate::calc(size_t ms) const { - double result = .0; + double result = 0.0; double data; for (int i = 0; i < m_threads; ++i) { @@ -121,3 +134,28 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) m_top[threadId] = (top + 1) & kBucketMask; } + + +void Hashrate::print() +{ + char num1[8]; + char num2[8]; + char num3[8]; + char num4[8]; + + LOG_INFO(Options::i()->colors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m highest: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s highest: %s H/s", + format(calc(2500), num1, sizeof(num1)), + format(calc(60000), num2, sizeof(num2)), + format(calc(900000), num3, sizeof(num3)), + format(m_highest, num4, sizeof(num4)) + ); +} + + +void Hashrate::updateHighest() +{ + double highest = calc(2500); + if (std::isnormal(highest) && highest > m_highest) { + m_highest = highest; + } +} diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index b225e1ca..c6f3cf27 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -35,11 +35,16 @@ public: 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(); + void updateHighest(); + + inline double highest() const { return m_highest; } private: constexpr static size_t kBucketSize = 2 << 11; constexpr static size_t kBucketMask = kBucketSize - 1; + double m_highest; int m_threads; uint32_t* m_top; uint64_t** m_counts; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 592bc17d..de3f7a0e 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -147,6 +147,7 @@ void Workers::onTick(uv_timer_t *handle) } if ((m_ticks++ & 0xF) == 0) { - LOG_NOTICE("%03.1f H/s", m_hashrate->calc(2500)); + m_hashrate->updateHighest(); + m_hashrate->print(); } }