Rename Telemetry class to Hashrate.

This commit is contained in:
XMRig 2017-06-15 21:00:25 +03:00
parent d1bf9ddc3f
commit fcb7b0fb3e
6 changed files with 40 additions and 38 deletions

View file

@ -23,8 +23,8 @@ set(HEADERS
src/version.h src/version.h
src/workers/DoubleWorker.h src/workers/DoubleWorker.h
src/workers/Handle.h src/workers/Handle.h
src/workers/Hashrate.h
src/workers/SingleWorker.h src/workers/SingleWorker.h
src/workers/Telemetry.h
src/workers/Worker.h src/workers/Worker.h
src/workers/Workers.h src/workers/Workers.h
) )
@ -55,8 +55,8 @@ set(SOURCES
src/Summary.cpp src/Summary.cpp
src/workers/DoubleWorker.cpp src/workers/DoubleWorker.cpp
src/workers/Handle.cpp src/workers/Handle.cpp
src/workers/Hashrate.cpp
src/workers/SingleWorker.cpp src/workers/SingleWorker.cpp
src/workers/Telemetry.cpp
src/workers/Worker.cpp src/workers/Worker.cpp
src/workers/Workers.cpp src/workers/Workers.cpp
src/xmrig.cpp src/xmrig.cpp

View file

@ -28,9 +28,9 @@
#include <time.h> #include <time.h>
#ifdef WIN32 #ifdef WIN32
# include <winsock2.h> # include <winsock2.h>
# include <malloc.h>
# include "3rdparty/winansi.h" # include "3rdparty/winansi.h"
#endif #endif

View file

@ -23,14 +23,14 @@
#include <memory.h> #include <memory.h>
#include <math.h> #include <cmath>
#include <chrono> #include <chrono>
#include "Console.h" #include "Console.h"
#include "workers/Telemetry.h" #include "workers/Hashrate.h"
Telemetry::Telemetry(int threads) : Hashrate::Hashrate(int threads) :
m_threads(threads) m_threads(threads)
{ {
m_counts = new uint64_t*[threads]; m_counts = new uint64_t*[threads];
@ -48,7 +48,23 @@ Telemetry::Telemetry(int threads) :
} }
double Telemetry::calc(size_t threadId, size_t ms) const double Hashrate::calc(size_t ms) const
{
double result = .0;
double data;
for (int i = 0; i < m_threads; ++i) {
data = calc(i, ms);
if (std::isnormal(data)) {
result += data;
}
}
return result;
}
double Hashrate::calc(size_t threadId, size_t ms) const
{ {
using namespace std::chrono; using namespace std::chrono;
const uint64_t now = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count(); const uint64_t now = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
@ -97,7 +113,7 @@ double Telemetry::calc(size_t threadId, size_t ms) const
} }
void Telemetry::add(size_t threadId, uint64_t count, uint64_t timestamp) void 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;

View file

@ -21,17 +21,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __TELEMETRY_H__ #ifndef __HASHRATE_H__
#define __TELEMETRY_H__ #define __HASHRATE_H__
#include <stdint.h> #include <stdint.h>
class Telemetry class Hashrate
{ {
public: public:
Telemetry(int threads); Hashrate(int threads);
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);
@ -46,4 +47,4 @@ private:
}; };
#endif /* __TELEMETRY_H__ */ #endif /* __HASHRATE_H__ */

View file

@ -29,18 +29,18 @@
#include "Mem.h" #include "Mem.h"
#include "workers/DoubleWorker.h" #include "workers/DoubleWorker.h"
#include "workers/Handle.h" #include "workers/Handle.h"
#include "workers/Hashrate.h"
#include "workers/SingleWorker.h" #include "workers/SingleWorker.h"
#include "workers/Telemetry.h"
#include "workers/Workers.h" #include "workers/Workers.h"
Hashrate *Workers::m_hashrate = nullptr;
IJobResultListener *Workers::m_listener = nullptr; IJobResultListener *Workers::m_listener = nullptr;
Job Workers::m_job; Job Workers::m_job;
std::atomic<int> Workers::m_paused; std::atomic<int> Workers::m_paused;
std::atomic<uint64_t> Workers::m_sequence; std::atomic<uint64_t> Workers::m_sequence;
std::list<JobResult> Workers::m_queue; std::list<JobResult> Workers::m_queue;
std::vector<Handle*> Workers::m_workers; std::vector<Handle*> Workers::m_workers;
Telemetry *Workers::m_telemetry = nullptr;
uint64_t Workers::m_ticks = 0; uint64_t Workers::m_ticks = 0;
uv_async_t Workers::m_async; uv_async_t Workers::m_async;
uv_mutex_t Workers::m_mutex; uv_mutex_t Workers::m_mutex;
@ -72,7 +72,7 @@ void Workers::setJob(const Job &job)
void Workers::start(int64_t affinity, bool nicehash) void Workers::start(int64_t affinity, bool nicehash)
{ {
const int threads = Mem::threads(); const int threads = Mem::threads();
m_telemetry = new Telemetry(threads); m_hashrate = new Hashrate(threads);
uv_mutex_init(&m_mutex); uv_mutex_init(&m_mutex);
uv_rwlock_init(&m_rwlock); uv_rwlock_init(&m_rwlock);
@ -139,29 +139,14 @@ void Workers::onResult(uv_async_t *handle)
void Workers::onTick(uv_timer_t *handle) void Workers::onTick(uv_timer_t *handle)
{ {
for (Handle *handle : m_workers) { for (Handle *handle : m_workers) {
if (handle->worker()) { if (!handle->worker()) {
m_telemetry->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp()); return;
} }
m_hashrate->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp());
} }
if ((m_ticks++ & 0xF) == 0) { if ((m_ticks++ & 0xF) == 0) {
double hps = 0.0; LOG_NOTICE("%03.1f H/s", m_hashrate->calc(2500));
double telem;
bool normal = true;
for (Handle *handle : m_workers) {
telem = m_telemetry->calc(handle->threadId(), 2500);
if (!std::isnormal(telem)) {
normal = false;
break;
}
else {
hps += telem;
}
}
if (normal) {
LOG_NOTICE("%03.1f H/s", hps);
}
} }
} }

View file

@ -35,8 +35,8 @@
class Handle; class Handle;
class Hashrate;
class IJobResultListener; class IJobResultListener;
class Telemetry;
class Workers class Workers
@ -58,13 +58,13 @@ private:
static void onResult(uv_async_t *handle); static void onResult(uv_async_t *handle);
static void onTick(uv_timer_t *handle); static void onTick(uv_timer_t *handle);
static Hashrate *m_hashrate;
static IJobResultListener *m_listener; static IJobResultListener *m_listener;
static Job m_job; static Job m_job;
static std::atomic<int> m_paused; static std::atomic<int> m_paused;
static std::atomic<uint64_t> m_sequence; static std::atomic<uint64_t> m_sequence;
static std::list<JobResult> m_queue; static std::list<JobResult> m_queue;
static std::vector<Handle*> m_workers; static std::vector<Handle*> m_workers;
static Telemetry *m_telemetry;
static uint64_t m_ticks; static uint64_t m_ticks;
static uv_async_t m_async; static uv_async_t m_async;
static uv_mutex_t m_mutex; static uv_mutex_t m_mutex;