Blame SOURCES/kvm-tools-kvm_stat-display-guest-list-in-pid-guest-selec.patch

9bac43
From 53a1267b00b7e981a5f67b9d241da6008004d002 Mon Sep 17 00:00:00 2001
9bac43
From: David Hildenbrand <david@redhat.com>
9bac43
Date: Tue, 17 Oct 2017 19:16:00 +0200
9bac43
Subject: [PATCH 55/69] tools/kvm_stat: display guest list in pid/guest
9bac43
 selection screens
9bac43
9bac43
RH-Author: David Hildenbrand <david@redhat.com>
9bac43
Message-id: <20171017191605.2378-35-david@redhat.com>
9bac43
Patchwork-id: 77338
9bac43
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 34/39] tools/kvm_stat: display guest list in pid/guest selection screens
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 865279c53ca9d88718d974bb014b2c6ce259ac75
9bac43
9bac43
commit 865279c53ca9d88718d974bb014b2c6ce259ac75
9bac43
Author: Stefan Raspl <raspl@linux.vnet.ibm.com>
9bac43
Date:   Wed Jun 7 21:08:43 2017 +0200
9bac43
9bac43
    tools/kvm_stat: display guest list in pid/guest selection screens
9bac43
9bac43
    Display a (possibly inaccurate) list of all running guests. Note that we
9bac43
    leave a bit of extra room above the list for potential error messages.
9bac43
    Furthermore, we deliberately do not reject pids or guest names that are
9bac43
    not in our list, as we cannot rule out that our fuzzy approach might be
9bac43
    in error somehow.
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 | 49 +++++++++++++++++++++++++++++++++++++------------
9bac43
 1 file changed, 37 insertions(+), 12 deletions(-)
9bac43
9bac43
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
9bac43
index cf7aa28..2cf5176 100755
9bac43
--- a/scripts/kvm/kvm_stat
9bac43
+++ b/scripts/kvm/kvm_stat
9bac43
@@ -894,15 +894,9 @@ class Tui(object):
9bac43
             curses.nocbreak()
9bac43
             curses.endwin()
9bac43
 
9bac43
-    @staticmethod
9bac43
-    def get_pid_from_gname(gname):
9bac43
-        """Fuzzy function to convert guest name to QEMU process pid.
9bac43
-
9bac43
-        Returns a list of potential pids, can be empty if no match found.
9bac43
-        Throws an exception on processing errors.
9bac43
-
9bac43
-        """
9bac43
-        pids = []
9bac43
+    def get_all_gnames(self):
9bac43
+        """Returns a list of (pid, gname) tuples of all running guests"""
9bac43
+        res = []
9bac43
         try:
9bac43
             child = subprocess.Popen(['ps', '-A', '--format', 'pid,args'],
9bac43
                                      stdout=subprocess.PIPE)
9bac43
@@ -912,11 +906,40 @@ class Tui(object):
9bac43
             line = line.lstrip().split(' ', 1)
9bac43
             # perform a sanity check before calling the more expensive
9bac43
             # function to possibly extract the guest name
9bac43
-            if (' -name ' in line[1] and
9bac43
-                    gname == self.get_gname_from_pid(line[0])):
9bac43
-                pids.append(int(line[0]))
9bac43
+            if ' -name ' in line[1]:
9bac43
+                res.append((line[0], self.get_gname_from_pid(line[0])))
9bac43
         child.stdout.close()
9bac43
 
9bac43
+        return res
9bac43
+
9bac43
+    def print_all_gnames(self, row):
9bac43
+        """Print a list of all running guests along with their pids."""
9bac43
+        self.screen.addstr(row, 2, '%8s  %-60s' %
9bac43
+                           ('Pid', 'Guest Name (fuzzy list, might be '
9bac43
+                            'inaccurate!)'),
9bac43
+                           curses.A_UNDERLINE)
9bac43
+        row += 1
9bac43
+        try:
9bac43
+            for line in self.get_all_gnames():
9bac43
+                self.screen.addstr(row, 2, '%8s  %-60s' % (line[0], line[1]))
9bac43
+                row += 1
9bac43
+                if row >= self.screen.getmaxyx()[0]:
9bac43
+                    break
9bac43
+        except Exception:
9bac43
+            self.screen.addstr(row + 1, 2, 'Not available')
9bac43
+
9bac43
+    def get_pid_from_gname(self, gname):
9bac43
+        """Fuzzy function to convert guest name to QEMU process pid.
9bac43
+
9bac43
+        Returns a list of potential pids, can be empty if no match found.
9bac43
+        Throws an exception on processing errors.
9bac43
+
9bac43
+        """
9bac43
+        pids = []
9bac43
+        for line in self.get_all_gnames():
9bac43
+            if gname == line[1]:
9bac43
+                pids.append(int(line[0]))
9bac43
+
9bac43
         return pids
9bac43
 
9bac43
     @staticmethod
9bac43
@@ -1102,6 +1125,7 @@ class Tui(object):
9bac43
                                'This might limit the shown data to the trace '
9bac43
                                'statistics.')
9bac43
             self.screen.addstr(5, 0, msg)
9bac43
+            self.print_all_gnames(7)
9bac43
 
9bac43
             curses.echo()
9bac43
             self.screen.addstr(3, 0, "Pid [0 or pid]: ")
9bac43
@@ -1171,6 +1195,7 @@ class Tui(object):
9bac43
                                'This might limit the shown data to the trace '
9bac43
                                'statistics.')
9bac43
             self.screen.addstr(5, 0, msg)
9bac43
+            self.print_all_gnames()
9bac43
             curses.echo()
9bac43
             self.screen.addstr(3, 0, "Guest [ENTER or guest]: ")
9bac43
             gname = self.screen.getstr()
9bac43
-- 
9bac43
1.8.3.1
9bac43