static secaddr last_pos;
static struct timeval last_time;
static double alpha = 0.1;
-static double wsum, wcount;
+static double avg = 0.0, corr = 0.0;
static int bad_err;
static const char throbber[] = "|<-<|>->";
double rate;
const char *unit;
- if (!wsum || !wcount) { rate = 0; eta = -1; }
- else { rate = wsum/wcount; eta = (int)((nsectors - ndone)/rate + 0.5); }
+ rate = avg/(1 - corr); eta = (int)((nsectors - ndone)/rate + 0.5);
rate = scale_bytes(rate*SECTORSZ, &unit);
- progress_putright(render, "ETA %s ", rate ? fmttime(eta, timebuf) : "???");
+ progress_putright(render, "ETA %s ", avg ? fmttime(eta, timebuf) : "???");
progress_putright(render, "%.1f %sB/s, ", rate, unit);
}
static void update_progress(secaddr pos)
{
struct timeval now;
- double t, f, g;
+ double t, beta_t, rate;
gettimeofday(&now, 0); t = tvdiff(&last_time, &now);
-
-#define BETA (1 - alpha)
-
if (t) {
- g = wcount ? pow(BETA, t) : 0.0; f = (1 - g)/(1 - BETA);
- wsum = f*(pos - last_pos)/t + g*wsum;
- wcount = f + g*wcount;
- ndone += pos - last_pos;
- last_time = now; last_pos = pos;
+ rate = (pos - last_pos)/t; beta_t = pow(1 - alpha, t);
+ avg = rate + beta_t*(avg - rate); corr *= beta_t;
+ ndone += pos - last_pos; last_time = now; last_pos = pos;
}
-
-#undef BETA
-
throbix++; if (!throbber[throbix]) throbix = 0;
}