]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: virsh-domain: display progress with enhanced granularity
authorShaleen Bathla <shaleen.bathla@oracle.com>
Wed, 26 Apr 2023 11:28:33 +0000 (16:58 +0530)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 2 May 2023 13:52:20 +0000 (15:52 +0200)
Switch from int to double for displaying job progress upto 2 decimal
places.

Signed-off-by: Shaleen Bathla <shaleen.bathla@oracle.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
tools/virsh-domain.c

index e30510a07dddf06f02991a03bcf7908a90c9f117..ffa586940d2f553d9eedf448b516bf6ce44198ea 100644 (file)
@@ -1722,21 +1722,22 @@ static void
 virshPrintJobProgress(const char *label, unsigned long long remaining,
                       unsigned long long total)
 {
-    int progress = 100;
+    double progress = 100.00;
 
     /* if remaining == 0 migration has completed */
     if (remaining != 0) {
-        /* use float to avoid overflow */
-        progress = (int)(100.0 - remaining * 100.0 / total);
-        if (progress >= 100) {
+        /* use double to avoid overflow */
+        progress = 100.00 - remaining * 100.00 / total;
+        if (progress >= 100.00) {
             /* migration has not completed, do not print [100 %] */
-            progress = 99;
+            progress = 99.99;
         }
     }
 
     /* see comments in vshError about why we must flush */
     fflush(stdout);
-    fprintf(stderr, "\r%s: [%3d %%]", label, progress);
+    /* avoid auto-round-off of double by keeping only 2 decimals */
+    fprintf(stderr, "\r%s: [%5.2f %%]", label, (int)(progress*100)/100.0);
     fflush(stderr);
 }