summaryrefslogtreecommitdiff
path: root/tools/kvm/kvm_stat
diff options
context:
space:
mode:
authorStefan Raspl <stefan.raspl@de.ibm.com>2018-02-05 15:59:57 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2018-02-24 03:43:41 +0300
commit3df33a0f34a3883b6696bff8cc8fcda3c7444a62 (patch)
treed88cec5c5fde40902b5fdbb6b75ac4c89172b4ec /tools/kvm/kvm_stat
parent369d5a85bb782ecf63c5bae9686c7e6104eea991 (diff)
downloadlinux-3df33a0f34a3883b6696bff8cc8fcda3c7444a62.tar.xz
tools/kvm_stat: fix crash when filtering out all non-child trace events
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 <raspl@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/kvm/kvm_stat')
-rwxr-xr-xtools/kvm/kvm_stat/kvm_stat6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index e3f0becb6632..4e0f282c5289 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -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)):