Rename --eta-window to --average-rate-window, since that is what it does, and correct the behaviour of the final update so the final rate shown is the average rate across the whole transfer.

This commit is contained in:
Andrew Wood
2023-07-16 21:00:08 +01:00
parent 62b5ac26df
commit 4fddf40436
9 changed files with 29 additions and 13 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ struct opts_s { /* structure describing run-time options */
double delay_start; /* delay before first display */
unsigned int watch_pid; /* process to watch fds of */
int watch_fd; /* fd to watch */
unsigned int eta_window; /* time window in seconds for eta calculations */
unsigned int average_rate_window; /* time window in seconds for average rate calculations */
unsigned int width; /* screen width */
unsigned int height; /* screen height */
char *name; /* process name, if any */
+1 -1
View File
@@ -93,7 +93,7 @@ extern void pv_state_name_set(pvstate_t, const char *);
extern void pv_state_format_string_set(pvstate_t, const char *);
extern void pv_state_watch_pid_set(pvstate_t, unsigned int);
extern void pv_state_watch_fd_set(pvstate_t, int);
extern void pv_state_eta_window_set(pvstate_t, int);
extern void pv_state_average_rate_window_set(pvstate_t, int);
extern void pv_state_inputfiles(pvstate_t, int, const char **);
+2 -2
View File
@@ -40,9 +40,9 @@ void display_help(void)
N_("show data transfer rate counter")},
{"-a", "--average-rate", 0,
N_("show data transfer average rate counter")},
{"-m", "--eta-window", N_("SEC"),
{"-m", "--average-rate-window", N_("SEC"),
N_
("compute ETA based on rate over past SEC seconds (default 30s)")},
("compute average rate over past SEC seconds (default 30s)")},
{"-b", "--bytes", 0,
N_("show number of bytes transferred")},
{"-T", "--buffer-percent", 0,
+1 -1
View File
@@ -206,7 +206,7 @@ int main(int argc, char **argv)
pv_state_format_string_set(state, opts->format);
pv_state_watch_pid_set(state, opts->watch_pid);
pv_state_watch_fd_set(state, opts->watch_fd);
pv_state_eta_window_set(state, opts->eta_window);
pv_state_average_rate_window_set(state, opts->average_rate_window);
pv_state_set_format(state, opts->progress, opts->timer, opts->eta,
opts->fineta, opts->rate, opts->average_rate,
+3 -3
View File
@@ -82,7 +82,7 @@ opts_t opts_parse(int argc, char **argv)
{"remote", 1, NULL, (int) 'R'},
{"pidfile", 1, NULL, (int) 'P'},
{"watchfd", 1, NULL, (int) 'd'},
{"eta-window", 1, NULL, (int) 'm'},
{"average-rate-window", 1, NULL, (int) 'm'},
{NULL, 0, NULL, 0}
};
int option_index = 0;
@@ -124,7 +124,7 @@ opts_t opts_parse(int argc, char **argv)
opts->delay_start = 0;
opts->watch_pid = 0;
opts->watch_fd = -1;
opts->eta_window = 30;
opts->average_rate_window = 30;
do {
#ifdef HAVE_GETOPT_LONG
@@ -341,7 +341,7 @@ opts_t opts_parse(int argc, char **argv)
&(opts->watch_fd));
break;
case 'm':
opts->eta_window = pv_getnum_ui(optarg);
opts->average_rate_window = pv_getnum_ui(optarg);
break;
default:
#ifdef HAVE_GETOPT_LONG
+16
View File
@@ -542,6 +542,22 @@ static char *pv__format(pvstate_t state,
update_history_avg_rate(state, total_bytes, elapsed_sec, rate);
average_rate = state->current_avg_rate;
/*
* If this is the final update at the end of the transfer, we
* recalculate the rate - and the average rate - across the whole
* period of the transfer.
*/
if (bytes_since_last < 0) {
/* Sanity check to avoid division by zero */
if (elapsed_sec < 0.000001)
elapsed_sec = 0.000001;
average_rate =
(((long double) total_bytes) -
((long double) state->initial_offset)) /
(long double) elapsed_sec;
rate = average_rate;
}
if (state->size <= 0) {
/*
* If we don't know the total size of the incoming data,
+1 -1
View File
@@ -250,7 +250,7 @@ void pv_state_watch_fd_set(pvstate_t state, int val)
state->watch_fd = val;
};
void pv_state_eta_window_set(pvstate_t state, int val)
void pv_state_average_rate_window_set(pvstate_t state, int val)
{
if (val < 1)
val = 1;