From 1fcdeab53bd75d8f4e0f83ed1697cacec453e1cb Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 23 Nov 2014 08:07:18 +0100 Subject: [PATCH] stats: rework stats map key to fix sort order to fix histo api command without param --- stats.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/stats.cpp b/stats.cpp index b4673dd..2ce9e44 100644 --- a/stats.cpp +++ b/stats.cpp @@ -26,8 +26,8 @@ extern int device_map[8]; */ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found, uint32_t height) { - uint64_t gpu = device_map[thr_id]; - uint64_t key = (gpu << 56) + (uid++ % UINT32_MAX); + const uint8_t gpu = (uint8_t) device_map[thr_id]; + const uint64_t key = ((uid++ % UINT32_MAX) << 32) + gpu; stats_data data; // to enough hashes to give right stats if (hashcount < 1000 || hashrate < 0.01) @@ -38,7 +38,7 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8 return; memset(&data, 0, sizeof(data)); - data.gpu_id = (uint8_t)gpu; + data.gpu_id = gpu; data.thr_id = (uint8_t)thr_id; data.tm_stat = (uint32_t) time(NULL); data.height = height; @@ -61,16 +61,15 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8 */ double stats_get_speed(int thr_id, double def_speed) { - uint64_t gpu = device_map[thr_id]; - uint64_t keypfx = (gpu << 56); - uint64_t keymsk = (0xffULL << 56); + const uint64_t gpu = device_map[thr_id]; + const uint64_t keymsk = 0xffULL; // last u8 is the gpu double speed = 0.0; int records = 0; std::map::reverse_iterator i = tlastscans.rbegin(); while (i != tlastscans.rend() && records < opt_statsavg) { if (!i->second.ignored) - if (thr_id == -1 || (keymsk & i->first) == keypfx) { + if (thr_id == -1 || (keymsk & i->first) == gpu) { if (i->second.hashcount > 1000) { speed += i->second.hashrate; records++; @@ -93,16 +92,15 @@ double stats_get_speed(int thr_id, double def_speed) int stats_get_history(int thr_id, struct stats_data *data, int max_records) { - uint64_t gpu = device_map[thr_id]; - uint64_t keypfx = (gpu << 56); - uint64_t keymsk = (0xffULL << 56); + const uint64_t gpu = device_map[thr_id]; + const uint64_t keymsk = 0xffULL; // last u8 is the gpu double speed = 0.0; int records = 0; std::map::reverse_iterator i = tlastscans.rbegin(); while (i != tlastscans.rend() && records < max_records) { if (!i->second.ignored) - if (thr_id == -1 || (keymsk & i->first) == keypfx) { + if (thr_id == -1 || (keymsk & i->first) == gpu) { memcpy(&data[records], &(i->second), sizeof(struct stats_data)); records++; }