Blame SOURCES/kvm-tools-kvm_stat-add-new-interactive-command-o.patch

9bac43
From 55f7ed9b2ccc2761e353d14680fe5d1ea8bc11be Mon Sep 17 00:00:00 2001
9bac43
From: David Hildenbrand <david@redhat.com>
9bac43
Date: Tue, 17 Oct 2017 19:15:59 +0200
9bac43
Subject: [PATCH 54/69] tools/kvm_stat: add new interactive command 'o'
9bac43
9bac43
RH-Author: David Hildenbrand <david@redhat.com>
9bac43
Message-id: <20171017191605.2378-34-david@redhat.com>
9bac43
Patchwork-id: 77347
9bac43
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 33/39] tools/kvm_stat: add new interactive command 'o'
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 6667ae8f395099257afca0963838d2dc50a18da7
9bac43
9bac43
Convertion of documentation (for man page generation) to texi.
9bac43
9bac43
commit 6667ae8f395099257afca0963838d2dc50a18da7
9bac43
Author: Stefan Raspl <raspl@linux.vnet.ibm.com>
9bac43
Date:   Wed Jun 7 21:08:41 2017 +0200
9bac43
9bac43
    tools/kvm_stat: add new interactive command 'o'
9bac43
9bac43
    Add new interactive command 'o' to toggle sorting by 'CurAvg/s' (default)
9bac43
    and 'Total' columns.
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      | 17 ++++++++++++++++-
9bac43
 scripts/kvm/kvm_stat.texi |  3 +++
9bac43
 2 files changed, 19 insertions(+), 1 deletion(-)
9bac43
9bac43
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
9bac43
index 1276b88..cf7aa28 100755
9bac43
--- a/scripts/kvm/kvm_stat
9bac43
+++ b/scripts/kvm/kvm_stat
9bac43
@@ -848,6 +848,7 @@ DELAY_DEFAULT = 3.0
9bac43
 MAX_GUEST_NAME_LEN = 48
9bac43
 MAX_REGEX_LEN = 44
9bac43
 DEFAULT_REGEX = r'^[^\(]*$'
9bac43
+SORT_DEFAULT = 0
9bac43
 
9bac43
 
9bac43
 class Tui(object):
9bac43
@@ -857,6 +858,7 @@ class Tui(object):
9bac43
         self.screen = None
9bac43
         self._delay_initial = 0.25
9bac43
         self._delay_regular = DELAY_DEFAULT
9bac43
+        self._sorting = SORT_DEFAULT
9bac43
 
9bac43
     def __enter__(self):
9bac43
         """Initialises curses for later use.  Based on curses.wrapper
9bac43
@@ -994,14 +996,23 @@ class Tui(object):
9bac43
         self.screen.clrtobot()
9bac43
         stats = self.stats.get()
9bac43
 
9bac43
-        def sortkey(x):
9bac43
+        def sortCurAvg(x):
9bac43
+            # sort by current events if available
9bac43
             if stats[x][1]:
9bac43
                 return (-stats[x][1], -stats[x][0])
9bac43
             else:
9bac43
                 return (0, -stats[x][0])
9bac43
+
9bac43
+        def sortTotal(x):
9bac43
+            # sort by totals
9bac43
+            return (0, -stats[x][0])
9bac43
         total = 0.
9bac43
         for val in stats.values():
9bac43
             total += val[0]
9bac43
+        if self._sorting == SORT_DEFAULT:
9bac43
+            sortkey = sortCurAvg
9bac43
+        else:
9bac43
+            sortkey = sortTotal
9bac43
         for key in sorted(stats.keys(), key=sortkey):
9bac43
 
9bac43
             if row >= self.screen.getmaxyx()[0]:
9bac43
@@ -1025,6 +1036,7 @@ class Tui(object):
9bac43
                '   f     filter by regular expression',
9bac43
                '   g     filter by guest name',
9bac43
                '   h     display interactive commands reference',
9bac43
+               '   o     toggle sorting order (Total vs CurAvg/s)',
9bac43
                '   p     filter by PID',
9bac43
                '   q     quit',
9bac43
                '   r     reset stats',
9bac43
@@ -1215,6 +1227,8 @@ class Tui(object):
9bac43
                     sleeptime = self._delay_initial
9bac43
                 if char == 'h':
9bac43
                     self.show_help_interactive()
9bac43
+                if char == 'o':
9bac43
+                    self._sorting = not self._sorting
9bac43
                 if char == 'p':
9bac43
                     curses.curs_set(1)
9bac43
                     self.show_vm_selection_by_pid()
9bac43
@@ -1302,6 +1316,7 @@ Interactive Commands:
9bac43
    f     filter by regular expression
9bac43
    g     filter by guest name
9bac43
    h     display interactive commands reference
9bac43
+   o     toggle sorting order (Total vs CurAvg/s)
9bac43
    p     filter by PID
9bac43
    q     quit
9bac43
    r     reset stats
9bac43
diff --git a/scripts/kvm/kvm_stat.texi b/scripts/kvm/kvm_stat.texi
9bac43
index f0066ff..68d5024 100644
9bac43
--- a/scripts/kvm/kvm_stat.texi
9bac43
+++ b/scripts/kvm/kvm_stat.texi
9bac43
@@ -36,6 +36,9 @@ filter by guest name
9bac43
 @item h
9bac43
 @kindex h
9bac43
 display interactive commands reference
9bac43
+@item o
9bac43
+@kindex o
9bac43
+toggle sorting order (Total vs CurAvg/s)
9bac43
 @item p
9bac43
 @kindex p
9bac43
 filter by PID
9bac43
-- 
9bac43
1.8.3.1
9bac43