diff mbox

[1/8] tools/kvm_stat: fix crash when filtering out all non-child trace events

Message ID 20180205130004.29691-2-raspl@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Raspl Feb. 5, 2018, 12:59 p.m. UTC
From: Stefan Raspl <stefan.raspl@de.ibm.com>

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>
---
 tools/kvm/kvm_stat/kvm_stat | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox

Patch

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index f64feaa6d1b4..681c79a139c8 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)):