- off_t in,out,tsize;
- time_t t = time(NULL);
-
- if (!verbose) return;
-
- if (am_server && sender) {
- write_longint(f,read_total());
- write_longint(f,write_total());
- write_longint(f,total_size);
- write_flush(f);
- return;
- }
-
- if (sender) {
- in = read_total();
- out = write_total();
- tsize = total_size;
- } else {
- in = read_longint(f);
- out = read_longint(f);
- tsize = read_longint(f);
- }
-
-#if HAVE_LONGLONG
- printf("wrote %lld bytes read %lld bytes %g bytes/sec\n",
- (long long)out,(long long)in,(in+out)/(0.5 + (t-starttime)));
- printf("total size is %lld speedup is %g\n",
- (long long)tsize,(1.0*tsize)/(in+out));
-#else
- printf("wrote %ld bytes read %ld bytes %g bytes/sec\n",
- (long)out,(long)in,(in+out)/(0.5 + (t-starttime)));
- printf("total size is %ld speedup is %g\n",
- (long)tsize,(1.0*tsize)/(in+out));
-#endif
+ /* Cache two stats because the read/write code can change it. */
+ int64 total_read = stats.total_read;
+ int64 total_written = stats.total_written;
+ time_t t = time(NULL);
+
+ if (do_stats && verbose > 1) {
+ /* These come out from every process */
+ show_malloc_stats();
+ show_flist_stats();
+ }
+
+ if (am_generator)
+ return;
+
+ if (am_daemon) {
+ log_exit(0, __FILE__, __LINE__);
+ if (f == -1 || !am_sender)
+ return;
+ }
+
+ if (am_server) {
+ if (am_sender) {
+ write_longint(f, total_read);
+ write_longint(f, total_written);
+ write_longint(f, stats.total_size);
+ if (protocol_version >= 29) {
+ write_longint(f, stats.flist_buildtime);
+ write_longint(f, stats.flist_xfertime);
+ }
+ }
+ return;
+ }
+
+ /* this is the client */
+
+ if (!am_sender) {
+ /* Read the first two in opposite order because the meaning of
+ * read/write swaps when switching from sender to receiver. */
+ total_written = read_longint(f);
+ total_read = read_longint(f);
+ stats.total_size = read_longint(f);
+ if (protocol_version >= 29) {
+ stats.flist_buildtime = read_longint(f);
+ stats.flist_xfertime = read_longint(f);
+ }
+ } else if (write_batch) {
+ /* The --read-batch process is going to be a client
+ * receiver, so we need to give it the stats. */
+ write_longint(batch_fd, total_read);
+ write_longint(batch_fd, total_written);
+ write_longint(batch_fd, stats.total_size);
+ if (protocol_version >= 29) {
+ write_longint(batch_fd, stats.flist_buildtime);
+ write_longint(batch_fd, stats.flist_xfertime);
+ }
+ }
+
+ if (do_stats) {
+ rprintf(FINFO,"\nNumber of files: %d\n", stats.num_files);
+ rprintf(FINFO,"Number of files transferred: %d\n",
+ stats.num_transferred_files);
+ rprintf(FINFO,"Total file size: %.0f bytes\n",
+ (double)stats.total_size);
+ rprintf(FINFO,"Total transferred file size: %.0f bytes\n",
+ (double)stats.total_transferred_size);
+ rprintf(FINFO,"Literal data: %.0f bytes\n",
+ (double)stats.literal_data);
+ rprintf(FINFO,"Matched data: %.0f bytes\n",
+ (double)stats.matched_data);
+ rprintf(FINFO,"File list size: %d\n", stats.flist_size);
+ if (stats.flist_buildtime) {
+ rprintf(FINFO,
+ "File list generation time: %.3f seconds\n",
+ (double)stats.flist_buildtime / 1000);
+ rprintf(FINFO,
+ "File list transfer time: %.3f seconds\n",
+ (double)stats.flist_xfertime / 1000);
+ }
+ rprintf(FINFO,"Total bytes sent: %.0f\n",
+ (double)total_written);
+ rprintf(FINFO,"Total bytes received: %.0f\n",
+ (double)total_read);
+ }
+
+ if (verbose || do_stats) {
+ rprintf(FINFO,
+ "\nsent %.0f bytes received %.0f bytes %.2f bytes/sec\n",
+ (double)total_written, (double)total_read,
+ (total_written + total_read)/(0.5 + (t - starttime)));
+ rprintf(FINFO, "total size is %.0f speedup is %.2f\n",
+ (double)stats.total_size,
+ (double)stats.total_size / (total_written+total_read));
+ }
+
+ fflush(stdout);
+ fflush(stderr);