From 528889888caa4dba8d2adc258aa29068e124b4bd Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 26 Oct 2025 12:06:32 +0000 Subject: [PATCH] Always calculate the elapsed transfer time every time around the loop, even if not displaying anything; and take -W into account so the elapsed time doesn't start ticking up until the first byte or line transferred, even if not displaying anything - so that -Q will report the right thing when querying a "pv -n" (#101). --- src/pv/loop.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pv/loop.c b/src/pv/loop.c index b57bd2d..1c81ab5 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -526,16 +526,6 @@ int pv_main_loop(pvstate_t state) pv_nanosleep(50000000); } - /* - * Just go round the loop again if there's no display and - * we're not reporting statistics. - * - * TODO: still calculate elapsed time, otherwise -Q can't - * read it (#101). - */ - if (state->control.no_display && !state->control.show_stats) - continue; - /* * If -W was given, we don't output anything until we have * written a byte (or line, in line mode), at which point @@ -577,6 +567,18 @@ int pv_main_loop(pvstate_t state) pv_elapsedtime_add_nsec(&next_update, (long long) (1000000000.0 * state->control.interval)); } + /* Calculate the elapsed transfer time. */ + state->transfer.elapsed_seconds = + pv__elapsed_transfer_time(&start_time, &cur_time, &(state->signal.toffset)); + + /* + * Just go round the loop again if there's no display and + * we're not reporting statistics. + */ + if (state->control.no_display && !state->control.show_stats) { + continue; + } + /* Restart the loop if it's not time to update the display. */ if (pv_elapsedtime_compare(&cur_time, &next_update) < 0) { continue; @@ -588,10 +590,6 @@ int pv_main_loop(pvstate_t state) if (pv_elapsedtime_compare(&next_update, &cur_time) < 0) pv_elapsedtime_copy(&next_update, &cur_time); - /* Calculate the elapsed transfer time. */ - state->transfer.elapsed_seconds = - pv__elapsed_transfer_time(&start_time, &cur_time, &(state->signal.toffset)); - /* Resize the display, if a resize signal was received. */ (void) pv__resize_display_on_signal(state);