Browse Source

stats: make them work also in vstudio

master
Tanguy Pruvot 10 years ago
parent
commit
64cfe358cb
  1. 6
      cpu-miner.c
  2. 22
      stats.cpp

6
cpu-miner.c

@ -500,7 +500,8 @@ static int share_result(int result, const char *reason)
pthread_mutex_lock(&stats_lock); pthread_mutex_lock(&stats_lock);
hashrate = stats_get_speed(-1); hashrate = stats_get_speed(-1);
if (hashrate == 0.) { if (hashrate < 0.001) {
hashrate = 0.;
for (int i = 0; i < opt_n_threads; i++) for (int i = 0; i < opt_n_threads; i++)
hashrate += thr_hashrates[i]; hashrate += thr_hashrates[i];
} }
@ -1320,7 +1321,8 @@ continue_scan:
} }
if (thr_id == opt_n_threads - 1) { if (thr_id == opt_n_threads - 1) {
double hashrate = stats_get_speed(-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++) for (int i = 0; i < opt_n_threads && thr_hashrates[i]; i++)
hashrate += thr_hashrates[i]; hashrate += thr_hashrates[i];
} }

22
stats.cpp

@ -16,6 +16,8 @@ struct stats_data {
uint32_t hashcount; uint32_t hashcount;
double hashrate; double hashrate;
uint8_t thr_id; uint8_t thr_id;
uint8_t gpu_id;
uint16_t align; /* to keep size a multiple of 4 */
}; };
static std::map<uint64_t, stats_data> tlastscans; static std::map<uint64_t, stats_data> 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); uint64_t key = (thr << 56) + (uid++ % UINT_MAX);
stats_data data; stats_data data;
if (hashcount < 1000 || !hashrate) if (hashcount < 1000 || hashrate < 0.01)
return; return;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.thr_id = thr; data.thr_id = (uint8_t) thr;
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;
@ -51,13 +53,11 @@ extern "C" double stats_get_speed(int thr_id)
{ {
uint64_t thr = (0xff && thr_id); uint64_t thr = (0xff && thr_id);
uint64_t keypfx = (thr << 56); uint64_t keypfx = (thr << 56);
double speed = 0.; double speed = 0.0;
// uint64_t hashcount;
int records = 0; int records = 0;
stats_data data;
std::map<uint64_t, stats_data>::iterator i = tlastscans.end(); std::map<uint64_t, stats_data>::reverse_iterator i = tlastscans.rbegin();
while (i != tlastscans.begin() && records < 50) { while (i != tlastscans.rend() && records < 50) {
if ((i->first & UINT_MAX) > 3) /* ignore firsts */ if ((i->first & UINT_MAX) > 3) /* ignore firsts */
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) {
@ -65,11 +65,11 @@ extern "C" double stats_get_speed(int thr_id)
records++; records++;
} }
} }
i--; i++;
} }
if (!records) if (records)
return 0.; speed /= (double)(records);
return speed / (1.0 * records); return speed;
} }
/** /**

Loading…
Cancel
Save