| 1 |
--- a/buffer.c |
| 2 |
+++ b/buffer.c |
| 3 |
@@ -109,6 +109,9 @@ |
| 4 |
* Initial revision |
| 5 |
* |
| 6 |
*/ |
| 7 |
+#include <stdlib.h> |
| 8 |
+#include <string.h> |
| 9 |
+#include <limits.h> |
| 10 |
#include <unistd.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <signal.h> |
| 13 |
@@ -120,6 +123,7 @@ |
| 14 |
#include <sys/shm.h> |
| 15 |
#include <sys/sem.h> |
| 16 |
#include <sys/wait.h> |
| 17 |
+#include <sys/time.h> |
| 18 |
#include "sem.h" |
| 19 |
|
| 20 |
#ifndef lint |
| 21 |
@@ -252,6 +256,8 @@ |
| 22 |
/* Number of K output */ |
| 23 |
unsigned long outk = 0; |
| 24 |
|
| 25 |
+struct timeval starttime; |
| 26 |
+ |
| 27 |
int |
| 28 |
main( argc, argv ) |
| 29 |
int argc; |
| 30 |
@@ -262,6 +268,8 @@ |
| 31 |
set_handlers(); |
| 32 |
|
| 33 |
buffer_allocate(); |
| 34 |
+ |
| 35 |
+ gettimeofday(&starttime, NULL); |
| 36 |
|
| 37 |
start_reader_and_writer(); |
| 38 |
|
| 39 |
@@ -961,7 +969,24 @@ |
| 40 |
void |
| 41 |
pr_out() |
| 42 |
{ |
| 43 |
- fprintf( stderr, " %10luK\r", outk ); |
| 44 |
+ struct timeval now; |
| 45 |
+ unsigned long ms_delta, k_per_s; |
| 46 |
+ |
| 47 |
+ gettimeofday(&now, NULL); |
| 48 |
+ ms_delta = (now.tv_sec - starttime.tv_sec) * 1000 |
| 49 |
+ + (now.tv_usec - starttime.tv_usec) / 1000; |
| 50 |
+ if (ms_delta) { |
| 51 |
+ /* Use increased accuracy for small amounts of data */ |
| 52 |
+ if (outk < ULONG_MAX / 1000) { |
| 53 |
+ k_per_s = (outk * 1000) / ms_delta; |
| 54 |
+ } else { |
| 55 |
+ k_per_s = outk / (ms_delta / 1000); |
| 56 |
+ } |
| 57 |
+ } else { |
| 58 |
+ k_per_s = 0; |
| 59 |
+ } |
| 60 |
+ |
| 61 |
+ fprintf( stderr, " %10luK, %10luK/s\r", outk, k_per_s ); |
| 62 |
} |
| 63 |
|
| 64 |
#ifdef SYS5 |