Browse Source

hashrate: format units based on the value size

2upstream
Erik Mossberg 10 years ago committed by Tanguy Pruvot
parent
commit
c41d9e7bb6
  1. 9
      ccminer.cpp
  2. 1
      miner.h
  3. 54
      util.cpp

9
ccminer.cpp

@ -1483,9 +1483,8 @@ static void *miner_thread(void *userdata)
/* output */ /* output */
if (!opt_quiet && loopcnt) { if (!opt_quiet && loopcnt) {
sprintf(s, thr_hashrates[thr_id] >= 1e6 ? "%.0f" : "%.2f", format_hashrate(thr_hashrates[thr_id], s);
1e-3 * thr_hashrates[thr_id]); applog(LOG_INFO, "GPU #%d: %s, %s",
applog(LOG_INFO, "GPU #%d: %s, %s kH/s",
device_map[thr_id], device_name[device_map[thr_id]], s); device_map[thr_id], device_name[device_map[thr_id]], s);
} }
@ -1497,8 +1496,8 @@ static void *miner_thread(void *userdata)
hashrate += stats_get_speed(i, thr_hashrates[i]); hashrate += stats_get_speed(i, thr_hashrates[i]);
pthread_mutex_unlock(&stats_lock); pthread_mutex_unlock(&stats_lock);
if (opt_benchmark) { if (opt_benchmark) {
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", hashrate / 1000.); format_hashrate(hashrate, s);
applog(LOG_NOTICE, "Total: %s kH/s", s); applog(LOG_NOTICE, "Total: %s", s);
} }
// X-Mining-Hashrate // X-Mining-Hashrate

1
miner.h

@ -517,6 +517,7 @@ extern uint32_t gpus_intensity[MAX_GPUS];
#define CL_WHT "\x1B[01;37m" /* white */ #define CL_WHT "\x1B[01;37m" /* white */
extern void format_hashrate(double hashrate, char *output);
extern void applog(int prio, const char *fmt, ...); extern void applog(int prio, const char *fmt, ...);
void get_defconfig_path(char *out, size_t bufsize, char *argv0); void get_defconfig_path(char *out, size_t bufsize, char *argv0);
extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,

54
util.cpp

@ -173,6 +173,60 @@ void get_defconfig_path(char *out, size_t bufsize, char *argv0)
#endif #endif
} }
void format_hashrate(double hashrate, char *output)
{
char prefix;
if (hashrate < 1e3)
prefix = ' ';
else if (hashrate < 1e6)
{
prefix = 'k';
hashrate *= 1e-3;
}
else if (hashrate < 1e9)
{
prefix = 'M';
hashrate *= 1e-6;
}
else if (hashrate < 1e12)
{
prefix = 'G';
hashrate *= 1e-9;
}
else if (hashrate < 1e15)
{
prefix = 'T';
hashrate *= 1e-12;
}
else if (hashrate < 1e18)
{
prefix = 'P';
hashrate *= 1e-15;
}
else if (hashrate < 1e21)
{
prefix = 'E';
hashrate *= 1e-18;
}
else if (hashrate < 1e24)
{
prefix = 'Z';
hashrate *= 1e-21;
}
else
{
prefix = 'Y';
hashrate *= 1e-24;
}
sprintf(
output,
prefix == ' ' ? "%.0f%cH/s" : "%.2f %cH/s",
hashrate, prefix
);
}
static void databuf_free(struct data_buffer *db) static void databuf_free(struct data_buffer *db)
{ {
if (!db) if (!db)

Loading…
Cancel
Save