Browse Source

hashrate: Remove some extra units and allow 4 digits

to keep current X11 output (sample: 2950.01 kH/s)
2upstream
Tanguy Pruvot 10 years ago
parent
commit
81fd04a208
  1. 6
      ccminer.cpp
  2. 41
      util.cpp

6
ccminer.cpp

@ -528,7 +528,7 @@ static void calc_diff(struct work *work, int known)
static int share_result(int result, const char *reason) static int share_result(int result, const char *reason)
{ {
char s[345]; char s[32] = { 0 };
double hashrate = 0.; double hashrate = 0.;
pthread_mutex_lock(&stats_lock); pthread_mutex_lock(&stats_lock);
@ -542,8 +542,8 @@ static int share_result(int result, const char *reason)
global_hashrate = llround(hashrate); global_hashrate = llround(hashrate);
sprintf(s, hashrate >= 1e6 ? "%.0f" : "%.2f", 1e-3 * hashrate); format_hashrate(hashrate, s);
applog(LOG_NOTICE, "accepted: %lu/%lu (%.2f%%), %s khash/s %s", applog(LOG_NOTICE, "accepted: %lu/%lu (%.2f%%), %s %s",
accepted_count, accepted_count,
accepted_count + rejected_count, accepted_count + rejected_count,
100. * accepted_count / (accepted_count + rejected_count), 100. * accepted_count / (accepted_count + rejected_count),

41
util.cpp

@ -175,54 +175,31 @@ void get_defconfig_path(char *out, size_t bufsize, char *argv0)
void format_hashrate(double hashrate, char *output) void format_hashrate(double hashrate, char *output)
{ {
char prefix; char prefix = '\0';
if (hashrate < 1e3) if (hashrate < 10000) {
prefix = ' '; // nop
else if (hashrate < 1e6) }
{ else if (hashrate < 1e7) {
prefix = 'k'; prefix = 'k';
hashrate *= 1e-3; hashrate *= 1e-3;
} }
else if (hashrate < 1e9) else if (hashrate < 1e10) {
{
prefix = 'M'; prefix = 'M';
hashrate *= 1e-6; hashrate *= 1e-6;
} }
else if (hashrate < 1e12) else if (hashrate < 1e13) {
{
prefix = 'G'; prefix = 'G';
hashrate *= 1e-9; hashrate *= 1e-9;
} }
else if (hashrate < 1e15) else {
{
prefix = 'T'; prefix = 'T';
hashrate *= 1e-12; 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( sprintf(
output, output,
prefix == ' ' ? "%.0f%cH/s" : "%.2f %cH/s", prefix ? "%.2f %cH/s" : "%.2f H/s%c",
hashrate, prefix hashrate, prefix
); );
} }

Loading…
Cancel
Save