progress.c

ソースコードを見る。


データ構造

struct  progress_history

関数

static unsigned long msdiff (struct timeval *t1, struct timeval *t2)
static 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)

変数

stats stats
int am_server
static struct progress_history ph_start
static struct progress_history ph_list [PROGRESS_HISTORY_SECS]
static int newest_hpos
static int oldest_hpos

関数

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

progress.c44 行で定義されています。

参照元 rprint_progress()show_progress().

00045 {
00046         return (t2->tv_sec - t1->tv_sec) * 1000L
00047              + (t2->tv_usec - t1->tv_usec) / 1000;
00048 }

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

引数:
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.)

progress.c58 行で定義されています。

参照先 stats::current_file_indexFINFOhuman_num()msdiff()stats::num_filesstats::num_transferred_filesprogress_history::ofsoldest_hposph_listph_startrprintf()snprintf()statsprogress_history::time.

参照元 end_progress()show_progress().

00060 {
00061         char eol[256];
00062         const char *units;
00063         int pct = ofs == size ? 100 : (int) (100.0 * ofs / size);
00064         unsigned long diff;
00065         double rate, remain;
00066         int remain_h, remain_m, remain_s;
00067 
00068         if (is_last) {
00069                 /* Compute stats based on the starting info. */
00070                 if (!ph_start.time.tv_sec
00071                     || !(diff = msdiff(&ph_start.time, now)))
00072                         diff = 1;
00073                 rate = (double) (ofs - ph_start.ofs) * 1000.0 / diff / 1024.0;
00074                 /* Switch to total time taken for our last update. */
00075                 remain = (double) diff / 1000.0;
00076         } else {
00077                 /* Compute stats based on recent progress. */
00078                 if (!(diff = msdiff(&ph_list[oldest_hpos].time, now)))
00079                         diff = 1;
00080                 rate = (double) (ofs - ph_list[oldest_hpos].ofs) * 1000.0
00081                      / diff / 1024.0;
00082                 remain = rate ? (double) (size - ofs) / rate / 1000.0 : 0.0;
00083         }
00084 
00085         if (rate > 1024*1024) {
00086                 rate /= 1024.0 * 1024.0;
00087                 units = "GB/s";
00088         } else if (rate > 1024) {
00089                 rate /= 1024.0;
00090                 units = "MB/s";
00091         } else {
00092                 units = "kB/s";
00093         }
00094 
00095         remain_s = (int) remain % 60;
00096         remain_m = (int) (remain / 60.0) % 60;
00097         remain_h = (int) (remain / 3600.0);
00098 
00099         if (is_last) {
00100                 snprintf(eol, sizeof eol, " (xfer#%d, to-check=%d/%d)\n",
00101                         stats.num_transferred_files,
00102                         stats.num_files - stats.current_file_index - 1,
00103                         stats.num_files);
00104         } else
00105                 strcpy(eol, "\r");
00106         rprintf(FINFO, "%12s %3d%% %7.2f%s %4d:%02d:%02d%s",
00107                 human_num(ofs), pct, rate, units,
00108                 remain_h, remain_m, remain_s, eol);
00109 }

void end_progress ( OFF_T  size  ) 

progress.c111 行で定義されています。

参照先 am_serverph_startrprint_progress().

参照元 receive_data()send_files().

00112 {
00113         if (!am_server) {
00114                 struct timeval now;
00115                 gettimeofday(&now, NULL);
00116                 rprint_progress(size, size, &now, True);
00117         }
00118         memset(&ph_start, 0, sizeof ph_start);
00119 }

void show_progress ( OFF_T  ofs,
OFF_T  size 
)

progress.c121 行で定義されています。

参照先 am_servermsdiff()newest_hposprogress_history::ofsoldest_hposph_listph_startrprint_progress()progress_history::time.

参照元 match_sums()matched()receive_data().

00122 {
00123         struct timeval now;
00124 #if defined HAVE_GETPGRP && defined HAVE_TCGETPGRP
00125         static pid_t pgrp = -1;
00126         pid_t tc_pgrp;
00127 #endif
00128 
00129         if (am_server)
00130                 return;
00131 
00132 #if defined HAVE_GETPGRP && defined HAVE_TCGETPGRP
00133         if (pgrp == -1)
00134                 pgrp = getpgrp(GETPGRP_ARG);
00135 #endif
00136 
00137         gettimeofday(&now, NULL);
00138 
00139         if (!ph_start.time.tv_sec) {
00140                 int i;
00141 
00142                 /* Try to guess the real starting time when the sender started
00143                  * to send us data by using the time we last received some data
00144                  * in the last file (if it was recent enough). */
00145                 if (msdiff(&ph_list[newest_hpos].time, &now) <= 1500) {
00146                         ph_start.time = ph_list[newest_hpos].time;
00147                         ph_start.ofs = 0;
00148                 } else {
00149                         ph_start.time.tv_sec = now.tv_sec;
00150                         ph_start.time.tv_usec = now.tv_usec;
00151                         ph_start.ofs = ofs;
00152                 }
00153 
00154                 for (i = 0; i < PROGRESS_HISTORY_SECS; i++)
00155                         ph_list[i] = ph_start;
00156         }
00157         else {
00158                 if (msdiff(&ph_list[newest_hpos].time, &now) < 1000)
00159                         return;
00160 
00161                 newest_hpos = oldest_hpos;
00162                 oldest_hpos = (oldest_hpos + 1) % PROGRESS_HISTORY_SECS;
00163                 ph_list[newest_hpos].time.tv_sec = now.tv_sec;
00164                 ph_list[newest_hpos].time.tv_usec = now.tv_usec;
00165                 ph_list[newest_hpos].ofs = ofs;
00166         }
00167 
00168 #if defined HAVE_GETPGRP && defined HAVE_TCGETPGRP
00169         tc_pgrp = tcgetpgrp(STDOUT_FILENO);
00170         if (tc_pgrp != pgrp && tc_pgrp != -1)
00171                 return;
00172 #endif
00173 
00174         rprint_progress(ofs, size, &now, False);
00175 }


変数

struct stats stats

log.c59 行で定義されています。

int am_server

options.c75 行で定義されています。

struct progress_history ph_start [static]

progress.c40 行で定義されています。

参照元 end_progress()rprint_progress()show_progress().

struct progress_history ph_list[PROGRESS_HISTORY_SECS] [static]

progress.c41 行で定義されています。

参照元 rprint_progress()show_progress().

int newest_hpos [static]

progress.c42 行で定義されています。

参照元 show_progress().

int oldest_hpos [static]

progress.c42 行で定義されています。

参照元 rprint_progress()show_progress().


rsyncに対してSat Dec 5 19:45:45 2009に生成されました。  doxygen 1.4.7