public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Raspl <raspl@linux.vnet.ibm.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, rkrcmar@redhat.com, frankja@linux.vnet.ibm.com
Subject: [PATCH 3/6] tools/kvm_stat: cache compiled regular expression
Date: Wed, 14 Feb 2018 22:45:50 +0100	[thread overview]
Message-ID: <20180214214553.96753-4-raspl@linux.vnet.ibm.com> (raw)
In-Reply-To: <20180214214553.96753-1-raspl@linux.vnet.ibm.com>

From: Stefan Raspl <stefan.raspl@de.ibm.com>

Should save us a couple of cycles.

Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
---
 tools/kvm/kvm_stat/kvm_stat | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat
index d7c80ac0374d..9f7e21cd5d19 100755
--- a/tools/kvm/kvm_stat/kvm_stat
+++ b/tools/kvm/kvm_stat/kvm_stat
@@ -480,7 +480,7 @@ class Provider(object):
         """Indicate whether field is valid according to fields_filter."""
         if not fields_filter:
             return True
-        return re.match(fields_filter, field) is not None
+        return fields_filter.match(field) is not None
 
     @staticmethod
     def walkdir(path):
@@ -811,9 +811,10 @@ class Stats(object):
 
     """
     def __init__(self, options):
-        self.providers = self._get_providers(options)
         self._pid_filter = options.pid
         self._fields_filter = options.fields
+        self._fields_filter_comp = re.compile(options.fields)
+        self.providers = self._get_providers(options)
         self.values = {}
 
     def _get_providers(self, options):
@@ -821,10 +822,12 @@ class Stats(object):
         providers = []
 
         if options.debugfs:
-            providers.append(DebugfsProvider(options.pid, options.fields,
+            providers.append(DebugfsProvider(self._pid_filter,
+                                             self._fields_filter_comp,
                                              options.dbgfs_include_past))
         if options.tracepoints or not providers:
-            providers.append(TracepointProvider(options.pid, options.fields))
+            providers.append(TracepointProvider(self._pid_filter,
+                                                self._fields_filter_comp))
 
         return providers
 
@@ -834,7 +837,7 @@ class Stats(object):
         # also clear the cache of old values.
         self.values = {}
         for provider in self.providers:
-            provider.update_fields(self._fields_filter)
+            provider.update_fields(self._fields_filter_comp)
 
     def reset(self):
         self.values = {}
@@ -849,6 +852,7 @@ class Stats(object):
     def fields_filter(self, fields_filter):
         if fields_filter != self._fields_filter:
             self._fields_filter = fields_filter
+            self._fields_filter_comp = re.compile(fields_filter)
             self._update_provider_filters()
 
     @property
@@ -1040,7 +1044,7 @@ class Tui(object):
             self.stats.fields_filter = DEFAULT_REGEX
 
         elif self.stats.fields_filter == DEFAULT_REGEX:
-            self.stats.fields_filter = None
+            self.stats.fields_filter = ''
 
     def _update_pid(self, pid):
         """Propagates pid selection to stats object."""
@@ -1548,7 +1552,7 @@ def main():
     stats = Stats(options)
 
     if options.fields == 'help':
-        stats.fields_filter = None
+        stats.fields_filter = ''
         event_list = []
         for key in stats.get().keys():
             event_list.append(key.split('(', 1)[0])
-- 
2.13.5

  parent reply	other threads:[~2018-02-14 21:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-14 21:45 [PATCH 0/6] tools/kvm_stat improvements Stefan Raspl
2018-02-14 21:45 ` [PATCH 1/6] tools/kvm_stat: mark private methods as such Stefan Raspl
2018-02-14 21:45 ` [PATCH 2/6] tools/kvm_stat: eliminate extra guest/pid selection dialog Stefan Raspl
2018-02-14 21:45 ` Stefan Raspl [this message]
2018-02-15  7:32   ` [PATCH 3/6] tools/kvm_stat: cache compiled regular expression Janosch Frank
2018-02-15  8:14     ` Stefan Raspl
2018-02-14 21:45 ` [PATCH 4/6] tools/kvm_stat: separate drilldown and fields filtering Stefan Raspl
2018-02-14 21:45 ` [PATCH 5/6] tools/kvm_stat: group child events indented after parent Stefan Raspl
2018-02-14 21:45 ` [PATCH 6/6] tools/kvm_stat: print 'Total' line for multiple events only Stefan Raspl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180214214553.96753-4-raspl@linux.vnet.ibm.com \
    --to=raspl@linux.vnet.ibm.com \
    --cc=frankja@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox