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>
This commit is contained in:
Janosch Frank 2016-01-11 16:17:49 +01:00 committed by Paolo Bonzini
parent a90b87bf25
commit e06715a363
1 changed files with 21 additions and 19 deletions

View File

@ -375,45 +375,47 @@ class Event(object):
class TracepointProvider(object): class TracepointProvider(object):
def __init__(self): 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') path = os.path.join(PATH_DEBUGFS_TRACING, 'events', 'kvm')
fields = walkdir(path)[1] fields = walkdir(path)[1]
extra = [] extra = []
for f in fields: for field in fields:
if f in filters: if field in filters:
subfield, values = filters[f] filter_name_, filter_dicts = filters[field]
for name, number in values.iteritems(): for name in filter_dicts:
extra.append(f + '(' + name + ')') extra.append(field + '(' + name + ')')
fields += extra fields += extra
self._setup(fields) return fields
self.fields = fields
def _setup(self, _fields): def setup_traces(self):
self._fields = _fields
cpus = get_online_cpus() cpus = get_online_cpus()
# The constant is needed as a buffer for python libs, std # The constant is needed as a buffer for python libs, std
# streams and other files that the script opens. # streams and other files that the script opens.
rlimit = len(cpus) * len(_fields) + 50 rlimit = len(cpus) * len(self._fields) + 50
try: try:
resource.setrlimit(resource.RLIMIT_NOFILE, (rlimit, rlimit)) resource.setrlimit(resource.RLIMIT_NOFILE, (rlimit, rlimit))
except ValueError: except ValueError:
sys.exit("NOFILE rlimit could not be raised to {0}".format(rlimit)) sys.exit("NOFILE rlimit could not be raised to {0}".format(rlimit))
events = []
self.group_leaders = []
for cpu in cpus: for cpu in cpus:
group = Group(cpu) group = Group(cpu)
for name in _fields: for name in self._fields:
tracepoint = name tracepoint = name
tracefilter = None tracefilter = None
m = re.match(r'(.*)\((.*)\)', name) match = re.match(r'(.*)\((.*)\)', name)
if m: if match:
tracepoint, sub = m.groups() tracepoint, sub = match.groups()
tracefilter = '%s==%d\0' % (filters[tracepoint][0], tracefilter = '%s==%d\0' % (filters[tracepoint][0],
filters[tracepoint][1][sub]) filters[tracepoint][1][sub])
event = group.add_event(name, event_set='kvm', group.add_event(name, event_set='kvm',
tracepoint=tracepoint, tracepoint=tracepoint,
tracefilter=tracefilter) tracefilter=tracefilter)
self.group_leaders.append(group) self.group_leaders.append(group)
@property @property