From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a295c-0007ZG-EV for qemu-devel@nongnu.org; Thu, 26 Nov 2015 21:48:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a295b-00056X-Ly for qemu-devel@nongnu.org; Thu, 26 Nov 2015 21:48:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a295b-00055t-H1 for qemu-devel@nongnu.org; Thu, 26 Nov 2015 21:48:47 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 3787B68E08 for ; Fri, 27 Nov 2015 02:48:47 +0000 (UTC) From: Peter Xu Date: Fri, 27 Nov 2015 10:48:17 +0800 Message-Id: <1448592497-2462-9-git-send-email-peterx@redhat.com> In-Reply-To: <1448592497-2462-1-git-send-email-peterx@redhat.com> References: <1448592497-2462-1-git-send-email-peterx@redhat.com> Subject: [Qemu-devel] [PATCH v2 8/8] dump-query: make the percentage accurate. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Xu By calculating the total_size and written_size of memory, we could get relatively accurate percentage of finished dump. Signed-off-by: Peter Xu --- 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