Blob Blame History Raw
From 55f7ed9b2ccc2761e353d14680fe5d1ea8bc11be Mon Sep 17 00:00:00 2001
From: David Hildenbrand <david@redhat.com>
Date: Tue, 17 Oct 2017 19:15:59 +0200
Subject: [PATCH 54/69] tools/kvm_stat: add new interactive command 'o'

RH-Author: David Hildenbrand <david@redhat.com>
Message-id: <20171017191605.2378-34-david@redhat.com>
Patchwork-id: 77347
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 33/39] tools/kvm_stat: add new interactive command 'o'
Bugzilla: 1497137
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Thomas Huth <thuth@redhat.com>

Upstream-status: linux.git 6667ae8f395099257afca0963838d2dc50a18da7

Convertion of documentation (for man page generation) to texi.

commit 6667ae8f395099257afca0963838d2dc50a18da7
Author: Stefan Raspl <raspl@linux.vnet.ibm.com>
Date:   Wed Jun 7 21:08:41 2017 +0200

    tools/kvm_stat: add new interactive command 'o'

    Add new interactive command 'o' to toggle sorting by 'CurAvg/s' (default)
    and 'Total' columns.

    Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 scripts/kvm/kvm_stat      | 17 ++++++++++++++++-
 scripts/kvm/kvm_stat.texi |  3 +++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 1276b88..cf7aa28 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -848,6 +848,7 @@ DELAY_DEFAULT = 3.0
 MAX_GUEST_NAME_LEN = 48
 MAX_REGEX_LEN = 44
 DEFAULT_REGEX = r'^[^\(]*$'
+SORT_DEFAULT = 0
 
 
 class Tui(object):
@@ -857,6 +858,7 @@ class Tui(object):
         self.screen = None
         self._delay_initial = 0.25
         self._delay_regular = DELAY_DEFAULT
+        self._sorting = SORT_DEFAULT
 
     def __enter__(self):
         """Initialises curses for later use.  Based on curses.wrapper
@@ -994,14 +996,23 @@ class Tui(object):
         self.screen.clrtobot()
         stats = self.stats.get()
 
-        def sortkey(x):
+        def sortCurAvg(x):
+            # sort by current events if available
             if stats[x][1]:
                 return (-stats[x][1], -stats[x][0])
             else:
                 return (0, -stats[x][0])
+
+        def sortTotal(x):
+            # sort by totals
+            return (0, -stats[x][0])
         total = 0.
         for val in stats.values():
             total += val[0]
+        if self._sorting == SORT_DEFAULT:
+            sortkey = sortCurAvg
+        else:
+            sortkey = sortTotal
         for key in sorted(stats.keys(), key=sortkey):
 
             if row >= self.screen.getmaxyx()[0]:
@@ -1025,6 +1036,7 @@ class Tui(object):
                '   f     filter by regular expression',
                '   g     filter by guest name',
                '   h     display interactive commands reference',
+               '   o     toggle sorting order (Total vs CurAvg/s)',
                '   p     filter by PID',
                '   q     quit',
                '   r     reset stats',
@@ -1215,6 +1227,8 @@ class Tui(object):
                     sleeptime = self._delay_initial
                 if char == 'h':
                     self.show_help_interactive()
+                if char == 'o':
+                    self._sorting = not self._sorting
                 if char == 'p':
                     curses.curs_set(1)
                     self.show_vm_selection_by_pid()
@@ -1302,6 +1316,7 @@ Interactive Commands:
    f     filter by regular expression
    g     filter by guest name
    h     display interactive commands reference
+   o     toggle sorting order (Total vs CurAvg/s)
    p     filter by PID
    q     quit
    r     reset stats
diff --git a/scripts/kvm/kvm_stat.texi b/scripts/kvm/kvm_stat.texi
index f0066ff..68d5024 100644
--- a/scripts/kvm/kvm_stat.texi
+++ b/scripts/kvm/kvm_stat.texi
@@ -36,6 +36,9 @@ filter by guest name
 @item h
 @kindex h
 display interactive commands reference
+@item o
+@kindex o
+toggle sorting order (Total vs CurAvg/s)
 @item p
 @kindex p
 filter by PID
-- 
1.8.3.1