feat(miner): scale displayed hashrate units dynamically

This commit is contained in:
2026-03-30 11:47:36 +02:00
parent b6af554b0c
commit 7f217df04f
4 changed files with 59 additions and 5 deletions

View File

@@ -53,6 +53,7 @@ static void dashboard_print(DashboardState *st, int n) {
long long total_attempts = 0;
time_t now_t = time(NULL);
char ts[64];
char total_rate_buf[32];
if (st->lines_printed > 0) {
clear_lines(st->lines_printed);
@@ -64,13 +65,16 @@ static void dashboard_print(DashboardState *st, int n) {
}
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", localtime(&now_t));
format_hashrate_khs(total_rate, total_rate_buf, sizeof(total_rate_buf));
printf("%s | MINING STATUS\n", ts);
printf("========================================\n");
printf("Total: %.2f kH/s | Attempts: %lld\n", total_rate, total_attempts);
printf("Total: %s | Attempts: %lld\n", total_rate_buf, total_attempts);
printf("----------------------------------------\n");
for (i = 0; i < n; i++) {
printf("Worker %-2d: %.2f kH/s | Attempts: %lld\n", i, st->rates[i], st->attempts[i]);
char worker_rate_buf[32];
format_hashrate_khs(st->rates[i], worker_rate_buf, sizeof(worker_rate_buf));
printf("Worker %-2d: %s | Attempts: %lld\n", i, worker_rate_buf, st->attempts[i]);
}
st->lines_printed = 4 + n;
@@ -228,6 +232,8 @@ static int aggregate_loop(WorkerProc *workers, int n) {
double elapsed = now_seconds() - st.start_t;
long long total_attempts = 0;
double avg_rate;
char winner_rate_buf[32];
char avg_rate_buf[32];
if (st.lines_printed > 0) {
clear_lines(st.lines_printed);
@@ -238,6 +244,7 @@ static int aggregate_loop(WorkerProc *workers, int n) {
}
avg_rate = (elapsed > 0.0) ? (double)total_attempts / elapsed / 1000.0 : 0.0;
format_hashrate_khs(avg_rate, avg_rate_buf, sizeof(avg_rate_buf));
printf("==============================================================================\n");
printf("[OK] BLOCK FOUND AND SUBMITTED\n");
@@ -246,9 +253,10 @@ static int aggregate_loop(WorkerProc *workers, int n) {
printf(" Worker: %d\n", st.winner_idx);
}
if (st.has_winner_rate) {
printf(" Worker hashrate: %.2f kH/s\n", st.winner_rate);
format_hashrate_khs(st.winner_rate, winner_rate_buf, sizeof(winner_rate_buf));
printf(" Worker hashrate: %s\n", winner_rate_buf);
}
printf(" Average total hashrate: %.2f kH/s\n", avg_rate);
printf(" Average total hashrate: %s\n", avg_rate_buf);
printf(" Total attempts: %lld\n", total_attempts);
printf("==============================================================================\n");