Fix hashrate bugs
Fix the max calculation and the hashare representation.
This commit is contained in:
parent
8041771e9d
commit
9f9de78bef
1 changed files with 31 additions and 13 deletions
|
@ -21,9 +21,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define isnormal(x) (_fpclass(x) == _FPCLASS_NN || _fpclass(x) == _FPCLASS_PN)
|
||||||
|
#else
|
||||||
|
#include <math.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
#if __cplusplus <= 199711L
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#else
|
#else
|
||||||
|
#include <chrono>
|
||||||
|
#define USE_CHRONO
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <stdint.h> // portable: uint64_t MSVC: __int64
|
#include <stdint.h> // portable: uint64_t MSVC: __int64
|
||||||
|
@ -60,10 +71,15 @@ static int gettimeofday(struct timeval* tp, struct timezone* tzp)
|
||||||
#include "workers/Hashrate.h"
|
#include "workers/Hashrate.h"
|
||||||
|
|
||||||
|
|
||||||
inline const char* format(double h, char* buf, size_t size)
|
inline std::string format(const double value)
|
||||||
{
|
{
|
||||||
snprintf(buf, size, "%03.1f", h);
|
char buff[8];
|
||||||
return buf;
|
if(false == isnormal(value) && 0 != value)
|
||||||
|
{
|
||||||
|
return "n/a";
|
||||||
|
}
|
||||||
|
snprintf(buff, sizeof(buff), "%03.1f", value);
|
||||||
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,9 +130,14 @@ double Hashrate::calc(size_t ms) const
|
||||||
|
|
||||||
double Hashrate::calc(size_t threadId, size_t ms) const
|
double Hashrate::calc(size_t threadId, size_t ms) const
|
||||||
{
|
{
|
||||||
|
#ifdef USE_CHRONO
|
||||||
|
using namespace std::chrono;
|
||||||
|
const uint64_t now = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
|
||||||
|
#else
|
||||||
struct timeval tp;
|
struct timeval tp;
|
||||||
gettimeofday(&tp, NULL);
|
gettimeofday(&tp, NULL);
|
||||||
uint64_t now = tp.tv_sec * 1000 + tp.tv_usec / 1000;
|
const uint64_t now = tp.tv_sec * 1000 + tp.tv_usec / 1000;
|
||||||
|
#endif
|
||||||
|
|
||||||
uint64_t earliestHashCount = 0;
|
uint64_t earliestHashCount = 0;
|
||||||
uint64_t earliestStamp = 0;
|
uint64_t earliestStamp = 0;
|
||||||
|
@ -180,14 +201,11 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp)
|
||||||
|
|
||||||
void Hashrate::print()
|
void Hashrate::print()
|
||||||
{
|
{
|
||||||
char num1[8];
|
LOG_INFO("speed 2.5s/60s/15m " <<
|
||||||
char num2[8];
|
format(calc(ShortInterval)) << " " <<
|
||||||
char num3[8];
|
format(calc(MediumInterval)) << " " <<
|
||||||
char num4[8];
|
format(calc(LargeInterval)) << " H/s max: " <<
|
||||||
|
format(m_highest) << " H/s");
|
||||||
LOG_INFO("speed 2.5s/60s/15m " << format(calc(ShortInterval), num1,
|
|
||||||
sizeof(num1)) << " " << format(calc(MediumInterval), num2, sizeof(num2)) << " " << format(calc(LargeInterval),
|
|
||||||
num3, sizeof(num3)) << " H/s max: " << format(m_highest, num4, sizeof(num4)) << " H/s");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,7 +218,7 @@ void Hashrate::stop()
|
||||||
void Hashrate::updateHighest()
|
void Hashrate::updateHighest()
|
||||||
{
|
{
|
||||||
double highest = calc(ShortInterval);
|
double highest = calc(ShortInterval);
|
||||||
if(0 != highest && highest > m_highest)
|
if(isnormal(highest) && highest > m_highest)
|
||||||
{
|
{
|
||||||
m_highest = highest;
|
m_highest = highest;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue