From 7bc419ee18fb59acbd0bf2fc5d31b25b32bc28ea Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Tue, 17 Oct 2017 19:15:45 +0200 Subject: [PATCH 40/69] tools/kvm_stat: fix event counts display for interrupted intervals RH-Author: David Hildenbrand Message-id: <20171017191605.2378-20-david@redhat.com> Patchwork-id: 77330 O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 19/39] tools/kvm_stat: fix event counts display for interrupted intervals Bugzilla: 1497137 RH-Acked-by: Paolo Bonzini RH-Acked-by: Cornelia Huck RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Thomas Huth Upstream-status: linux.git 124c2fc9fdf5fb1d9cea4707d7e5471e317ba3bf commit 124c2fc9fdf5fb1d9cea4707d7e5471e317ba3bf Author: Stefan Raspl Date: Wed Jun 7 21:08:26 2017 +0200 tools/kvm_stat: fix event counts display for interrupted intervals 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 Signed-off-by: Paolo Bonzini Signed-off-by: David Hildenbrand Signed-off-by: Miroslav Rezanina --- scripts/kvm/kvm_stat | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 904eb62..b571584 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/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() -- 1.8.3.1