| 743 | /* Print transfer statistics. */ |
| 744 | |
| 745 | static void |
| 746 | print_xfer_stats (xtime_t progress_time) |
| 747 | { |
| 748 | xtime_t now = progress_time ? progress_time : gethrxtime (); |
| 749 | static char const slash_s[] = "/s"; |
| 750 | char hbuf[3][LONGEST_HUMAN_READABLE + sizeof slash_s]; |
| 751 | double delta_s; |
| 752 | char const *bytes_per_second; |
| 753 | char const *si = human_readable (w_bytes, hbuf[0], human_opts, 1, 1); |
| 754 | char const *iec = human_readable (w_bytes, hbuf[1], |
| 755 | human_opts | human_base_1024, 1, 1); |
| 756 | |
| 757 | /* Use integer arithmetic to compute the transfer rate, |
| 758 | since that makes it easy to use SI abbreviations. */ |
| 759 | char *bpsbuf = hbuf[2]; |
| 760 | int bpsbufsize = sizeof hbuf[2]; |
| 761 | if (start_time < now) |
| 762 | { |
| 763 | double XTIME_PRECISIONe0 = XTIME_PRECISION; |
| 764 | xtime_t delta_xtime = now - start_time; |
| 765 | delta_s = delta_xtime / XTIME_PRECISIONe0; |
| 766 | bytes_per_second = human_readable (w_bytes, bpsbuf, human_opts, |
| 767 | XTIME_PRECISION, delta_xtime); |
| 768 | strcat (bytes_per_second - bpsbuf + bpsbuf, slash_s); |
| 769 | } |
| 770 | else |
| 771 | { |
| 772 | delta_s = 0; |
| 773 | snprintf (bpsbuf, bpsbufsize, "%s B/s", _("Infinity")); |
| 774 | bytes_per_second = bpsbuf; |
| 775 | } |
| 776 | |
| 777 | if (progress_time) |
| 778 | fputc ('\r', stderr); |
| 779 | |
| 780 | /* Use full seconds when printing progress, since the progress |
| 781 | report is output once per second and there is little point |
| 782 | displaying any subsecond jitter. Use default precision with %g |
| 783 | otherwise, as this provides more-useful output then. With long |
| 784 | transfers %g can generate a number with an exponent; that is OK. */ |
| 785 | char delta_s_buf[24]; |
| 786 | snprintf (delta_s_buf, sizeof delta_s_buf, |
| 787 | progress_time ? "%.0f s" : "%g s", delta_s); |
| 788 | |
| 789 | int stats_len |
| 790 | = (abbreviation_lacks_prefix (si) |
| 791 | ? fprintf (stderr, |
| 792 | ngettext ("%jd byte copied, %s, %s", |
| 793 | "%jd bytes copied, %s, %s", |
| 794 | select_plural (w_bytes)), |
| 795 | w_bytes, delta_s_buf, bytes_per_second) |
| 796 | : abbreviation_lacks_prefix (iec) |
| 797 | ? fprintf (stderr, |
| 798 | _("%jd bytes (%s) copied, %s, %s"), |
| 799 | w_bytes, si, delta_s_buf, bytes_per_second) |
| 800 | : fprintf (stderr, |
| 801 | _("%jd bytes (%s, %s) copied, %s, %s"), |
| 802 | w_bytes, si, iec, delta_s_buf, bytes_per_second)); |
no test coverage detected