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

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