diff --git a/src/main/help.c b/src/main/help.c index 7d9da6f..103e49c 100644 --- a/src/main/help.c +++ b/src/main/help.c @@ -41,7 +41,8 @@ void display_help(void) {"-a", "--average-rate", 0, N_("show data transfer average rate counter")}, {"-m", "--eta-window", N_("SEC"), - N_("compute current average rate over a SEC seconds window for ETA (default 30s)")}, + N_ + ("compute ETA based on rate over past SEC seconds (default 30s)")}, {"-b", "--bytes", 0, N_("show number of bytes transferred")}, {"-T", "--buffer-percent", 0, diff --git a/src/pv/display.c b/src/pv/display.c index 53ea989..6cba6b7 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -103,7 +103,7 @@ static long pv__calc_eta(const long long so_far, const long long total, { long long amount_left; - if (so_far < 1 || !rate) + if ((so_far < 1) || (0 == rate)) return 0; amount_left = (total - so_far) / rate; @@ -434,29 +434,30 @@ static long bound_long(long x, long min, long max) /* Update history and current average rate */ static void update_history_avg_rate(pvstate_t state, long long total_bytes, - long double elapsed_sec, long double rate) + long double elapsed_sec, + long double rate) { int first = state->history_first; int last = state->history_last; long double last_elapsed = state->history[last].elapsed_sec; - if (!(last_elapsed == 0.0 || /* Empty */ + if (!(last_elapsed == 0.0 || /* Empty */ elapsed_sec > last_elapsed + state->history_interval)) return; - - if (last_elapsed) { /* Not empty, add new entry in circular buffer */ + + if (last_elapsed) { /* Not empty, add new entry in circular buffer */ int len = state->history_len; state->history_last = last = (last + 1) % len; if (last == first) state->history_first = first = (first + 1) % len; } - + state->history[last].elapsed_sec = elapsed_sec; state->history[last].total_bytes = total_bytes; - - if (first == last) + + if (first == last) { state->current_avg_rate = rate; - else { + } else { long long bytes = (state->history[last].total_bytes - state->history[first].total_bytes); long double sec = (state->history[last].elapsed_sec - diff --git a/src/pv/loop.c b/src/pv/loop.c index 949ba5f..8aa0625 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -156,7 +156,9 @@ int pv_main_loop(pvstate_t state) ((long double) (state->rate_limit)) / (long double) (1000000 / RATE_GRANULARITY); - long double burstMax = ((long double) (state->rate_limit * RATE_BURST_WINDOW)); + long double burstMax = + ((long double) (state->rate_limit * + RATE_BURST_WINDOW)); if (target > burstMax) { target = burstMax; } diff --git a/src/pv/state.c b/src/pv/state.c index d0b76ac..1d05f93 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -16,13 +16,14 @@ static void pv_alloc_history(pvstate_t state) { if (state->history) free(state->history); - + assert(state->history_len); assert(state->history_interval); - state->history = calloc(state->history_len, sizeof(state->history[0])); + state->history = + calloc(state->history_len, sizeof(state->history[0])); state->history_first = state->history_last = 0; - state->history[0].elapsed_sec = 0.0; /* to be safe, memset() not recommended for doubles */ + state->history[0].elapsed_sec = 0.0; /* to be safe, memset() not recommended for doubles */ } /* @@ -88,7 +89,7 @@ void pv_state_free(pvstate_t state) if (state->history) free(state->history); state->history = NULL; - + free(state); return; @@ -249,8 +250,7 @@ void pv_state_eta_window_set(pvstate_t state, int val) if (val >= 20) { state->history_len = val / 5 + 1; state->history_interval = 5; - } - else { + } else { state->history_len = val + 1; state->history_interval = 1; }