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

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