From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Raspl Subject: [PATCH v1 02/19] tools/kvm_stat: fix event counts display for interrupted intervals Date: Wed, 7 Jun 2017 21:08:26 +0200 Message-ID: <20170607190843.76869-3-raspl@linux.vnet.ibm.com> References: <20170607190843.76869-1-raspl@linux.vnet.ibm.com> Cc: pbonzini@redhat.com, rkrcmar@redhat.com, frankja@linux.vnet.ibm.com To: kvm@vger.kernel.org Return-path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:58892 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751694AbdFGTJp (ORCPT ); Wed, 7 Jun 2017 15:09:45 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v57J8rtg036905 for ; Wed, 7 Jun 2017 15:09:40 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2axpgwt9qp-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 07 Jun 2017 15:09:39 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Jun 2017 20:09:38 +0100 In-Reply-To: <20170607190843.76869-1-raspl@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: When an update interval is interrupted via key press (e.g. space), the 'Current' column value is calculated using the full interval length instead of the elapsed time, which leads to lower than actual numbers. Furthermore, the value should be rounded, not truncated. This is fixed by using the actual elapsed time for the calculation. Signed-off-by: Stefan Raspl --- tools/kvm/kvm_stat/kvm_stat | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat index 904eb6214602..b571584419ae 100755 --- a/tools/kvm/kvm_stat/kvm_stat +++ b/tools/kvm/kvm_stat/kvm_stat @@ -1009,7 +1009,8 @@ class Tui(object): self.screen.addstr(row, col, '%7.1f' % (values[0] * 100 / total,)) col += 7 if values[1] is not None: - self.screen.addstr(row, col, '%8d' % (values[1] / sleeptime,)) + self.screen.addstr(row, col, '%8d' % + round(values[1] / sleeptime)) row += 1 self.screen.refresh() @@ -1130,9 +1131,11 @@ class Tui(object): """Refreshes the screen and processes user input.""" sleeptime = DELAY_INITIAL self.refresh_header() + start = 0.0 # result based on init value never appears on screen while True: - self.refresh_body(sleeptime) + self.refresh_body(time.time() - start) curses.halfdelay(int(sleeptime * 10)) + start = time.time() sleeptime = DELAY_REGULAR try: char = self.screen.getkey() -- 2.11.2