Restored printable hashrate.
This commit is contained in:
parent
27f3008d79
commit
5699147aab
15 changed files with 196 additions and 204 deletions
164
src/backend/common/Hashrate.cpp
Normal file
164
src/backend/common/Hashrate.cpp
Normal file
|
@ -0,0 +1,164 @@
|
|||
/* 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/tools/Chrono.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "backend/common/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";
|
||||
}
|
||||
|
||||
|
||||
xmrig::Hashrate::Hashrate(size_t threads) :
|
||||
m_highest(0.0),
|
||||
m_threads(threads)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 data;
|
||||
|
||||
for (size_t i = 0; i < m_threads; ++i) {
|
||||
data = calc(i, ms);
|
||||
if (isnormal(data)) {
|
||||
result += data;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
double xmrig::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 xmrig::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 xmrig::Hashrate::updateHighest()
|
||||
{
|
||||
double highest = calc(ShortInterval);
|
||||
if (isnormal(highest) && highest > m_highest) {
|
||||
m_highest = highest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Hashrate::format(double h, char *buf, size_t size)
|
||||
{
|
||||
return ::format(h, buf, size);
|
||||
}
|
71
src/backend/common/Hashrate.h
Normal file
71
src/backend/common/Hashrate.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* 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>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Hashrate
|
||||
{
|
||||
public:
|
||||
enum Intervals {
|
||||
ShortInterval = 10000,
|
||||
MediumInterval = 60000,
|
||||
LargeInterval = 900000
|
||||
};
|
||||
|
||||
Hashrate(size_t threads);
|
||||
~Hashrate();
|
||||
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 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:
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_HASHRATE_H */
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "backend/common/Hashrate.h"
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/CpuWorker.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
@ -37,13 +38,16 @@ class WorkersPrivate
|
|||
public:
|
||||
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>
|
||||
void xmrig::Workers<T>::add(const T &data)
|
||||
{
|
||||
|
@ -75,6 +86,8 @@ void xmrig::Workers<T>::add(const T &data)
|
|||
template<class T>
|
||||
void xmrig::Workers<T>::start()
|
||||
{
|
||||
d_ptr->hashrate = new Hashrate(m_workers.size());
|
||||
|
||||
for (Thread<T> *worker : m_workers) {
|
||||
worker->start(Workers<T>::onReady);
|
||||
}
|
||||
|
@ -92,13 +105,34 @@ void xmrig::Workers<T>::stop()
|
|||
|
||||
m_workers.clear();
|
||||
Nonce::touch(T::backend());
|
||||
|
||||
delete d_ptr->hashrate;
|
||||
d_ptr->hashrate = nullptr;
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class Hashrate;
|
||||
class WorkersPrivate;
|
||||
|
||||
|
||||
|
@ -44,9 +45,11 @@ public:
|
|||
Workers();
|
||||
~Workers();
|
||||
|
||||
const Hashrate *hashrate() const;
|
||||
void add(const T &data);
|
||||
void start();
|
||||
void stop();
|
||||
void tick(uint64_t ticks);
|
||||
|
||||
private:
|
||||
static void onReady(void *arg);
|
||||
|
|
|
@ -2,6 +2,7 @@ set(HEADERS_BACKEND_COMMON
|
|||
src/backend/common/interfaces/IBackend.h
|
||||
src/backend/common/interfaces/IThread.h
|
||||
src/backend/common/interfaces/IWorker.h
|
||||
src/backend/common/Hashrate.h
|
||||
src/backend/common/Thread.h
|
||||
src/backend/common/Threads.h
|
||||
src/backend/common/Worker.h
|
||||
|
@ -10,6 +11,7 @@ set(HEADERS_BACKEND_COMMON
|
|||
)
|
||||
|
||||
set(SOURCES_BACKEND_COMMON
|
||||
src/backend/common/Hashrate.cpp
|
||||
src/backend/common/Threads.cpp
|
||||
src/backend/common/Worker.cpp
|
||||
src/backend/common/Workers.cpp
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
class Hashrate;
|
||||
class Job;
|
||||
class String;
|
||||
|
||||
|
@ -41,6 +42,7 @@ class IBackend
|
|||
public:
|
||||
virtual ~IBackend() = default;
|
||||
|
||||
virtual const Hashrate *hashrate() const = 0;
|
||||
virtual const String &profileName() const = 0;
|
||||
virtual void printHashrate(bool details) = 0;
|
||||
virtual void setJob(const Job &job) = 0;
|
||||
|
|
|
@ -23,17 +23,16 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "backend/common/Hashrate.h"
|
||||
#include "backend/common/Workers.h"
|
||||
#include "backend/cpu/CpuBackend.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
|
||||
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
return d_ptr->profileName;
|
||||
|
@ -106,7 +111,26 @@ const xmrig::String &xmrig::CpuBackend::profileName() const
|
|||
|
||||
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)
|
||||
{
|
||||
|
||||
d_ptr->workers.tick(ticks);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
~CpuBackend() override;
|
||||
|
||||
protected:
|
||||
const Hashrate *hashrate() const override;
|
||||
const String &profileName() const override;
|
||||
void printHashrate(bool details) override;
|
||||
void setJob(const Job &job) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue