From: Stefan Raspl <raspl@linux.vnet.ibm.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, rkrcmar@redhat.com, frankja@linux.vnet.ibm.com
Subject: [PATCH v1 19/19] tools/kvm_stat: display guest list in pid/guest selection screens
Date: Wed, 7 Jun 2017 21:08:43 +0200 [thread overview]
Message-ID: <20170607190843.76869-20-raspl@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170607190843.76869-1-raspl@linux.vnet.ibm.com>
Display a (possibly inaccurate) list of all running guests. Note that we
leave a bit of extra room above the list for potential error messages.
Furthermore, we deliberately do not reject pids or guest names that are
not in our list, as we cannot rule out that our fuzzy approach might be
in error somehow.
Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
---
tools/kvm/kvm_stat/kvm_stat | 49 ++++++++++++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index f1cec0103757..8237d9bb8547 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -954,15 +954,9 @@ class Tui(object):
curses.nocbreak()
curses.endwin()
- @staticmethod
- def get_pid_from_gname(gname):
- """Fuzzy function to convert guest name to QEMU process pid.
-
- Returns a list of potential pids, can be empty if no match found.
- Throws an exception on processing errors.
-
- """
- pids = []
+ def get_all_gnames(self):
+ """Returns a list of (pid, gname) tuples of all running guests"""
+ res = []
try:
child = subprocess.Popen(['ps', '-A', '--format', 'pid,args'],
stdout=subprocess.PIPE)
@@ -972,11 +966,40 @@ class Tui(object):
line = line.lstrip().split(' ', 1)
# perform a sanity check before calling the more expensive
# function to possibly extract the guest name
- if (' -name ' in line[1] and
- gname == self.get_gname_from_pid(line[0])):
- pids.append(int(line[0]))
+ if ' -name ' in line[1]:
+ res.append((line[0], self.get_gname_from_pid(line[0])))
child.stdout.close()
+ return res
+
+ def print_all_gnames(self, row):
+ """Print a list of all running guests along with their pids."""
+ self.screen.addstr(row, 2, '%8s %-60s' %
+ ('Pid', 'Guest Name (fuzzy list, might be '
+ 'inaccurate!)'),
+ curses.A_UNDERLINE)
+ row += 1
+ try:
+ for line in self.get_all_gnames():
+ self.screen.addstr(row, 2, '%8s %-60s' % (line[0], line[1]))
+ row += 1
+ if row >= self.screen.getmaxyx()[0]:
+ break
+ except Exception:
+ self.screen.addstr(row + 1, 2, 'Not available')
+
+ def get_pid_from_gname(self, gname):
+ """Fuzzy function to convert guest name to QEMU process pid.
+
+ Returns a list of potential pids, can be empty if no match found.
+ Throws an exception on processing errors.
+
+ """
+ pids = []
+ for line in self.get_all_gnames():
+ if gname == line[1]:
+ pids.append(int(line[0]))
+
return pids
@staticmethod
@@ -1167,6 +1190,7 @@ class Tui(object):
'This might limit the shown data to the trace '
'statistics.')
self.screen.addstr(5, 0, msg)
+ self.print_all_gnames(7)
curses.echo()
self.screen.addstr(3, 0, "Pid [0 or pid]: ")
@@ -1236,6 +1260,7 @@ class Tui(object):
'This might limit the shown data to the trace '
'statistics.')
self.screen.addstr(5, 0, msg)
+ self.print_all_gnames()
curses.echo()
self.screen.addstr(3, 0, "Guest [ENTER or guest]: ")
gname = self.screen.getstr()
--
2.11.2
next prev parent reply other threads:[~2017-06-07 19:09 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-07 19:08 [PATCH v1 00/19] tools/kvm_stat: More misc patches Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 01/19] tools/kvm_stat: fix typo Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 02/19] tools/kvm_stat: fix event counts display for interrupted intervals Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 03/19] tools/kvm_stat: fix undue use of initial sleeptime Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 04/19] tools/kvm_stat: remove unnecessary header redraws Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 05/19] tools/kvm_stat: simplify line print logic Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 06/19] tools/kvm_stat: removed unused function Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 07/19] tools/kvm_stat: remove extra statement Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 08/19] tools/kvm_stat: simplify initializers Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 09/19] tools/kvm_stat: move functions to corresponding classes Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 10/19] tools/kvm_stat: show cursor in selection screens Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 11/19] tools/kvm_stat: display message indicating lack of events Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 12/19] tools/kvm_stat: make heading look a bit more like 'top' Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 13/19] tools/kvm_stat: rename 'Current' column to 'CurAvg/s' Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 14/19] tools/kvm_stat: add new interactive command 'h' Stefan Raspl
2017-06-08 16:19 ` Paolo Bonzini
2017-06-20 9:10 ` Stefan Raspl
2017-06-20 12:34 ` Paolo Bonzini
2017-06-07 19:08 ` [PATCH v1 15/19] tools/kvm_stat: add new interactive command 's' Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 16/19] tools/kvm_stat: add new interactive command 't' Stefan Raspl
2017-06-08 16:21 ` Paolo Bonzini
2017-06-20 9:10 ` Stefan Raspl
2017-06-20 12:34 ` Paolo Bonzini
2017-06-20 13:09 ` Stefan Raspl
2017-06-20 13:17 ` Paolo Bonzini
2017-06-20 14:17 ` Stefan Raspl
2017-06-20 14:47 ` Paolo Bonzini
2017-06-21 6:54 ` Stefan Raspl
2017-06-21 10:37 ` Paolo Bonzini
2017-06-22 7:46 ` Stefan Raspl
2017-06-22 7:52 ` Paolo Bonzini
2017-06-22 8:51 ` Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 17/19] tools/kvm_stat: add new interactive command 'o' Stefan Raspl
2017-06-07 19:08 ` [PATCH v1 18/19] tools/kvm_stat: add new interactive command 'b' Stefan Raspl
2017-06-08 16:24 ` Paolo Bonzini
2017-06-20 9:10 ` Stefan Raspl
2017-06-20 12:33 ` Paolo Bonzini
2017-06-20 13:07 ` Stefan Raspl
2017-06-20 13:10 ` Paolo Bonzini
2017-06-20 14:41 ` Stefan Raspl
2017-06-20 14:47 ` Paolo Bonzini
2017-06-21 4:51 ` Stefan Raspl
2017-06-07 19:08 ` Stefan Raspl [this message]
2017-06-08 16:25 ` [PATCH v1 00/19] tools/kvm_stat: More misc patches Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170607190843.76869-20-raspl@linux.vnet.ibm.com \
--to=raspl@linux.vnet.ibm.com \
--cc=frankja@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.