Commit 865279c5 authored by Stefan Raspl's avatar Stefan Raspl Committed by Paolo Bonzini

tools/kvm_stat: display guest list in pid/guest selection screens

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: default avatarStefan Raspl <raspl@linux.vnet.ibm.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 6667ae8f
...@@ -894,15 +894,9 @@ class Tui(object): ...@@ -894,15 +894,9 @@ class Tui(object):
curses.nocbreak() curses.nocbreak()
curses.endwin() curses.endwin()
@staticmethod def get_all_gnames(self):
def get_pid_from_gname(gname): """Returns a list of (pid, gname) tuples of all running guests"""
"""Fuzzy function to convert guest name to QEMU process pid. res = []
Returns a list of potential pids, can be empty if no match found.
Throws an exception on processing errors.
"""
pids = []
try: try:
child = subprocess.Popen(['ps', '-A', '--format', 'pid,args'], child = subprocess.Popen(['ps', '-A', '--format', 'pid,args'],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
...@@ -912,11 +906,40 @@ class Tui(object): ...@@ -912,11 +906,40 @@ class Tui(object):
line = line.lstrip().split(' ', 1) line = line.lstrip().split(' ', 1)
# perform a sanity check before calling the more expensive # perform a sanity check before calling the more expensive
# function to possibly extract the guest name # function to possibly extract the guest name
if (' -name ' in line[1] and if ' -name ' in line[1]:
gname == self.get_gname_from_pid(line[0])): res.append((line[0], self.get_gname_from_pid(line[0])))
pids.append(int(line[0]))
child.stdout.close() 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 return pids
@staticmethod @staticmethod
...@@ -1102,6 +1125,7 @@ class Tui(object): ...@@ -1102,6 +1125,7 @@ class Tui(object):
'This might limit the shown data to the trace ' 'This might limit the shown data to the trace '
'statistics.') 'statistics.')
self.screen.addstr(5, 0, msg) self.screen.addstr(5, 0, msg)
self.print_all_gnames(7)
curses.echo() curses.echo()
self.screen.addstr(3, 0, "Pid [0 or pid]: ") self.screen.addstr(3, 0, "Pid [0 or pid]: ")
...@@ -1171,6 +1195,7 @@ class Tui(object): ...@@ -1171,6 +1195,7 @@ class Tui(object):
'This might limit the shown data to the trace ' 'This might limit the shown data to the trace '
'statistics.') 'statistics.')
self.screen.addstr(5, 0, msg) self.screen.addstr(5, 0, msg)
self.print_all_gnames()
curses.echo() curses.echo()
self.screen.addstr(3, 0, "Guest [ENTER or guest]: ") self.screen.addstr(3, 0, "Guest [ENTER or guest]: ")
gname = self.screen.getstr() gname = self.screen.getstr()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment