Blame SOURCES/kvm-tools-kvm_stat-simplify-line-print-logic.patch

4a2fec
From c4f941df751961aaf2456dfd4ffe7a7a8c0fda4c Mon Sep 17 00:00:00 2001
4a2fec
From: David Hildenbrand <david@redhat.com>
4a2fec
Date: Tue, 17 Oct 2017 19:15:48 +0200
4a2fec
Subject: [PATCH 43/69] tools/kvm_stat: simplify line print logic
4a2fec
4a2fec
RH-Author: David Hildenbrand <david@redhat.com>
4a2fec
Message-id: <20171017191605.2378-23-david@redhat.com>
4a2fec
Patchwork-id: 77329
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 22/39] tools/kvm_stat: simplify line print logic
4a2fec
Bugzilla: 1497137
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
4a2fec
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
4a2fec
Upstream-status: linux.git 5a7d11f8dc59ddb36e89dca42a2526ea25914def
4a2fec
4a2fec
commit 5a7d11f8dc59ddb36e89dca42a2526ea25914def
4a2fec
Author: Stefan Raspl <raspl@linux.vnet.ibm.com>
4a2fec
Date:   Wed Jun 7 21:08:29 2017 +0200
4a2fec
4a2fec
    tools/kvm_stat: simplify line print logic
4a2fec
4a2fec
    Simplify line print logic for header and data lines in interactive mode
4a2fec
    as previously suggested by Radim.
4a2fec
    While at it, add a space between the first two columns to avoid the
4a2fec
    total bleeding into the event name.
4a2fec
    Furthermore, for column 'Current', differentiate between no events being
4a2fec
    reported (empty 'Current' column) vs the case where events were reported
4a2fec
    but the average was rounded down to zero ('0' in 'Current column), for
4a2fec
    the folks who appreciate the difference.
4a2fec
    Finally: Only skip events which were not reported at all yet, instead of
4a2fec
    events that don't have a value in the current interval.
4a2fec
    Considered using constants for the field widths in the format strings.
4a2fec
    However, that would make things a bit more complicated, and considering
4a2fec
    that there are only two places where output happens, I figured it isn't
4a2fec
    worth the trouble.
4a2fec
4a2fec
    Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
4a2fec
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
4a2fec
Signed-off-by: David Hildenbrand <david@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 scripts/kvm/kvm_stat | 26 +++++++-------------------
4a2fec
 1 file changed, 7 insertions(+), 19 deletions(-)
4a2fec
4a2fec
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
4a2fec
index d2526b6..a527b2f 100755
4a2fec
--- a/scripts/kvm/kvm_stat
4a2fec
+++ b/scripts/kvm/kvm_stat
4a2fec
@@ -887,8 +887,6 @@ class Stats(object):
4a2fec
                 self.values[key] = (newval, newdelta)
4a2fec
         return self.values
4a2fec
 
4a2fec
-LABEL_WIDTH = 40
4a2fec
-NUMBER_WIDTH = 10
4a2fec
 DELAY_INITIAL = 0.25
4a2fec
 DELAY_REGULAR = 3.0
4a2fec
 MAX_GUEST_NAME_LEN = 48
4a2fec
@@ -970,13 +968,8 @@ class Tui(object):
4a2fec
             if len(regex) > MAX_REGEX_LEN:
4a2fec
                 regex = regex[:MAX_REGEX_LEN] + '...'
4a2fec
             self.screen.addstr(1, 17, 'regex filter: {0}'.format(regex))
4a2fec
-        self.screen.addstr(2, 1, 'Event')
4a2fec
-        self.screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH -
4a2fec
-                           len('Total'), 'Total')
4a2fec
-        self.screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH + 7 -
4a2fec
-                           len('%Total'), '%Total')
4a2fec
-        self.screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH + 7 + 8 -
4a2fec
-                           len('Current'), 'Current')
4a2fec
+        self.screen.addstr(2, 1, '%-40s %10s%7s %7s' %
4a2fec
+                           ('Event', 'Total', '%Total', 'Current'))
4a2fec
         self.screen.addstr(4, 1, 'Collecting data...')
4a2fec
         self.screen.refresh()
4a2fec
 
4a2fec
@@ -1001,16 +994,11 @@ class Tui(object):
4a2fec
             values = stats[key]
4a2fec
             if not values[0] and not values[1]:
4a2fec
                 break
4a2fec
-            col = 1
4a2fec
-            self.screen.addstr(row, col, key)
4a2fec
-            col += LABEL_WIDTH
4a2fec
-            self.screen.addstr(row, col, '%10d' % (values[0],))
4a2fec
-            col += NUMBER_WIDTH
4a2fec
-            self.screen.addstr(row, col, '%7.1f' % (values[0] * 100 / total,))
4a2fec
-            col += 7
4a2fec
-            if values[1] is not None:
4a2fec
-                self.screen.addstr(row, col, '%8d' %
4a2fec
-                                   round(values[1] / sleeptime))
4a2fec
+            if values[0] is not None:
4a2fec
+                cur = int(round(values[1] / sleeptime)) if values[1] else ''
4a2fec
+                self.screen.addstr(row, 1, '%-40s %10d%7.1f %7s' %
4a2fec
+                                   (key, values[0], values[0] * 100 / total,
4a2fec
+                                    cur))
4a2fec
             row += 1
4a2fec
         self.screen.refresh()
4a2fec
 
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec