qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 02/11] kvm_stat: allow choosing between tracepoints and old stats
Date: Wed,  4 Jun 2014 13:20:03 +0200	[thread overview]
Message-ID: <1401880812-818-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1401880812-818-1-git-send-email-pbonzini@redhat.com>

The old stats contain information not available in the tracepoints.
By default, keep the old behavior, but allow choosing which set of stats
to present, or even both.

Inspired by a patch from Marcelo Tosatti.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/kvm/kvm_stat | 60 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 41 insertions(+), 19 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 762544b..d7e97e7 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -352,8 +352,8 @@ class TracepointProvider(object):
         return ret
 
 class Stats:
-    def __init__(self, provider, fields = None):
-        self.provider = provider
+    def __init__(self, providers, fields = None):
+        self.providers = providers
         self.fields_filter = fields
         self._update()
     def _update(self):
@@ -362,22 +362,25 @@ class Stats:
             if not self.fields_filter:
                 return True
             return re.match(self.fields_filter, key) is not None
-        self.values = dict([(key, None)
-                            for key in provider.fields()
-                            if wanted(key)])
-        self.provider.select(self.values.keys())
+        self.values = dict()
+        for d in providers:
+            provider_fields = [key for key in d.fields() if wanted(key)]
+            for key in provider_fields:
+                self.values[key] = None
+            d.select(provider_fields)
     def set_fields_filter(self, fields_filter):
         self.fields_filter = fields_filter
         self._update()
     def get(self):
-        new = self.provider.read()
-        for key in self.provider.fields():
-            oldval = self.values.get(key, (0, 0))
-            newval = new[key]
-            newdelta = None
-            if oldval is not None:
-                newdelta = newval - oldval[0]
-            self.values[key] = (newval, newdelta)
+        for d in providers:
+            new = d.read()
+            for key in d.fields():
+                oldval = self.values.get(key, (0, 0))
+                newval = new[key]
+                newdelta = None
+                if oldval is not None:
+                    newdelta = newval - oldval[0]
+                self.values[key] = (newval, newdelta)
         return self.values
 
 if not os.access('/sys/kernel/debug', os.F_OK):
@@ -487,6 +490,18 @@ options.add_option('-l', '--log',
                    dest = 'log',
                    help = 'run in logging mode (like vmstat)',
                    )
+options.add_option('-t', '--tracepoints',
+                   action = 'store_true',
+                   default = False,
+                   dest = 'tracepoints',
+                   help = 'retrieve statistics from tracepoints',
+                   )
+options.add_option('-d', '--debugfs',
+                   action = 'store_true',
+                   default = False,
+                   dest = 'debugfs',
+                   help = 'retrieve statistics from debugfs',
+                   )
 options.add_option('-f', '--fields',
                    action = 'store',
                    default = None,
@@ -495,12 +510,19 @@ options.add_option('-f', '--fields',
                    )
 (options, args) = options.parse_args(sys.argv)
 
-try:
-    provider = TracepointProvider()
-except:
-    provider = DebugfsProvider()
+providers = []
+if options.tracepoints:
+    providers.append(TracepointProvider())
+if options.debugfs:
+    providers.append(DebugfsProvider())
+
+if len(providers) == 0:
+    try:
+        providers = [TracepointProvider()]
+    except:
+        providers = [DebugfsProvider()]
 
-stats = Stats(provider, fields = options.fields)
+stats = Stats(providers, fields = options.fields)
 
 if options.log:
     log(stats)
-- 
1.8.3.1

  parent reply	other threads:[~2014-06-04 11:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 11:20 [Qemu-devel] [PULL 00/11] KVM changes for 2014-06-04 Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 01/11] kvmclock: Ensure time in migration never goes backward Paolo Bonzini
2014-06-04 11:20 ` Paolo Bonzini [this message]
2014-06-04 11:20 ` [Qemu-devel] [PULL 03/11] target-i386: Fix vm86 mode regression introduced in fd460606fd6f Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 04/11] target-i386: fix segment flags for SMM and VM86 mode Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 05/11] target-i386: rework CPL checks during task switch, preparing for next patch Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 06/11] target-i386: get CPL from SS.DPL Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 07/11] target-i386: set CC_OP to CC_OP_EFLAGS in cpu_load_eflags Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 08/11] kvm: Ensure negative return value on kvm_init() error handling path Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 09/11] kvm: Enable -cpu option to hide KVM Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 10/11] kvmclock: Ensure proper env->tsc value for kvmclock_current_nsec calculation Paolo Bonzini
2014-06-04 11:20 ` [Qemu-devel] [PULL 11/11] kvm: Fix eax for cpuid leaf 0x40000000 Paolo Bonzini
2014-06-05 18:42 ` [Qemu-devel] [PULL 00/11] KVM changes for 2014-06-04 Peter Maydell

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=1401880812-818-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.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).