diff -urN pv-1.0.1.orig/doc/quickref.1.in pv-1.0.1/doc/quickref.1.in --- pv-1.0.1.orig/doc/quickref.1.in 2007-08-03 23:40:52.000000000 +0100 +++ pv-1.0.1/doc/quickref.1.in 2007-08-07 17:13:40.000000000 +0100 @@ -101,6 +101,10 @@ Turn the rate counter on. This will display the current rate of data transfer. .TP +.B \-l, \-\-lines +Turn the line rate counter on. This will display the current rate of lines +being transferd. +.TP .B \-b, \-\-bytes Turn the total byte counter on. This will display the total amount of data transferred so far. diff -urN pv-1.0.1.orig/README pv-1.0.1/README --- pv-1.0.1.orig/README 2007-08-02 18:33:58.000000000 +0100 +++ pv-1.0.1/README 2007-08-07 17:16:33.000000000 +0100 @@ -89,4 +89,7 @@ Gert Menke - reported bug when piping to dd with a large input buffer size + Thomas Stewart rate = 1; numopts++; break; + case 'l': + opts->lines = 1; + numopts++; + break; case 'b': opts->bytes = 1; numopts++; diff -urN pv-1.0.1.orig/src/pv/display.c pv-1.0.1/src/pv/display.c --- pv-1.0.1.orig/src/pv/display.c 2007-08-04 21:37:30.000000000 +0100 +++ pv-1.0.1/src/pv/display.c 2007-08-07 17:00:34.000000000 +0100 @@ -87,15 +87,18 @@ * * If "opts" is NULL, then free all allocated memory and return. */ -void pv_display(opts_t opts, long double esec, long long sl, long long tot) +void pv_display(opts_t opts, long double esec, long long sl, long long lsl, + long long tot, long long ltot) { static long percentage = 0; static long double prev_esec = 0; static long double prev_rate = 0; static long double prev_trans = 0; + static long double prev_lines_rate = 0; + static long double prev_lines = 0; static char *display = NULL; static long dispbufsz = 0; - long double sincelast, rate, transferred; + long double sincelast=0, rate=0, lines_rate=0, transferred; long eta; char prefix[128]; /* RATS: ignore (checked OK) */ char suffix[128]; /* RATS: ignore (checked OK) */ @@ -129,6 +132,23 @@ } prev_rate = rate; + if (lsl >= 0) { + if (sincelast <= 0.01) { + lines_rate = prev_lines_rate; + prev_lines += lsl; + } else { + lines_rate = ((long double) lsl + prev_lines) / + sincelast; + prev_esec = esec; + prev_lines = 0; + } + } else { + if (esec < 0.000001) + esec = 0.000001; + rate = ((long double) ltot) / (long double) esec; + } + prev_lines_rate = lines_rate; + if (rate > 0) percentage += 2; if (percentage > 199) @@ -243,6 +263,13 @@ strcat(display, prefix); /* RATS: ignore (OK) */ } + if (opts->lines) { + if (lines_rate > 100000) + lines_rate = 100000; + sprintf(prefix, "[%Lg lines/s]", lines_rate); + strcat(display, prefix); /* RATS: ignore (OK) */ + } + suffix[0] = 0; if (opts->eta && opts->size > 0) { if (eta < 0) diff -urN pv-1.0.1.orig/src/pv/loop.c pv-1.0.1/src/pv/loop.c --- pv-1.0.1.orig/src/pv/loop.c 2007-08-04 21:37:30.000000000 +0100 +++ pv-1.0.1/src/pv/loop.c 2007-08-07 17:08:16.000000000 +0100 @@ -31,8 +31,9 @@ */ int pv_main_loop(opts_t opts) { - long written; + long written, lines; long long total_written, since_last, cansend, donealready, target; + long long total_lines, lines_since_last; int eof_in, eof_out, final_update; struct timeval start_time, next_update, next_reset, cur_time; struct timeval init_time; @@ -48,6 +49,8 @@ eof_out = 0; total_written = 0; since_last = 0; + total_lines = 0; + lines_since_last = 0; gettimeofday(&start_time, NULL); gettimeofday(&cur_time, NULL); @@ -96,13 +99,17 @@ cansend = 0; } - written = - pv_transfer(opts, fd, &eof_in, &eof_out, cansend); + written = pv_transfer(opts, fd, &eof_in, &eof_out, cansend, + &lines); if (written < 0) return 1; since_last += written; total_written += written; + + lines_since_last += lines; + total_lines += lines; + if (opts->rate_limit > 0) donealready += written; @@ -212,17 +219,21 @@ elapsed += (cur_time.tv_usec - init_time.tv_usec) / 1000000.0; - if (final_update) + if (final_update) { since_last = -1; + lines_since_last = -1; + } if (pv_sig_newsize) { pv_sig_newsize = 0; pv_screensize(opts); } - pv_display(opts, elapsed, since_last, total_written); + pv_display(opts, elapsed, since_last, lines_since_last, + total_written, total_lines); since_last = 0; + lines_since_last = 0; } if (opts->cursor) { @@ -236,8 +247,8 @@ * Free up the buffers used by the display and data transfer * routines. */ - pv_display(0, 0, 0, 0); - pv_transfer(0, -1, 0, 0, 0); + pv_display(0, 0, 0, 0, 0, 0); + pv_transfer(0, -1, 0, 0, 0, 0); return 0; } diff -urN pv-1.0.1.orig/src/pv/transfer.c pv-1.0.1/src/pv/transfer.c --- pv-1.0.1.orig/src/pv/transfer.c 2007-08-04 21:37:30.000000000 +0100 +++ pv-1.0.1/src/pv/transfer.c 2007-08-07 17:09:26.000000000 +0100 @@ -54,7 +54,7 @@ * returned. */ long pv_transfer(opts_t opts, int fd, int *eof_in, int *eof_out, - unsigned long long allowed) + unsigned long long allowed, long *lines_read) { static unsigned char *buf = NULL; static unsigned long in_buffer = 0; @@ -65,7 +65,7 @@ int max_fd; long to_write, written; ssize_t r, w; - int n; + int i, n; if (opts == NULL) { if (buf) @@ -128,6 +128,7 @@ return -1; } + *lines_read = 0; written = 0; if (FD_ISSET(fd, &readfds)) { @@ -161,6 +162,14 @@ } } + if(opts->lines) { + for(i=bytes_written; i < to_write; i++) { + if(buf[bytes_written + i] == '\n') { + (*lines_read)++; + } + } + } + if (FD_ISSET(STDOUT_FILENO, &writefds) && (in_buffer > bytes_written) && (to_write > 0)) {