MCPcopy Index your code
hub / github.com/RsyncProject/rsync / rprint_progress

Function rprint_progress

progress.c:69–135  ·  view source on GitHub ↗

* @param ofs Current position in file * @param size Total size of file * @param 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.) **/

Source from the content-addressed store, hash-verified

67 * necessarily the same as all bytes being received.)
68 **/
69static void rprint_progress(OFF_T ofs, OFF_T size, struct timeval *now, int is_last)
70{
71 char rembuf[64], eol[128];
72 const char *units;
73 unsigned long diff;
74 double rate, remain;
75 int pct;
76
77 if (is_last) {
78 int len = snprintf(eol, sizeof eol,
79 " (xfr#%d, %s-chk=%d/%d)\n",
80 stats.xferred_files, flist_eof ? "to" : "ir",
81 stats.num_files - current_file_index - 1,
82 stats.num_files);
83 if (INFO_GTE(PROGRESS, 2)) {
84 static int last_len = 0;
85 /* Drop \n and pad with spaces if line got shorter. */
86 if (last_len < --len)
87 last_len = len;
88 eol[last_len] = '\0';
89 while (last_len > len)
90 eol[--last_len] = ' ';
91 is_last = 0;
92 }
93 /* Compute stats based on the starting info. */
94 if (!ph_start.time.tv_sec || !(diff = msdiff(&ph_start.time, now)))
95 diff = 1;
96 rate = (double) (ofs - ph_start.ofs) * 1000.0 / diff / 1024.0;
97 /* Switch to total time taken for our last update. */
98 remain = (double) diff / 1000.0;
99 } else {
100 strlcpy(eol, " ", sizeof eol);
101 /* Compute stats based on recent progress. */
102 if (!(diff = msdiff(&ph_list[oldest_hpos].time, now)))
103 diff = 1;
104 rate = (double) (ofs - ph_list[oldest_hpos].ofs) * 1000.0 / diff / 1024.0;
105 remain = rate ? (double) (size - ofs) / rate / 1000.0 : 0.0;
106 }
107
108 if (rate > 1024*1024) {
109 rate /= 1024.0 * 1024.0;
110 units = "GB/s";
111 } else if (rate > 1024) {
112 rate /= 1024.0;
113 units = "MB/s";
114 } else {
115 units = "kB/s";
116 }
117
118 if (remain < 0 || remain > 9999.0 * 3600.0)
119 strlcpy(rembuf, " ??:??:??", sizeof rembuf);
120 else {
121 snprintf(rembuf, sizeof rembuf, "%4u:%02u:%02u",
122 (unsigned int) (remain / 3600.0),
123 (unsigned int) (remain / 60.0) % 60,
124 (unsigned int) remain % 60);
125 }
126

Callers 2

end_progressFunction · 0.85
show_progressFunction · 0.85

Calls 5

msdiffFunction · 0.85
strlcpyFunction · 0.85
human_numFunction · 0.85
rflushFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected