Package: pv
Version: 1.6.6-1
Severity: normal
Tags: upstream patch
Hello,
This was reported upstream some time ago but it doesn't seem new pv
versions are coming out so reporting here instead, maybe we can do
something about it in debian.
This was found on ubuntu initially, sorry I haven't tested debian per se
but from what I can see it's affected as well as package sources are
identical.
Consider following scenario:
I was running a really long task that generates a 800Mb file at about
50k/s. Something like:
while true ; do ls -l /* ; sleep 1 ; done > /tmp/file
Sometime after it started I thought of using pv to keep track of
progress with:
tail -n +1 -f /tmp/file | pv -s 800m >/dev/null
I was interested in ETA mostly, unfortunately if you do this after a few
mb have been generated the ETA is wildly wrong for a very long time:
transfer rate is really fast initially and fools pv into thinking we're
going to get something like that over time, and it takes a really long
time for the average rate to drop back to 50k/s which is all we're
getting actually.
It'd be nice to have an ETA based on current rate average here, say over
last 30s or last 10s, instead of global rate average.
I've been playing with this patch on top of pv 1.6.6
(also at https://github.com/lemonsqueeze/pv)
Which keeps track of history periodically over a given time window and uses
that to compute current average rate for ETA. Looks like it works pretty
well in this case. Also added a --rate-window option to change time window
(default: last 10s) (name isn't great, maybe could find a better one).
-- System Information:
Debian Release: stretch/sid
APT prefers xenial-updates
APT policy: (500, 'xenial-updates'), (500, 'xenial-security'), (500,
'xenial'), (100, 'xenial-backports')
Architecture: i386 (i686)
Kernel: Linux 4.4.0-174-generic (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages pv depends on:
ii libc6 2.23-0ubuntu11
pv recommends no packages.
Versions of packages pv suggests:
pn doc-base
-- no debconf information
diff --git a/doc/quickref.1.in b/doc/quickref.1.in
index 5245e3f..3a0835c 100644
--- a/doc/quickref.1.in
+++ b/doc/quickref.1.in
@@ -263,6 +263,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, \-\-rate-window SEC
+Compute current average rate over a
+.B SEC
+seconds window for ETA (default 10s).
+.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 0f8029e..c2834bb 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 rate_window; /* time window in seconds for current
average rate */
unsigned int width;/* screen width */
unsigned int height; /* screen height */
char *name;/* process name, if any */
diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h
index 46d7496..9b49ba3 100644
--- a/src/include/pv-internal.h
+++ b/src/include/pv-internal.h
@@ -44,7 +44,13 @@ extern "C" {
#define MAXIMISE_BUFFER_FILL 1
+
+typedef struct pvhistory {
+ long long total_bytes;
+ long double elapsed_sec;
+} pvhistory_t;
+
/*
* Structure for holding PV internal state. Opaque outside the PV library.
*/
@@ -113,6 +119,15 @@ struct pvstate_s {
long double prev_elapsed_sec;
long double prev_rate;
long double prev_trans;
+
+ /* Keep track of progress over last intervals to compute current
average rate. */
+ pvhistory_t *history;/* state at previous intervals
(circular buffer) */
+ int history_len; /* total size */
+ int history_interval;/* seconds between each history entry
*/
+ int history_first;
+ int history_last;
+ long double current_avg_rate;/* current average rate over last
history intervals */
+
unsigned long long initial_offset;
char *display_buffer;
long display_buffer_size;
diff --git a/src/include/pv.h b/src/include/pv.h
index 7a3970c..a93faf4 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_rate_window_set(pvstate_t, int);
extern void