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
@@ -5,7 +5,7 @@ UNRELEASED
* fix: add burst rate limit to transfer, so rate limits are not broken by bursty traffic (pull request [#62](https://github.com/a-j-wood/pv/pull/62) supplied by [Volodymyr Bychkovyak](https://github.com/vbychkoviak))
* feature: the "`--size`" option now accepts "`@filename`" to use the size of another file (pull request [#57](https://github.com/a-j-wood/pv/pull/57) supplied by [Dave Beckett](https://github.com/dajobe))
* feature: the "`--watchfd`" option is now available on OS X (pull request [#60](https://github.com/a-j-wood/pv/pull/60) supplied by [christoph-zededa](https://github.com/christoph-zededa))
* feature: new "`--eta-window`" option, to set the window over which the rate is checked, when calculating the ETA (pull request [#65](https://github.com/a-j-wood/pv/pull/65) supplied by [lemonsqueeze](https://github.com/lemonsqueeze))
* feature: new "`--average-rate-window`" option, to set the window over which the average rate is calculated, also used for ETA (modified from pull request [#65](https://github.com/a-j-wood/pv/pull/65) supplied by [lemonsqueeze](https://github.com/lemonsqueeze))
* feature: the "`--watchfd`" option will now show relative filenames, if they are under the current directory (pull request [#66](https://github.com/a-j-wood/pv/pull/66) supplied by [ikasty](https://github.com/ikasty))
* docs: moved all open issues into GitHub and updated the TODO list
* docs: renamed README to README.md and altered it to Markdown format
+3 -3
View File
@@ -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, see --eta-window).
rate of data transfer (default: last 30s, see --average-rate-window).
.TP
.B \-b, \-\-bytes
Turn the total byte counter on. This will display the total amount of
@@ -276,10 +276,10 @@ 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
.B \-m SEC, \-\-average-rate-window SEC
Compute current average rate over a
.B SEC
seconds window for ETA calculation (default 30s).
seconds window for average rate and ETA calculations (default 30s).
.TP
.B \-w WIDTH, \-\-width WIDTH
Assume the terminal is
+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;