diff --git a/doc/quickref.1.in b/doc/quickref.1.in index 823507f..ab54171 100644 --- a/doc/quickref.1.in +++ b/doc/quickref.1.in @@ -143,7 +143,7 @@ transfer. .TP .B \-a, \-\-average\-rate Turn the average rate counter on. This will display the current average -rate of data transfer (default: last 30s). +rate of data transfer (default: last 30s, see --eta-window). .TP .B \-b, \-\-bytes Turn the total byte counter on. This will display the total amount of @@ -265,6 +265,11 @@ Wait seconds between updates. The default is to update every second. Note that this can be a decimal such as 0.1. .TP +.B \-m SEC, \-\-eta-window SEC +Compute current average rate over a +.B SEC +seconds window for ETA calculation (default 30s). +.TP .B \-w WIDTH, \-\-width WIDTH Assume the terminal is .B WIDTH diff --git a/src/include/options.h b/src/include/options.h index 90d8f85..9de9e68 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -42,6 +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 width; /* screen width */ unsigned int height; /* screen height */ char *name; /* process name, if any */ diff --git a/src/include/pv.h b/src/include/pv.h index cde7d08..26130e9 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -93,6 +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_inputfiles(pvstate_t, int, const char **); diff --git a/src/main/help.c b/src/main/help.c index 2ebab41..7d9da6f 100644 --- a/src/main/help.c +++ b/src/main/help.c @@ -40,6 +40,8 @@ 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"), + N_("compute current average rate over a SEC seconds window for ETA (default 30s)")}, {"-b", "--bytes", 0, N_("show number of bytes transferred")}, {"-T", "--buffer-percent", 0, diff --git a/src/main/main.c b/src/main/main.c index 75fbae2..5e0f75f 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -206,6 +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_set_format(state, opts->progress, opts->timer, opts->eta, opts->fineta, opts->rate, opts->average_rate, diff --git a/src/main/options.c b/src/main/options.c index 0d370ed..35e501d 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -80,12 +80,13 @@ 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'}, {NULL, 0, NULL, 0} }; int option_index = 0; #endif char *short_options = - "hVpteIrabTA:fnqcWD:s:l0i:w:H:N:F:L:B:CESR:P:d:"; + "hVpteIrabTA:fnqcWD:s:l0i:w:H:N:F:L:B:CESR:P:d:m:"; int c, numopts; unsigned int check_pid; int check_fd; @@ -121,6 +122,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; do { #ifdef HAVE_GETOPT_LONG @@ -144,6 +146,7 @@ opts_t opts_parse(int argc, char **argv) case 'L': case 'B': case 'R': + case 'm': if (pv_getnum_check(optarg, PV_NUMTYPE_INTEGER) != 0) { fprintf(stderr, "%s: -%c: %s\n", @@ -310,6 +313,9 @@ opts_t opts_parse(int argc, char **argv) (void) sscanf(optarg, "%u:%d", &(opts->watch_pid), &(opts->watch_fd)); break; + case 'm': + opts->eta_window = pv_getnum_ui(optarg); + break; default: #ifdef HAVE_GETOPT_LONG fprintf(stderr, diff --git a/src/pv/state.c b/src/pv/state.c index ed9ff7f..96c27b7 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -51,10 +51,6 @@ pvstate_t pv_state_alloc(const char *program_name) #endif /* HAVE_SPLICE */ state->display_visible = false; - state->history_len = 30+1; /* default history for current avg rate */ - state->history_interval = 1; - pv_alloc_history(state); - return state; } @@ -234,6 +230,19 @@ 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) +{ + if (val >= 20) { + state->history_len = val / 5 + 1; + state->history_interval = 5; + } + else { + state->history_len = val + 1; + state->history_interval = 1; + } + pv_alloc_history(state); +}; + /* * Set the array of input files.