Use the suffix string function for displaying hashrate with 4 significant digits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
diff --git a/cgminer.c b/cgminer.c
index cd2c31b..4dfeef4 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1476,6 +1476,7 @@ void tailsprintf(char *f, const char *fmt, ...)
* associated suitable for Mega, Giga etc. Buf array needs to be long enough */
static void suffix_string(uint64_t val, char *buf, int sigdigits)
{
+ const double dkilo = 1000.0;
const uint64_t kilo = 1000ull;
const uint64_t mega = 1000000ull;
const uint64_t giga = 1000000000ull;
@@ -1487,26 +1488,26 @@ static void suffix_string(uint64_t val, char *buf, int sigdigits)
if (val >= exa) {
val /= peta;
- dval = (double)val / kilo;
+ dval = (double)val / dkilo;
sprintf(suffix, "E");
} else if (val >= peta) {
val /= tera;
- dval = (double)val / kilo;
+ dval = (double)val / dkilo;
sprintf(suffix, "P");
} else if (val >= tera) {
val /= giga;
- dval = (double)val / kilo;
+ dval = (double)val / dkilo;
sprintf(suffix, "T");
} else if (val >= giga) {
val /= mega;
- dval = (double)val / kilo;
+ dval = (double)val / dkilo;
sprintf(suffix, "G");
} else if (val >= mega) {
val /= kilo;
- dval = (double)val / kilo;
+ dval = (double)val / dkilo;
sprintf(suffix, "M");
} else if (val >= kilo) {
- dval = (double)val / kilo;
+ dval = (double)val / dkilo;
sprintf(suffix, "K");
} else
dval = val;
@@ -1519,26 +1520,25 @@ static void suffix_string(uint64_t val, char *buf, int sigdigits)
static void get_statline(char *buf, struct cgpu_info *cgpu)
{
- double displayed_hashes, displayed_rolling = cgpu->rolling;
- bool mhash_base = true;
+ char displayed_hashes[16], displayed_rolling[16];
+ uint64_t dh64, dr64;
- displayed_hashes = cgpu->total_mhashes / total_secs;
- if (displayed_hashes < 1) {
- displayed_hashes *= 1000;
- displayed_rolling *= 1000;
- mhash_base = false;
- }
+ dh64 = cgpu->total_mhashes / total_secs;
+ dh64 *= 1000000ull;
+ dr64 = cgpu->rolling;
+ dr64 *= 1000000ull;
+ suffix_string(dh64, displayed_hashes, 4);
+ suffix_string(dr64, displayed_rolling, 4);
sprintf(buf, "%s%d ", cgpu->api->name, cgpu->device_id);
if (cgpu->api->get_statline_before)
cgpu->api->get_statline_before(buf, cgpu);
else
tailsprintf(buf, " | ");
- tailsprintf(buf, "(%ds):%.1f (avg):%.1f %sh/s | A:%d R:%d HW:%d U:%.1f/m",
+ tailsprintf(buf, "(%ds):%s (avg):%sh/s | A:%d R:%d HW:%d U:%.1f/m",
opt_log_interval,
displayed_rolling,
displayed_hashes,
- mhash_base ? "M" : "K",
cgpu->accepted,
cgpu->rejected,
cgpu->hw_errors,
@@ -4038,9 +4038,10 @@ static void hashmeter(int thr_id, struct timeval *diff,
double utility, efficiency = 0.0;
static double local_mhashes_done = 0;
static double rolling = 0;
- double local_mhashes, displayed_hashes, displayed_rolling;
- bool mhash_base = true;
+ double local_mhashes;
bool showlog = false;
+ char displayed_hashes[16], displayed_rolling[16];
+ uint64_t dh64, dr64;
local_mhashes = (double)hashes_done / 1000000.0;
/* Update the last time this thread reported in */
@@ -4118,17 +4119,14 @@ static void hashmeter(int thr_id, struct timeval *diff,
utility = total_accepted / total_secs * 60;
efficiency = total_getworks ? total_accepted * 100.0 / total_getworks : 0.0;
- displayed_hashes = total_mhashes_done / total_secs;
- displayed_rolling = rolling;
- if (displayed_hashes < 1) {
- displayed_hashes *= 1000;
- displayed_rolling *= 1000;
- mhash_base = false;
- }
+ dh64 = (double)total_mhashes_done / total_secs * 1000000ull;
+ dr64 = (double)rolling * 1000000ull;
+ suffix_string(dh64, displayed_hashes, 4);
+ suffix_string(dr64, displayed_rolling, 4);
- sprintf(statusline, "%s(%ds):%.1f (avg):%.1f %sh/s | Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.1f/m",
+ sprintf(statusline, "%s(%ds):%s (avg):%sh/s | Q:%d A:%d R:%d HW:%d E:%.0f%% U:%.1f/m",
want_per_device_stats ? "ALL " : "",
- opt_log_interval, displayed_rolling, displayed_hashes, mhash_base ? "M" : "K",
+ opt_log_interval, displayed_rolling, displayed_hashes,
total_getworks, total_accepted, total_rejected, hw_errors, efficiency, utility);