aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Raspl <stefan.raspl@de.ibm.com>2018-02-05 07:59:57 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2018-02-23 19:43:41 -0500
commit3df33a0f34a3883b6696bff8cc8fcda3c7444a62 (patch)
treed88cec5c5fde40902b5fdbb6b75ac4c89172b4ec
parent369d5a85bb782ecf63c5bae9686c7e6104eea991 (diff)
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>
-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):
1084 self.screen.clrtobot() 1084 self.screen.clrtobot()
1085 stats = self.stats.get(self._display_guests) 1085 stats = self.stats.get(self._display_guests)
1086 total = 0. 1086 total = 0.
1087 ctotal = 0.
1087 for key, values in stats.items(): 1088 for key, values in stats.items():
1088 if key.find('(') == -1: 1089 if key.find('(') == -1:
1089 total += values.value 1090 total += values.value
1091 else:
1092 ctotal += values.value
1093 if total == 0.:
1094 # we don't have any fields, or all non-child events are filtered
1095 total = ctotal
1090 1096
1091 if self._sorting == SORT_DEFAULT: 1097 if self._sorting == SORT_DEFAULT:
1092 def sortkey((_k, v)): 1098 def sortkey((_k, v)):