Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

progress.c File Reference

Go to the source code of this file.

Functions

unsigned long msdiff (struct timeval *t1, struct timeval *t2)
void rprint_progress (OFF_T ofs, OFF_T size, struct timeval *now, int is_last)
void end_progress (OFF_T size)
void show_progress (OFF_T ofs, OFF_T size)

Variables

OFF_T last_ofs
timeval print_time
timeval start_time
OFF_T start_ofs


Function Documentation

unsigned long msdiff struct timeval *    t1,
struct timeval *    t2
[static]
 

Definition at line 29 of file progress.c.

Referenced by rprint_progress(), and show_progress().

00030 {
00031     return (t2->tv_sec - t1->tv_sec) * 1000
00032         + (t2->tv_usec - t1->tv_usec) / 1000;
00033 }

void rprint_progress OFF_T    ofs,
OFF_T    size,
struct timeval *    now,
int    is_last
[static]
 

Parameters:
ofs  Current position in file
size  Total size of file
is_last  True if this is the last time progress will be printed for this file, so we should output a newline. (Not necessarily the same as all bytes being received.)

Definition at line 43 of file progress.c.

References FINFO, msdiff(), rprintf(), start_ofs, and start_time.

Referenced by end_progress(), and show_progress().

00045 {
00046     int           pct  = (ofs == size) ? 100 : (int)((100.0*ofs)/size);
00047     unsigned long diff = msdiff(&start_time, now);
00048     double        rate = diff ? (double) (ofs-start_ofs) * 1000.0 / diff / 1024.0 : 0;
00049     const char    *units;
00050     /* If we've finished transferring this file, show the time taken;
00051      * otherwise show expected time to complete.  That's kind of
00052      * inconsistent, but people can probably cope.  Hopefully we'll
00053      * get more consistent and complete progress reporting soon. --
00054      * mbp */
00055     double        remain = is_last
00056                         ? (double) diff / 1000.0
00057                         : rate ? (double) (size-ofs) / rate / 1000.0 : 0.0;
00058     int           remain_h, remain_m, remain_s;
00059 
00060     if (rate > 1024*1024) {
00061             rate /= 1024.0 * 1024.0;
00062             units = "GB/s";
00063     } else if (rate > 1024) {
00064             rate /= 1024.0;
00065             units = "MB/s";
00066     } else {
00067             units = "kB/s";
00068     }
00069 
00070     remain_s = (int) remain % 60;
00071     remain_m = (int) (remain / 60.0) % 60;
00072     remain_h = (int) (remain / 3600.0);
00073     
00074     rprintf(FINFO, "%12.0f %3d%% %7.2f%s %4d:%02d:%02d%s",
00075             (double) ofs, pct, rate, units,
00076             remain_h, remain_m, remain_s,
00077             is_last ? "\n" : "\r");
00078 }

void end_progress OFF_T    size
 

Definition at line 80 of file progress.c.

References last_ofs, print_time, rprint_progress(), start_ofs, and start_time.

Referenced by matched(), and receive_data().

00081 {
00082         extern int do_progress, am_server;
00083 
00084         if (do_progress && !am_server) {
00085                 struct timeval now;
00086                 gettimeofday(&now, NULL);
00087                 rprint_progress(size, size, &now, True);
00088         }
00089         last_ofs   = 0;
00090         start_ofs  = 0;
00091         print_time.tv_sec  = print_time.tv_usec  = 0;
00092         start_time.tv_sec  = start_time.tv_usec  = 0;
00093 }

void show_progress OFF_T    ofs,
OFF_T    size
 

Definition at line 95 of file progress.c.

References last_ofs, msdiff(), print_time, rprint_progress(), start_ofs, and start_time.

Referenced by matched(), and receive_data().

00096 {
00097         extern int do_progress, am_server;
00098         struct timeval now;
00099 
00100         gettimeofday(&now, NULL);
00101 
00102         if (!start_time.tv_sec && !start_time.tv_usec) {
00103                 start_time.tv_sec  = now.tv_sec;
00104                 start_time.tv_usec = now.tv_usec;
00105                 start_ofs          = ofs;
00106         }
00107 
00108         if (do_progress
00109             && !am_server
00110             && ofs > last_ofs + 1000
00111             && msdiff(&print_time, &now) > 250) {
00112                 rprint_progress(ofs, size, &now, False);
00113                 last_ofs = ofs;
00114                 print_time.tv_sec  = now.tv_sec;
00115                 print_time.tv_usec = now.tv_usec;
00116         }
00117 }


Variable Documentation

OFF_T last_ofs [static]
 

Definition at line 24 of file progress.c.

Referenced by end_progress(), and show_progress().

struct timeval print_time [static]
 

Definition at line 25 of file progress.c.

Referenced by end_progress(), and show_progress().

struct timeval start_time [static]
 

Definition at line 26 of file progress.c.

Referenced by end_progress(), rprint_progress(), and show_progress().

OFF_T start_ofs [static]
 

Definition at line 27 of file progress.c.

Referenced by end_progress(), rprint_progress(), and show_progress().


Generated on Tue Apr 16 12:37:39 2002 for rsync by doxygen1.2.15