From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Janosch Frank <frankja@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL 24/49] scripts/kvm/kvm_stat: Introduce properties for providers
Date: Tue, 26 Jan 2016 14:46:56 +0100 [thread overview]
Message-ID: <1453816041-36362-25-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>
As previous commit authors used a mixture of setters/getters and
direct access to class variables consolidating them the python way
improved readability.
Properties allow us to assign a value to a class variable through a
setter without the need to call the setter ourselves.
Reviewed-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com>
Message-Id: <1452525484-32309-19-git-send-email-frankja@linux.vnet.ibm.com>
[prop.setter is new in Python 2.6, which is the earliest supported
version. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scripts/kvm/kvm_stat | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 66dfed6..c4e22d0 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -385,9 +385,7 @@ class TracepointProvider(object):
extra.append(f + '(' + name + ')')
fields += extra
self._setup(fields)
- self.select(fields)
- def fields(self):
- return self._fields
+ self.fields = fields
def _setup(self, _fields):
self._fields = _fields
@@ -417,7 +415,14 @@ class TracepointProvider(object):
tracepoint=tracepoint,
tracefilter=tracefilter)
self.group_leaders.append(group)
- def select(self, fields):
+
+ @property
+ def fields(self):
+ return self._fields
+
+ @fields.setter
+ def fields(self, fields):
+ self._fields = fields
for group in self.group_leaders:
for event in group.events:
if event.name in fields:
@@ -425,6 +430,7 @@ class TracepointProvider(object):
event.enable()
else:
event.disable()
+
def read(self):
ret = defaultdict(int)
for group in self.group_leaders:
@@ -435,10 +441,15 @@ class TracepointProvider(object):
class DebugfsProvider(object):
def __init__(self):
self._fields = walkdir(PATH_DEBUGFS_KVM)[2]
+
+ @property
def fields(self):
return self._fields
- def select(self, fields):
+
+ @fields.setter
+ def fields(self, fields):
self._fields = fields
+
def read(self):
def val(key):
return int(file(PATH_DEBUGFS_KVM + '/' + key).read())
@@ -456,17 +467,17 @@ class Stats:
return re.match(self.fields_filter, key) is not None
self.values = dict()
for d in self.providers:
- provider_fields = [key for key in d.fields() if wanted(key)]
+ provider_fields = [key for key in d.fields if wanted(key)]
for key in provider_fields:
self.values[key] = None
- d.select(provider_fields)
+ d.fields = provider_fields
def set_fields_filter(self, fields_filter):
self.fields_filter = fields_filter
self._update()
def get(self):
for d in self.providers:
new = d.read()
- for key in d.fields():
+ for key in d.fields:
oldval = self.values.get(key, (0, 0))
newval = new[key]
newdelta = None
--
1.8.3.1
next prev 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 ` Paolo Bonzini [this message]
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 ` [Qemu-devel] [PULL 27/49] scripts/kvm/kvm_stat: Encapsulate filters variable Paolo Bonzini
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-25-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).