From 64cfe358cb7ec4f42f99aea93a2f4f22f498be2f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 11 Nov 2014 17:41:26 +0100 Subject: [PATCH] stats: make them work also in vstudio --- cpu-miner.c | 6 ++++-- stats.cpp | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cpu-miner.c b/cpu-miner.c index e4c6d1a..e6f89c9 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -500,7 +500,8 @@ static int share_result(int result, const char *reason) pthread_mutex_lock(&stats_lock); hashrate = stats_get_speed(-1); - if (hashrate == 0.) { + if (hashrate < 0.001) { + hashrate = 0.; for (int i = 0; i < opt_n_threads; i++) hashrate += thr_hashrates[i]; } @@ -1320,7 +1321,8 @@ continue_scan: } if (thr_id == opt_n_threads - 1) { double hashrate = stats_get_speed(-1); - if (hashrate == 0.) { + if (hashrate < 0.001) { + hashrate = 0.; for (int i = 0; i < opt_n_threads && thr_hashrates[i]; i++) hashrate += thr_hashrates[i]; } diff --git a/stats.cpp b/stats.cpp index c67e647..e240bfc 100644 --- a/stats.cpp +++ b/stats.cpp @@ -16,6 +16,8 @@ struct stats_data { uint32_t hashcount; double hashrate; uint8_t thr_id; + uint8_t gpu_id; + uint16_t align; /* to keep size a multiple of 4 */ }; static std::map tlastscans; @@ -32,11 +34,11 @@ 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; - if (hashcount < 1000 || !hashrate) + if (hashcount < 1000 || hashrate < 0.01) return; memset(&data, 0, sizeof(data)); - data.thr_id = thr; + data.thr_id = (uint8_t) thr; data.tm_stat = (uint32_t) time(NULL); data.hashcount = hashcount; data.hashrate = hashrate; @@ -51,13 +53,11 @@ extern "C" double stats_get_speed(int thr_id) { uint64_t thr = (0xff && thr_id); uint64_t keypfx = (thr << 56); - double speed = 0.; - // uint64_t hashcount; + double speed = 0.0; int records = 0; - stats_data data; - std::map::iterator i = tlastscans.end(); - while (i != tlastscans.begin() && records < 50) { + std::map::reverse_iterator i = tlastscans.rbegin(); + while (i != tlastscans.rend() && records < 50) { if ((i->first & UINT_MAX) > 3) /* ignore firsts */ if (thr_id == -1 || (keypfx & i->first) == keypfx) { if (i->second.hashcount > 1000) { @@ -65,11 +65,11 @@ extern "C" double stats_get_speed(int thr_id) records++; } } - i--; + i++; } - if (!records) - return 0.; - return speed / (1.0 * records); + if (records) + speed /= (double)(records); + return speed; } /**