]> Dogcows Code - chaz/tar/commitdiff
When computing write rate do not take
authorSergey Poznyakoff <gray@gnu.org.ua>
Tue, 31 Aug 2004 11:48:05 +0000 (11:48 +0000)
committerSergey Poznyakoff <gray@gnu.org.ua>
Tue, 31 Aug 2004 11:48:05 +0000 (11:48 +0000)
into account the time needed to verify the archive(s).
The bug reported by John L. Males <jlmales@yahoo.com>
(set_start_time,compute_duration): New functions.
(print_total_written): Use the result of compute_duration().
(close_archive): Call compute_duration.

src/buffer.c

index d7c6844c4fd9da9eb8873d94991334f6ad4397ce..0bba3fa990ce79492d54786247d15978b616424d 100644 (file)
@@ -115,32 +115,53 @@ clear_read_error_count (void)
   read_error_count = 0;
 }
 
+\f
+/* 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 ();
+}
+
+\f
+
+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)
This page took 0.033306 seconds and 4 git commands to generate.