summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanosch Frank2016-01-11 16:17:48 +0100
committerPaolo Bonzini2016-01-26 15:58:12 +0100
commita90b87bf25d4d96a8c31a78eefe4633a0e9da3ad (patch)
tree0395323b9ee4e70bcc3f83e05e0c96f50a4ace84
parentscripts/kvm/kvm_stat: Rename _perf_event_open (diff)
downloadqemu-a90b87bf25d4d96a8c31a78eefe4633a0e9da3ad.tar.gz
qemu-a90b87bf25d4d96a8c31a78eefe4633a0e9da3ad.tar.xz
qemu-a90b87bf25d4d96a8c31a78eefe4633a0e9da3ad.zip
scripts/kvm/kvm_stat: Introduce properties for providers
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>
-rwxr-xr-xscripts/kvm/kvm_stat27
1 files changed, 19 insertions, 8 deletions
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 66dfed6ec3..c4e22d0536 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