qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Janosch Frank <frankja@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 27/49] scripts/kvm/kvm_stat: Encapsulate filters variable
Date: Tue, 26 Jan 2016 14:46:59 +0100	[thread overview]
Message-ID: <1453816041-36362-28-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1453816041-36362-1-git-send-email-pbonzini@redhat.com>

From: Janosch Frank <frankja@linux.vnet.ibm.com>

The variable was only used in one class but still was defined
globally. Additionaly the detect_platform routine which prepares the
data that goes into the variable was called on each start of the
script, no matter if the class was needed.

To make the variable local to the TracepointProvider class, a new
function that calls detect_platform and returns the filters was
introduced.

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

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 083dd2f..7837f40 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -302,10 +302,14 @@ def get_online_cpus():
         cpu_string = cpu_list.readline()
         return parse_int_list(cpu_string)
 
-filters = {}
-filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
-if EXIT_REASONS:
-    filters['kvm_exit'] = ('exit_reason', EXIT_REASONS)
+
+def get_filters():
+    detect_platform()
+    filters = {}
+    filters['kvm_userspace_exit'] = ('reason', USERSPACE_EXIT_REASONS)
+    if EXIT_REASONS:
+        filters['kvm_exit'] = ('exit_reason', EXIT_REASONS)
+    return filters
 
 libc = ctypes.CDLL('libc.so.6', use_errno=True)
 syscall = libc.syscall
@@ -385,6 +389,7 @@ class Event(object):
 class TracepointProvider(object):
     def __init__(self):
         self.group_leaders = []
+        self.filters = get_filters()
         self._fields = self.get_available_fields()
         self.setup_traces()
         self.fields = self._fields
@@ -394,8 +399,8 @@ class TracepointProvider(object):
         fields = walkdir(path)[1]
         extra = []
         for field in fields:
-            if field in filters:
-                filter_name_, filter_dicts = filters[field]
+            if field in self.filters:
+                filter_name_, filter_dicts = self.filters[field]
                 for name in filter_dicts:
                     extra.append(field + '(' + name + ')')
         fields += extra
@@ -420,8 +425,9 @@ class TracepointProvider(object):
                 match = re.match(r'(.*)\((.*)\)', name)
                 if match:
                     tracepoint, sub = match.groups()
-                    tracefilter = '%s==%d\0' % (filters[tracepoint][0],
-                                                filters[tracepoint][1][sub])
+                    tracefilter = ('%s==%d\0' %
+                                   (self.filters[tracepoint][0],
+                                    self.filters[tracepoint][1][sub]))
                 group.add_event(name, event_set='kvm',
                                 tracepoint=tracepoint,
                                 tracefilter=tracefilter)
@@ -652,7 +658,6 @@ def check_access():
 
 def main():
     check_access()
-    detect_platform()
     options = get_options()
     providers = get_providers(options)
     stats = Stats(providers, fields=options.fields)
-- 
1.8.3.1

  parent reply	other threads:[~2016-01-26 13:48 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 13:46 [Qemu-devel] [PULL 00/49] chardev, NBD, cpus, scripts/ changes for 2015-01-26 Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 01/49] char: remove fixed length filename allocation Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 02/49] char: convert from GIOChannel to QIOChannel Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 03/49] char: don't assume telnet initialization will not block Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 04/49] char: introduce support for TLS encrypted TCP chardev backend Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 05/49] docs: Style the command and its options in the synopsis Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 06/49] qemu-char: avoid leak in qemu_chr_open_pp_fd Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 07/49] scripts/kvm/kvm_stat: Cleanup of multiple imports Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 08/49] scripts/kvm/kvm_stat: Replaced os.listdir with os.walk Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 09/49] scripts/kvm/kvm_stat: Make constants uppercase Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 10/49] scripts/kvm/kvm_stat: Removed unneeded PERF constants Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 11/49] scripts/kvm/kvm_stat: Mark globals in functions Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 12/49] scripts/kvm/kvm_stat: Invert dictionaries Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 13/49] scripts/kvm/kvm_stat: Cleanup of path variables Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 14/49] scripts/kvm/kvm_stat: Improve debugfs access checking Paolo Bonzini
2016-02-02 14:02   ` Christian Borntraeger
2016-02-02 14:25     ` Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 15/49] scripts/kvm/kvm_stat: Introduce main function Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 16/49] scripts/kvm/kvm_stat: Fix spaces around keyword assignments Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 17/49] scripts/kvm/kvm_stat: Rename variables that redefine globals Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 18/49] scripts/kvm/kvm_stat: Moved DebugfsProvider Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 19/49] scripts/kvm/kvm_stat: Fixup syscall error reporting Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 20/49] scripts/kvm/kvm_stat: Set sensible no. files rlimit Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 21/49] scripts/kvm/kvm_stat: Cleanup of platform detection Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 22/49] scripts/kvm/kvm_stat: Make cpu detection a function Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 23/49] scripts/kvm/kvm_stat: Rename _perf_event_open Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 24/49] scripts/kvm/kvm_stat: Introduce properties for providers Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 25/49] scripts/kvm/kvm_stat: Cleanup of TracepointProvider Paolo Bonzini
2016-01-26 13:46 ` [Qemu-devel] [PULL 26/49] scripts/kvm/kvm_stat: Cleanup cpu list retrieval Paolo Bonzini
2016-01-26 13:46 ` Paolo Bonzini [this message]
2016-01-26 13:47 ` [Qemu-devel] [PULL 28/49] scripts/kvm/kvm_stat: Cleanup of Stats class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 29/49] scripts/kvm/kvm_stat: Cleanup of Groups class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 30/49] scripts/kvm/kvm_stat: Cleanup of Event class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 31/49] scripts/kvm/kvm_stat: Group arch specific data Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 32/49] scripts/kvm/kvm_stat: Remove unneeded X86_EXIT_REASONS Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 33/49] scripts/kvm/kvm_stat: Make tui function a class Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 34/49] scripts/kvm/kvm_stat: Fix output formatting Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 35/49] scripts/kvm/kvm_stat: Cleanup and pre-init perf_event_attr Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 36/49] scripts/kvm/kvm_stat: Read event values as u64 Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 37/49] scripts/kvm/kvm_stat: Fix rlimit for unprivileged users Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 38/49] scripts/kvm/kvm_stat: Fixup filtering Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 39/49] scripts/kvm/kvm_stat: Add interactive filtering Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 40/49] scripts/kvm/kvm_stat: Add optparse description Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 41/49] cpus: use broadcast on qemu_pause_cond Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 42/49] memory: exit when hugepage allocation fails if mem-prealloc Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 43/49] nbd: add missed aio_context_acquire in nbd_export_new Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 44/49] scripts/dump-guest-memory.py: Move constants to the top Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 45/49] scripts/dump-guest-memory.py: Make methods functions Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 46/49] scripts/dump-guest-memory.py: Improve python 3 compatibility Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 47/49] scripts/dump-guest-memory.py: Cleanup functions Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 48/49] scripts/dump-guest-memory.py: Introduce multi-arch support Paolo Bonzini
2016-01-26 13:47 ` [Qemu-devel] [PULL 49/49] scripts/dump-guest-memory.py: Fix module docstring Paolo Bonzini
2016-01-26 14:38 ` [Qemu-devel] [PULL 00/49] chardev, NBD, cpus, scripts/ changes for 2015-01-26 Peter Maydell
2016-01-26 15:29   ` Daniel P. Berrange
2016-01-26 16:06   ` [Qemu-devel] [PATCH] char: make io_channel_send be used unconditionally Daniel P. Berrange

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=1453816041-36362-28-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=frankja@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).