Skip to content

Commit

Permalink
tools/kvm_stat: fix updates for dead guests
Browse files Browse the repository at this point in the history
With pid filtering active, when a guest is removed e.g. via virsh shutdown,
successive updates produce garbage.
Therefore, we add code to detect this case and prevent further body updates.
Note that when displaying the help dialog via 'h' in this case, once we exit
we're stuck with the 'Collecting data...' message till we remove the filter.

Signed-off-by: Stefan Raspl <[email protected]>
Signed-off-by: Radim Krčmář <[email protected]>
  • Loading branch information
Stefan-Raspl authored and rkrcmar committed Aug 30, 2018
1 parent 617c66b commit 710ab11
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tools/kvm/kvm_stat/kvm_stat
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,9 @@ class Tui(object):

return sorted_items

if not self._is_running_guest(self.stats.pid_filter):
# leave final data on screen
return
row = 3
self.screen.move(row, 0)
self.screen.clrtobot()
Expand Down Expand Up @@ -1327,6 +1330,12 @@ class Tui(object):
msg = '"' + str(val) + '": Invalid value'
self._refresh_header()

def _is_running_guest(self, pid):
"""Check if pid is still a running process."""
if not pid:
return True
return os.path.isdir(os.path.join('/proc/', str(pid)))

def _show_vm_selection_by_guest(self):
"""Draws guest selection mask.
Expand Down Expand Up @@ -1354,7 +1363,7 @@ class Tui(object):
if not guest or guest == '0':
break
if guest.isdigit():
if not os.path.isdir(os.path.join('/proc/', guest)):
if not self._is_running_guest(guest):
msg = '"' + guest + '": Not a running process'
continue
pid = int(guest)
Expand Down

0 comments on commit 710ab11

Please sign in to comment.