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

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