qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2 8/8] dump-query: make the percentage accurate.


From: Peter Xu
Subject: [Qemu-devel] [PATCH v2 8/8] dump-query: make the percentage accurate.
Date: Fri, 27 Nov 2015 10:48:17 +0800

By calculating the total_size and written_size of memory, we could
get relatively accurate percentage of finished dump.

Signed-off-by: Peter Xu <address@hidden>
---
 dump.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/dump.c b/dump.c
index 65bd5fb..0fcad28 100644
--- a/dump.c
+++ b/dump.c
@@ -1643,8 +1643,9 @@ static const char *const dump_result_table[] = {
  * resources using qapi_free_DumpStatus(). */
 DumpStatus *dump_status_query(void)
 {
+    DumpState *state = NULL;
     DumpStatus *status = g_malloc0(sizeof(*status));
-    int percentage = 50;
+    float percentage = 0;
     char buf[64] = {0};
 
     GlobalDumpState *global = dump_state_get_global();
@@ -1653,7 +1654,9 @@ DumpStatus *dump_status_query(void)
     /* TBD: get correct percentage */
     status->status = g_strdup(dump_result_table[global->gds_result]);
     if (global->gds_result == DUMP_RES_IN_PROGRESS) {
-        snprintf(buf, sizeof(buf) - 1, "%d%%", percentage);
+        state = global->gds_cur;
+        percentage = 100.0 * state->written_size / state->total_size;
+        snprintf(buf, sizeof(buf) - 1, "%.2f%%", percentage);
         status->percentage = g_strdup(buf);
     } else {
         status->percentage = g_strdup("N/A");
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]