aboutsummaryrefslogtreecommitdiff
path: root/scripts/kvm
diff options
context:
space:
mode:
authorJanosch Frank <frankja@linux.vnet.ibm.com>2016-01-11 16:17:49 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2016-01-26 15:58:13 +0100
commite06715a3632e0b454dca32ffb9bfefe8fd106a7d (patch)
tree7342ab1645189fc411d5dbf1aa8aea46e0ada034 /scripts/kvm
parenta90b87bf25d4d96a8c31a78eefe4633a0e9da3ad (diff)
scripts/kvm/kvm_stat: Cleanup of TracepointProvider
Variables with bad names like f and m were renamed to their full name, so it is clearer which data they contain. Unneeded variables were removed and the field generating code was moved in an own function. dict.iteritems() was removed as directly iterating over a dictionary also yields the needed keys. Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com> Message-Id: <1452525484-32309-20-git-send-email-frankja@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'scripts/kvm')
-rwxr-xr-xscripts/kvm/kvm_stat40
1 files changed, 21 insertions, 19 deletions
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index c4e22d0536..032e491f6b 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -375,45 +375,47 @@ class Event(object):
class TracepointProvider(object):
def __init__(self):
+ self.group_leaders = []
+ self._fields = self.get_available_fields()
+ self.setup_traces()
+ self.fields = self._fields
+
+ def get_available_fields(self):
path = os.path.join(PATH_DEBUGFS_TRACING, 'events', 'kvm')
fields = walkdir(path)[1]
extra = []
- for f in fields:
- if f in filters:
- subfield, values = filters[f]
- for name, number in values.iteritems():
- extra.append(f + '(' + name + ')')
+ for field in fields:
+ if field in filters:
+ filter_name_, filter_dicts = filters[field]
+ for name in filter_dicts:
+ extra.append(field + '(' + name + ')')
fields += extra
- self._setup(fields)
- self.fields = fields
+ return fields
- def _setup(self, _fields):
- self._fields = _fields
+ def setup_traces(self):
cpus = get_online_cpus()
# The constant is needed as a buffer for python libs, std
# streams and other files that the script opens.
- rlimit = len(cpus) * len(_fields) + 50
+ rlimit = len(cpus) * len(self._fields) + 50
try:
resource.setrlimit(resource.RLIMIT_NOFILE, (rlimit, rlimit))
except ValueError:
sys.exit("NOFILE rlimit could not be raised to {0}".format(rlimit))
- events = []
- self.group_leaders = []
for cpu in cpus:
group = Group(cpu)
- for name in _fields:
+ for name in self._fields:
tracepoint = name
tracefilter = None
- m = re.match(r'(.*)\((.*)\)', name)
- if m:
- tracepoint, sub = m.groups()
+ match = re.match(r'(.*)\((.*)\)', name)
+ if match:
+ tracepoint, sub = match.groups()
tracefilter = '%s==%d\0' % (filters[tracepoint][0],
filters[tracepoint][1][sub])
- event = group.add_event(name, event_set='kvm',
- tracepoint=tracepoint,
- tracefilter=tracefilter)
+ group.add_event(name, event_set='kvm',
+ tracepoint=tracepoint,
+ tracefilter=tracefilter)
self.group_leaders.append(group)
@property