Spinner, so we can detect hangs.
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 9 Feb 2008 16:57:20 +0000 (16:57 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sat, 9 Feb 2008 16:57:20 +0000 (16:57 +0000)
virt-p2v

index 755e4a8..e1ba0d1 100755 (executable)
--- a/virt-p2v
+++ b/virt-p2v
@@ -1476,25 +1476,26 @@ Compression:  %b"
       let (sock,_) as conn = do_connect remote_name size in
 
       (* Copy the data. *)
+      let spinners = "|/-\\" (* "Oo" *) in
       let bufsize = 1024 * 1024 in
       let buffer = String.create bufsize in
       let start = gettimeofday () in
 
-      let rec copy bytes_sent last_printed_at =
+      let rec copy bytes_sent last_printed_at spinner =
        let n = read fd buffer 0 bufsize in
        if n > 0 then (
          let n' = write sock buffer 0 n in
          if n <> n' then assert false; (* never, according to the manual *)
 
          let bytes_sent = Int64.add bytes_sent (Int64.of_int n) in
-         let last_printed_at =
+         let last_printed_at, spinner =
            let now = gettimeofday () in
            (* Print progress every few seconds. *)
-           if now -. last_printed_at > 5. then (
+           if now -. last_printed_at > 2. then (
              let elapsed = Int64.to_float bytes_sent /. Int64.to_float size in
              let secs_elapsed = now -. start in
-             printf "%.0f%% @ %.1f Mbps"
-               (100. *. elapsed)
+             printf "%.0f%% %c %.1f Mbps"
+               (100. *. elapsed) spinners.[spinner]
                (Int64.to_float bytes_sent/.secs_elapsed/.1_000_000. *. 8.);
              (* After 60 seconds has elapsed, start printing estimates. *)
              if secs_elapsed >= 60. then (
@@ -1507,14 +1508,15 @@ Compression:  %b"
                    secs_remaining
              );
              printf "          \r%!";
-             now
+             let spinner = (spinner + 1) mod String.length spinners in
+             now, spinner
            )
-           else last_printed_at in
+           else last_printed_at, spinner in
 
-         copy bytes_sent last_printed_at
+         copy bytes_sent last_printed_at spinner
        )
       in
-      copy 0L start;
+      copy 0L start 0;
       printf "\n\n%!"; (* because of the messages printed above *)
 
       (* Disconnect. *)