Skip to content

Commit

Permalink
tools/kvm_stat: fix crash when filtering out all non-child trace events
Browse files Browse the repository at this point in the history
When we apply a filter that will only leave child trace events, we
receive a ZeroDivisionError when calculating the percentages.
In that case, provide percentages based on child events only.
To reproduce, run 'kvm_stat -f .*[\(].*'.

Signed-off-by: Stefan Raspl <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Stefan-Raspl authored and bonzini committed Feb 24, 2018
1 parent 369d5a8 commit 3df33a0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/kvm/kvm_stat/kvm_stat
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,15 @@ class Tui(object):
self.screen.clrtobot()
stats = self.stats.get(self._display_guests)
total = 0.
ctotal = 0.
for key, values in stats.items():
if key.find('(') == -1:
total += values.value
else:
ctotal += values.value
if total == 0.:
# we don't have any fields, or all non-child events are filtered
total = ctotal

if self._sorting == SORT_DEFAULT:
def sortkey((_k, v)):
Expand Down

0 comments on commit 3df33a0

Please sign in to comment.