patch from faith@alephnull to add rate indicator to --progress

Robert Scholten r.scholten at physics.unimelb.edu.au
Thu Nov 29 10:08:13 EST 2001


Ooooh! I love this sort of thing - helps debugging problems, and in making
decisions such as "have I got time to go for a coffee while this is
cranking".  2.4.7pre5 please.


On Thu, 29 Nov 2001, Martin Pool wrote:

> Any votes for/against?
>
>
> ----- Forwarded message from Rik Faith <faith at alephnull.com> -----
>
> Date: Wed, 28 Nov 2001 12:55:29 -0500
> From: Rik Faith <faith at alephnull.com>
> To: mbp at samba.org
> Subject: rsync patch
> X-Mailer: VM 6.96; XEmacs 21.1; Linux 2.4.16 (light)
>
> Here is a patch that adds rate information (e.g., kB/s) to the
> --progress display.  I just noticed that 2.4.7pre4 is coming out and I
> realized I forgot to send this to someone.  Assuming I'm too late,
> please let me know where I should send it (or if you'd like to see some
> changes or just aren't interested at all).  Thanks, Rik.
>
> [The motivation was to see how ssh's encryption and compression options
> impact rsync throughput -- and to be sure I'm using the right options to
> provide optimal throughput.]
>
> --- rsync-2.4.6/util.c.rik	Tue Sep  5 22:46:43 2000
> +++ rsync-2.4.6/util.c	Fri Oct  5 09:19:35 2001
> @@ -835,28 +835,70 @@
>  	return (int)*s1 - (int)*s2;
>  }
>
> -static OFF_T last_ofs;
> +static OFF_T  last_ofs;
> +static struct timeval print_time;
> +static struct timeval start_time;
> +static OFF_T  start_ofs;
> +
> +static unsigned long msdiff(struct timeval *t1, struct timeval *t2)
> +{
> +    return (t2->tv_sec - t1->tv_sec) * 1000
> +        + (t2->tv_usec - t1->tv_usec) / 1000;
> +}
> +
> +static void rprint_progress(OFF_T ofs, OFF_T size, struct timeval *now)
> +{
> +    int           pct  = (int)((100.0*ofs)/size);
> +    unsigned long diff = msdiff(&start_time, now);
> +    double        rate = diff ? ((ofs-start_ofs) / diff) * 1000.0/1024.0 : 0;
> +
> +    if (ofs == size) pct = 100;
> +
> +    rprintf(FINFO,"%12.0f %3d%%", (double)ofs, pct);
> +
> +    if (rate > 1024*1024) rprintf(FINFO, " %7.2fGB/s", rate/1024.0/1024.0);
> +    else if (rate > 1024) rprintf(FINFO, " %7.2fMB/s", rate/1024.0);
> +    else                  rprintf(FINFO, " %7.2fKB/s", rate);
> +
> +    rprintf(FINFO, (pct == 100) ? "\n" : "\r");
> +}
>
>  void end_progress(OFF_T size)
>  {
>  	extern int do_progress, am_server;
>
>  	if (do_progress && !am_server) {
> -		rprintf(FINFO,"%.0f (100%%)\n", (double)size);
> +        	struct timeval now;
> +                gettimeofday(&now, NULL);
> +                rprint_progress(size, size, &now);
>  	}
> -	last_ofs = 0;
> +	last_ofs   = 0;
> +        start_ofs  = 0;
> +        print_time.tv_sec  = print_time.tv_usec  = 0;
> +        start_time.tv_sec  = start_time.tv_usec  = 0;
>  }
>
>  void show_progress(OFF_T ofs, OFF_T size)
>  {
>  	extern int do_progress, am_server;
> +        struct timeval now;
>
> -	if (do_progress && !am_server) {
> -		if (ofs > last_ofs + 1000) {
> -			int pct = (int)((100.0*ofs)/size);
> -			rprintf(FINFO,"%.0f (%d%%)\r", (double)ofs, pct);
> -			last_ofs = ofs;
> -		}
> +        gettimeofday(&now, NULL);
> +
> +        if (!start_time.tv_sec && !start_time.tv_usec) {
> +        	start_time.tv_sec  = now.tv_sec;
> +                start_time.tv_usec = now.tv_usec;
> +                start_ofs          = ofs;
> +        }
> +
> +	if (do_progress
> +            && !am_server
> +            && ofs > last_ofs + 1000
> +            && msdiff(&print_time, &now) > 250) {
> +        	rprint_progress(ofs, size, &now);
> +                last_ofs = ofs;
> +                print_time.tv_sec  = now.tv_sec;
> +                print_time.tv_usec = now.tv_usec;
>  	}
>  }
>
>
>
> ----- End forwarded message -----
> --
> Martin
>
>

--
Robert Scholten                   Tel:   +61 3 8344 5457  Mob: 0412 834 196
School of Physics                 Fax:   +61 3 9347 4783
University of Melbourne           email: r.scholten at physics.unimelb.edu.au
Victoria 3010  AUSTRALIA          http://www.ph.unimelb.edu.au/~scholten





More information about the rsync mailing list