diff mbox

[v2,8/8] dump-query: make the percentage accurate.

Message ID 1448592497-2462-9-git-send-email-peterx@redhat.com
State New
Headers show

Commit Message

Peter Xu Nov. 27, 2015, 2:48 a.m. UTC
By calculating the total_size and written_size of memory, we could
get relatively accurate percentage of finished dump.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 dump.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox

Patch

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");