public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: [PATCH 1/6] kvm_stat: refactor to separate stats provider from difference engine
Date: Tue, 31 Aug 2010 16:25:27 +0300	[thread overview]
Message-ID: <1283261132-5904-3-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1283261132-5904-1-git-send-email-avi@redhat.com>

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 kvm/kvm_stat |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/kvm/kvm_stat b/kvm/kvm_stat
index 21aff5b..75424fc 100755
--- a/kvm/kvm_stat
+++ b/kvm/kvm_stat
@@ -3,21 +3,36 @@
 import curses
 import sys, os, time, optparse
 
+class DebugfsProvider(object):
+    def __init__(self):
+        self.base = '/sys/kernel/debug/kvm'
+        self._fields = os.listdir(self.base)
+    def fields(self):
+        return self._fields
+    def select(self, fields):
+        self._fields = fields
+    def read(self):
+        def val(key):
+            return int(file(self.base + '/' + key).read())
+        return dict([(key, val(key)) for key in self._fields])
+
 class Stats:
-    def __init__(self, fields = None):
+    def __init__(self, provider, fields = None):
         def wanted(key):
             import re
             if not fields:
                 return True
             return re.match(fields, key) != None
-        self.base = '/sys/kernel/debug/kvm'
-        self.values = {}
-        for key in os.listdir(self.base):
-            if wanted(key):
-                self.values[key] = None
+        self.provider = provider
+        self.values = dict([(key, None)
+                            for key in provider.fields()
+                            if wanted(key)])
+        self.provider.select(self.values.keys())
     def get(self):
-        for key, oldval in self.values.iteritems():
-            newval = int(file(self.base + '/' + key).read())
+        new = self.provider.read()
+        for key in self.provider.fields():
+            oldval = self.values[key]
+            newval = new[key]
             newdelta = None
             if oldval is not None:
                 newdelta = newval - oldval[0]
@@ -118,7 +133,7 @@ options.add_option('-f', '--fields',
                    )
 (options, args) = options.parse_args(sys.argv)
 
-stats = Stats(fields = options.fields)
+stats = Stats(provider = DebugfsProvider(), fields = options.fields)
 
 if options.log:
     log(stats)
-- 
1.7.1


  parent reply	other threads:[~2010-08-31 13:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-31 13:25 [PATCH 0/6] kvm_stat tracepoint support Avi Kivity
2010-08-31 13:25 ` [PATCH 0/6] *** SUBJECT HERE *** Avi Kivity
2010-08-31 13:30   ` Avi Kivity
2010-08-31 14:43     ` Gerd Hoffmann
2010-08-31 16:10       ` Avi Kivity
2010-08-31 16:13         ` Anthony Liguori
2010-08-31 16:24           ` Avi Kivity
2010-09-01  7:32           ` Gerd Hoffmann
2010-08-31 13:25 ` Avi Kivity [this message]
2010-08-31 13:25 ` [PATCH 2/6] kvm_stat: implement tracepoint stats provider Avi Kivity
2010-08-31 13:25 ` [PATCH 3/6] kvm_stat: provide detailed kvm_exit:exit_reason display Avi Kivity
2010-08-31 13:25 ` [PATCH 4/6] kvm_stat: sort tui output according to highest occurence Avi Kivity
2010-08-31 13:25 ` [PATCH 5/6] kvm_stat: increase label width Avi Kivity
2010-08-31 13:25 ` [PATCH 6/6] kvm_stat: be slower Avi Kivity

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=1283261132-5904-3-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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