Use direct access to hashrate in API.
This commit is contained in:
parent
b32ec5342e
commit
c221bf09f6
8 changed files with 26 additions and 61 deletions
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <chrono>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
@ -45,7 +46,7 @@ inline const char *format(double h, char* buf, size_t size)
|
|||
}
|
||||
|
||||
|
||||
Hashrate::Hashrate(int threads, xmrig::Controller *controller) :
|
||||
Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) :
|
||||
m_highest(0.0),
|
||||
m_threads(threads),
|
||||
m_controller(controller)
|
||||
|
@ -54,13 +55,10 @@ Hashrate::Hashrate(int threads, xmrig::Controller *controller) :
|
|||
m_timestamps = new uint64_t*[threads];
|
||||
m_top = new uint32_t[threads];
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
m_counts[i] = new uint64_t[kBucketSize];
|
||||
m_timestamps[i] = new uint64_t[kBucketSize];
|
||||
m_top[i] = 0;
|
||||
|
||||
memset(m_counts[0], 0, sizeof(uint64_t) * kBucketSize);
|
||||
memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize);
|
||||
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();
|
||||
|
@ -79,7 +77,7 @@ double Hashrate::calc(size_t ms) const
|
|||
double result = 0.0;
|
||||
double data;
|
||||
|
||||
for (int i = 0; i < m_threads; ++i) {
|
||||
for (size_t i = 0; i < m_threads; ++i) {
|
||||
data = calc(i, ms);
|
||||
if (isnormal(data)) {
|
||||
result += data;
|
||||
|
@ -92,6 +90,8 @@ double Hashrate::calc(size_t ms) const
|
|||
|
||||
double Hashrate::calc(size_t threadId, size_t ms) const
|
||||
{
|
||||
assert(threadId < m_threads);
|
||||
|
||||
using namespace std::chrono;
|
||||
const uint64_t now = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
LargeInterval = 900000
|
||||
};
|
||||
|
||||
Hashrate(int threads, xmrig::Controller *controller);
|
||||
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);
|
||||
|
@ -52,7 +52,7 @@ public:
|
|||
void updateHighest();
|
||||
|
||||
inline double highest() const { return m_highest; }
|
||||
inline int threads() const { return m_threads; }
|
||||
inline size_t threads() const { return m_threads; }
|
||||
|
||||
private:
|
||||
static void onReport(uv_timer_t *handle);
|
||||
|
@ -61,7 +61,7 @@ private:
|
|||
constexpr static size_t kBucketMask = kBucketSize - 1;
|
||||
|
||||
double m_highest;
|
||||
int m_threads;
|
||||
size_t m_threads;
|
||||
uint32_t* m_top;
|
||||
uint64_t** m_counts;
|
||||
uint64_t** m_timestamps;
|
||||
|
|
|
@ -243,10 +243,6 @@ void Workers::onTick(uv_timer_t *handle)
|
|||
if ((m_ticks++ & 0xF) == 0) {
|
||||
m_hashrate->updateHighest();
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
Api::tick(m_hashrate);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ public:
|
|||
static inline bool isEnabled() { return m_enabled; }
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||
static inline Hashrate *hashrate() { return m_hashrate; }
|
||||
static inline size_t threads() { return m_status.threads; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_active = false; m_paused = 1; m_sequence++; }
|
||||
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue