From 51b4f32420e5905a752788ee391da6ff11b4ce05 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 11 Nov 2014 17:59:45 +0100 Subject: [PATCH] stats: ignore erroneous data --- stats.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/stats.cpp b/stats.cpp index e240bfc..d3504d8 100644 --- a/stats.cpp +++ b/stats.cpp @@ -17,7 +17,8 @@ struct stats_data { double hashrate; uint8_t thr_id; uint8_t gpu_id; - uint16_t align; /* to keep size a multiple of 4 */ + uint8_t ignored; + uint8_t align; /* to keep size a multiple of 4 */ }; static std::map tlastscans; @@ -25,6 +26,9 @@ static uint64_t uid = 0; #define STATS_PURGE_TIMEOUT 5*60 +extern uint64_t global_hashrate; +extern int opt_n_threads; + /** * Store speed per thread (todo: compute here) */ @@ -34,14 +38,25 @@ extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hash uint64_t key = (thr << 56) + (uid++ % UINT_MAX); stats_data data; + // to enough hashes to give right stats if (hashcount < 1000 || hashrate < 0.01) return; + // first hash rates are often erroneous + if (uid <= opt_n_threads) + return; + memset(&data, 0, sizeof(data)); data.thr_id = (uint8_t) thr; data.tm_stat = (uint32_t) time(NULL); data.hashcount = hashcount; data.hashrate = hashrate; + if (global_hashrate && uid > 10) { + // prevent stats on too high vardiff (erroneous rates) + double ratio = (hashrate / (1.0 * global_hashrate)); + if (ratio < 0.4 || ratio > 1.6) + data.ignored = 1; + } tlastscans[key] = data; } @@ -58,7 +73,8 @@ extern "C" double stats_get_speed(int thr_id) std::map::reverse_iterator i = tlastscans.rbegin(); while (i != tlastscans.rend() && records < 50) { - if ((i->first & UINT_MAX) > 3) /* ignore firsts */ + /* ignore n firsts */ + if (!i->second.ignored) if (thr_id == -1 || (keypfx & i->first) == keypfx) { if (i->second.hashcount > 1000) { speed += i->second.hashrate;