X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fbuffer.c;h=69812ec71597cfc502f207ef86cb7fab3ce71869;hb=7347b4f5d51c15bb19637ea52e9bf7dff832cc52;hp=d7c6844c4fd9da9eb8873d94991334f6ad4397ce;hpb=2d041189aaa148d08a9ce2cf7ab2a286d2aa545e;p=chaz%2Ftar diff --git a/src/buffer.c b/src/buffer.c index d7c6844..69812ec 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "system.h" +#include #include @@ -28,7 +28,7 @@ #include #include "common.h" -#include "rmt.h" +#include /* Number of retries before giving up on read. */ #define READ_ERROR_MAX 10 @@ -115,32 +115,53 @@ clear_read_error_count (void) read_error_count = 0; } + +/* Time-related functions */ + +double duration; + void -print_total_written (void) +set_start_time () { - tarlong written = prev_written + bytes_written; - char bytes[sizeof (tarlong) * CHAR_BIT]; - char abbr[LONGEST_HUMAN_READABLE + 1]; - char rate[LONGEST_HUMAN_READABLE + 1]; - double seconds; - int human_opts = human_autoscale | human_base_1024 | human_SI | human_B; +#if HAVE_CLOCK_GETTIME + if (clock_gettime (CLOCK_REALTIME, &start_timespec) != 0) +#endif + start_time = time (0); +} +void +compute_duration () +{ #if HAVE_CLOCK_GETTIME struct timespec now; if (clock_gettime (CLOCK_REALTIME, &now) == 0) - seconds = ((now.tv_sec - start_timespec.tv_sec) - + (now.tv_nsec - start_timespec.tv_nsec) / 1e9); + duration += ((now.tv_sec - start_timespec.tv_sec) + + (now.tv_nsec - start_timespec.tv_nsec) / 1e9); else #endif - seconds = time (0) - start_time; + duration += time (NULL) - start_time; + set_start_time (); +} + + + +void +print_total_written (void) +{ + tarlong written = prev_written + bytes_written; + char bytes[sizeof (tarlong) * CHAR_BIT]; + char abbr[LONGEST_HUMAN_READABLE + 1]; + char rate[LONGEST_HUMAN_READABLE + 1]; + + int human_opts = human_autoscale | human_base_1024 | human_SI | human_B; sprintf (bytes, TARLONG_FORMAT, written); /* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */ fprintf (stderr, _("Total bytes written: %s (%s, %s/s)\n"), bytes, human_readable (written, abbr, human_opts, 1, 1), - (0 < seconds && written / seconds < (uintmax_t) -1 - ? human_readable (written / seconds, rate, human_opts, 1, 1) + (0 < duration && written / duration < (uintmax_t) -1 + ? human_readable (written / duration, rate, human_opts, 1, 1) : "?")); } @@ -934,7 +955,8 @@ close_archive (void) sys_drain_input_pipe (); - if (verify_option) + compute_duration (); + if (verify_option) verify_volume (); if (rmtclose (archive) != 0)