diff mbox

[PULL,38/49] scripts/kvm/kvm_stat: Fixup filtering

Message ID 1453816041-36362-39-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini Jan. 26, 2016, 1:47 p.m. UTC
From: Janosch Frank <frankja@linux.vnet.ibm.com>

When filtering, the group leader event should not be disabled, as all
other events under it will also be disabled. Also we should make sure
that values from disabled fields will not be displayed.

This also filters the fields from the log and batch output for better
readability.

Also the drilldown update now directly checks for the stats' field
filter and (un)sets drilldown accordingly.

Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
Message-Id: <1452525484-32309-33-git-send-email-frankja@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/kvm/kvm_stat | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 2a1842e..eb97a65 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -467,6 +467,9 @@  class TracepointProvider(object):
                                       trace_filter=tracefilter))
             self.group_leaders.append(group)
 
+    def available_fields(self):
+        return self.get_available_fields()
+
     @property
     def fields(self):
         return self._fields
@@ -475,23 +478,30 @@  class TracepointProvider(object):
     def fields(self, fields):
         self._fields = fields
         for group in self.group_leaders:
-            for event in group.events:
+            for index, event in enumerate(group.events):
                 if event.name in fields:
                     event.reset()
                     event.enable()
                 else:
-                    event.disable()
+                    # Do not disable the group leader.
+                    # It would disable all of its events.
+                    if index != 0:
+                        event.disable()
 
     def read(self):
         ret = defaultdict(int)
         for group in self.group_leaders:
             for name, val in group.read().iteritems():
-                ret[name] += val
+                if name in self._fields:
+                    ret[name] += val
         return ret
 
 class DebugfsProvider(object):
     def __init__(self):
-        self._fields = walkdir(PATH_DEBUGFS_KVM)[2]
+        self._fields = self.get_available_fields()
+
+    def get_available_fields(self):
+        return walkdir(PATH_DEBUGFS_KVM)[2]
 
     @property
     def fields(self):
@@ -523,7 +533,8 @@  class Stats(object):
         # also clear the cache of old values.
         self.values = {}
         for provider in self.providers:
-            provider_fields = [key for key in provider.fields if wanted(key)]
+            provider_fields = [key for key in provider.get_available_fields()
+                               if wanted(key)]
             provider.fields = provider_fields
 
     @property
@@ -555,7 +566,6 @@  class Tui(object):
         self.stats = stats
         self.screen = None
         self.drilldown = False
-        self.fields_filter = self.stats.fields_filter
         self.update_drilldown()
 
     def __enter__(self):
@@ -586,11 +596,11 @@  class Tui(object):
             curses.endwin()
 
     def update_drilldown(self):
-        if not self.fields_filter:
-            if self.drilldown:
-                self.stats.fields_filter = None
-            else:
-                self.stats.fields_filter = r'^[^\(]*$'
+        if not self.stats.fields_filter:
+            self.stats.fields_filter = r'^[^\(]*$'
+
+        elif self.stats.fields_filter == r'^[^\(]*$':
+            self.stats.fields_filter = None
 
     def refresh(self, sleeptime):
         self.screen.erase()