Browse Source

stats: reduce the average samples count to 20

2upstream
Tanguy Pruvot 10 years ago
parent
commit
99bbe380fd
  1. 16
      stats.cpp

16
stats.cpp

@ -24,13 +24,15 @@ struct stats_data {
static std::map<uint64_t, stats_data> tlastscans; static std::map<uint64_t, stats_data> tlastscans;
static uint64_t uid = 0; static uint64_t uid = 0;
#define STATS_AVG_SAMPLES 20
#define STATS_PURGE_TIMEOUT 5*60 #define STATS_PURGE_TIMEOUT 5*60
extern uint64_t global_hashrate; extern uint64_t global_hashrate;
extern int opt_n_threads; extern int opt_n_threads;
extern int device_map[8];
/** /**
* Store speed per thread (todo: compute here) * Store speed per thread (todo: compute vardiff ?)
*/ */
extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate) extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate)
{ {
@ -43,7 +45,7 @@ extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hash
return; return;
// first hash rates are often erroneous // first hash rates are often erroneous
if (uid <= opt_n_threads) if (uid < opt_n_threads * 2)
return; return;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
@ -51,6 +53,7 @@ extern "C" void stats_remember_speed(int thr_id, uint32_t hashcount, double hash
data.tm_stat = (uint32_t) time(NULL); data.tm_stat = (uint32_t) time(NULL);
data.hashcount = hashcount; data.hashcount = hashcount;
data.hashrate = hashrate; data.hashrate = hashrate;
data.gpu_id = device_map[thr_id];
if (global_hashrate && uid > 10) { if (global_hashrate && uid > 10) {
// prevent stats on too high vardiff (erroneous rates) // prevent stats on too high vardiff (erroneous rates)
double ratio = (hashrate / (1.0 * global_hashrate)); double ratio = (hashrate / (1.0 * global_hashrate));
@ -72,8 +75,7 @@ extern "C" double stats_get_speed(int thr_id)
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 < 50) { while (i != tlastscans.rend() && records < STATS_AVG_SAMPLES) {
/* ignore n firsts */
if (!i->second.ignored) if (!i->second.ignored)
if (thr_id == -1 || (keypfx & i->first) == keypfx) { if (thr_id == -1 || (keypfx & i->first) == keypfx) {
if (i->second.hashcount > 1000) { if (i->second.hashcount > 1000) {
@ -81,7 +83,7 @@ extern "C" double stats_get_speed(int thr_id)
records++; records++;
} }
} }
i++; ++i;
} }
if (records) if (records)
speed /= (double)(records); speed /= (double)(records);
@ -98,14 +100,14 @@ extern "C" void stats_purge_old(void)
uint32_t sz = tlastscans.size(); uint32_t sz = tlastscans.size();
std::map<uint64_t, stats_data>::iterator i = tlastscans.begin(); std::map<uint64_t, stats_data>::iterator i = tlastscans.begin();
while (i != tlastscans.end()) { while (i != tlastscans.end()) {
if ((now - i->second.tm_stat) > STATS_PURGE_TIMEOUT) { if (i->second.ignored || (now - i->second.tm_stat) > STATS_PURGE_TIMEOUT) {
deleted++; deleted++;
tlastscans.erase(i++); tlastscans.erase(i++);
} }
else ++i; else ++i;
} }
if (opt_debug && deleted) { if (opt_debug && deleted) {
applog(LOG_DEBUG, "hashlog: %d/%d purged", deleted, sz); applog(LOG_DEBUG, "stats: %d/%d records purged", deleted, sz);
} }
} }

Loading…
Cancel
Save