Fix hashrate

Calc the correct hash rate
This commit is contained in:
enWILLYado 2018-02-26 21:35:32 +01:00
parent b7c89a214a
commit 373129a7e8
2 changed files with 64 additions and 4 deletions

View file

@ -21,8 +21,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _WIN32
#include <sys/time.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdint.h> // portable: uint64_t MSVC: __int64
#include <WinSock2.h>
#include <time.h>
static int gettimeofday(struct timeval* tp, struct timezone* tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1970
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime) ;
time += ((uint64_t)file_time.dwHighDateTime) << 32;
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
return 0;
}
#endif
#include <math.h>
#include <memory.h>
@ -87,7 +114,9 @@ double Hashrate::calc(size_t ms) const
double Hashrate::calc(size_t threadId, size_t ms) const
{
const uint64_t now = time(NULL);
struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t now = tp.tv_sec * 1000 + tp.tv_usec / 1000;
uint64_t earliestHashCount = 0;
uint64_t earliestStamp = 0;

View file

@ -27,7 +27,35 @@
#include "workers/Handle.h"
#include "workers/Worker.h"
#include <time.h>
#ifndef _WIN32
#include <sys/time.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdint.h> // portable: uint64_t MSVC: __int64
#include <WinSock2.h>
static int gettimeofday(struct timeval* tp, struct timezone* tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1970
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime) ;
time += ((uint64_t)file_time.dwHighDateTime) << 32;
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
return 0;
}
#endif
Worker::Worker(Handle* handle) :
m_id(handle->threadId()),
@ -54,7 +82,10 @@ Worker::~Worker()
void Worker::storeStats()
{
const uint64_t timestamp = time(NULL);
struct timeval tp;
gettimeofday(&tp, NULL);
uint64_t timestamp = tp.tv_sec * 1000 + tp.tv_usec / 1000;
m_hashCount = m_count;
m_timestamp = timestamp;
}