]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
tools/kvm_stat: fix crash when filtering out all non-child trace events
authorStefan Raspl <stefan.raspl@de.ibm.com>
Mon, 5 Feb 2018 12:59:57 +0000 (13:59 +0100)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 12 Apr 2018 13:26:55 +0000 (10:26 -0300)
BugLink: http://bugs.launchpad.net/bugs/1734130
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>
(cherry picked from commit 3df33a0f34a3883b6696bff8cc8fcda3c7444a62)
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
tools/kvm/kvm_stat/kvm_stat

index e3f0becb6632e96d181b7f545ff800a03a3d7be6..4e0f282c52896489fcdb5d25974d07a80ec7531e 100755 (executable)
@@ -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)):