Browse Source

stats: rework stats map key to fix sort order

to fix histo api command without param
master
Tanguy Pruvot 10 years ago
parent
commit
1fcdeab53b
  1. 20
      stats.cpp

20
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) 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]; const uint8_t gpu = (uint8_t) device_map[thr_id];
uint64_t key = (gpu << 56) + (uid++ % UINT32_MAX); const uint64_t key = ((uid++ % UINT32_MAX) << 32) + gpu;
stats_data data; stats_data data;
// to enough hashes to give right stats // to enough hashes to give right stats
if (hashcount < 1000 || hashrate < 0.01) if (hashcount < 1000 || hashrate < 0.01)
@ -38,7 +38,7 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8
return; return;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.gpu_id = (uint8_t)gpu; data.gpu_id = gpu;
data.thr_id = (uint8_t)thr_id; data.thr_id = (uint8_t)thr_id;
data.tm_stat = (uint32_t) time(NULL); data.tm_stat = (uint32_t) time(NULL);
data.height = height; 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) double stats_get_speed(int thr_id, double def_speed)
{ {
uint64_t gpu = device_map[thr_id]; const uint64_t gpu = device_map[thr_id];
uint64_t keypfx = (gpu << 56); const uint64_t keymsk = 0xffULL; // last u8 is the gpu
uint64_t keymsk = (0xffULL << 56);
double speed = 0.0; double speed = 0.0;
int records = 0; int records = 0;
std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin(); std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
while (i != tlastscans.rend() && records < opt_statsavg) { while (i != tlastscans.rend() && records < opt_statsavg) {
if (!i->second.ignored) 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) { if (i->second.hashcount > 1000) {
speed += i->second.hashrate; speed += i->second.hashrate;
records++; 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) int stats_get_history(int thr_id, struct stats_data *data, int max_records)
{ {
uint64_t gpu = device_map[thr_id]; const uint64_t gpu = device_map[thr_id];
uint64_t keypfx = (gpu << 56); const uint64_t keymsk = 0xffULL; // last u8 is the gpu
uint64_t keymsk = (0xffULL << 56);
double speed = 0.0; double speed = 0.0;
int records = 0; int records = 0;
std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin(); std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
while (i != tlastscans.rend() && records < max_records) { while (i != tlastscans.rend() && records < max_records) {
if (!i->second.ignored) 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)); memcpy(&data[records], &(i->second), sizeof(struct stats_data));
records++; records++;
} }

Loading…
Cancel
Save