Add option "--print-time".

This commit is contained in:
XMRig 2017-06-16 11:08:10 +03:00
parent 4e4c54314b
commit fed163568e
5 changed files with 35 additions and 2 deletions

View file

@ -58,6 +58,15 @@ Hashrate::Hashrate(int threads) :
memset(m_counts[0], 0, sizeof(uint64_t) * kBucketSize);
memset(m_timestamps[0], 0, sizeof(uint64_t) * kBucketSize);
}
const int printTime = Options::i()->printTime();
if (printTime > 0) {
uv_timer_init(uv_default_loop(), &m_timer);
m_timer.data = this;
uv_timer_start(&m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000);
}
}
@ -159,3 +168,9 @@ void Hashrate::updateHighest()
m_highest = highest;
}
}
void Hashrate::onReport(uv_timer_t *handle)
{
static_cast<Hashrate*>(handle->data)->print();
}

View file

@ -26,6 +26,7 @@
#include <stdint.h>
#include <uv.h>
class Hashrate
@ -41,6 +42,8 @@ public:
inline double highest() const { return m_highest; }
private:
static void onReport(uv_timer_t *handle);
constexpr static size_t kBucketSize = 2 << 11;
constexpr static size_t kBucketMask = kBucketSize - 1;
@ -49,6 +52,7 @@ private:
uint32_t* m_top;
uint64_t** m_counts;
uint64_t** m_timestamps;
uv_timer_t m_timer;
};

View file

@ -27,6 +27,7 @@
#include "Console.h"
#include "interfaces/IJobResultListener.h"
#include "Mem.h"
#include "Options.h"
#include "workers/DoubleWorker.h"
#include "workers/Handle.h"
#include "workers/Hashrate.h"
@ -102,7 +103,6 @@ void Workers::submit(const JobResult &result)
}
void Workers::onReady(void *arg)
{
auto handle = static_cast<Handle*>(arg);
@ -148,6 +148,5 @@ void Workers::onTick(uv_timer_t *handle)
if ((m_ticks++ & 0xF) == 0) {
m_hashrate->updateHighest();
m_hashrate->print();
}
}