Commit c0e8c21e authored by Stefan Raspl's avatar Stefan Raspl Committed by Paolo Bonzini

tools/kvm_stat: mark private methods as such

Helps quite a bit reading the code when it's obvious when a method is
intended for internal use only.
Signed-off-by: default avatarStefan Raspl <raspl@linux.vnet.ibm.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 1fd6a708
...@@ -373,7 +373,7 @@ class Event(object): ...@@ -373,7 +373,7 @@ class Event(object):
self.syscall = self.libc.syscall self.syscall = self.libc.syscall
self.name = name self.name = name
self.fd = None self.fd = None
self.setup_event(group, trace_cpu, trace_pid, trace_point, self._setup_event(group, trace_cpu, trace_pid, trace_point,
trace_filter, trace_set) trace_filter, trace_set)
def __del__(self): def __del__(self):
...@@ -387,7 +387,7 @@ class Event(object): ...@@ -387,7 +387,7 @@ class Event(object):
if self.fd: if self.fd:
os.close(self.fd) os.close(self.fd)
def perf_event_open(self, attr, pid, cpu, group_fd, flags): def _perf_event_open(self, attr, pid, cpu, group_fd, flags):
"""Wrapper for the sys_perf_evt_open() syscall. """Wrapper for the sys_perf_evt_open() syscall.
Used to set up performance events, returns a file descriptor or -1 Used to set up performance events, returns a file descriptor or -1
...@@ -406,7 +406,7 @@ class Event(object): ...@@ -406,7 +406,7 @@ class Event(object):
ctypes.c_int(pid), ctypes.c_int(cpu), ctypes.c_int(pid), ctypes.c_int(cpu),
ctypes.c_int(group_fd), ctypes.c_long(flags)) ctypes.c_int(group_fd), ctypes.c_long(flags))
def setup_event_attribute(self, trace_set, trace_point): def _setup_event_attribute(self, trace_set, trace_point):
"""Returns an initialized ctype perf_event_attr struct.""" """Returns an initialized ctype perf_event_attr struct."""
id_path = os.path.join(PATH_DEBUGFS_TRACING, 'events', trace_set, id_path = os.path.join(PATH_DEBUGFS_TRACING, 'events', trace_set,
...@@ -416,7 +416,7 @@ class Event(object): ...@@ -416,7 +416,7 @@ class Event(object):
event_attr.config = int(open(id_path).read()) event_attr.config = int(open(id_path).read())
return event_attr return event_attr
def setup_event(self, group, trace_cpu, trace_pid, trace_point, def _setup_event(self, group, trace_cpu, trace_pid, trace_point,
trace_filter, trace_set): trace_filter, trace_set):
"""Sets up the perf event in Linux. """Sets up the perf event in Linux.
...@@ -425,7 +425,7 @@ class Event(object): ...@@ -425,7 +425,7 @@ class Event(object):
""" """
event_attr = self.setup_event_attribute(trace_set, trace_point) event_attr = self._setup_event_attribute(trace_set, trace_point)
# First event will be group leader. # First event will be group leader.
group_leader = -1 group_leader = -1
...@@ -434,7 +434,7 @@ class Event(object): ...@@ -434,7 +434,7 @@ class Event(object):
if group.events: if group.events:
group_leader = group.events[0].fd group_leader = group.events[0].fd
fd = self.perf_event_open(event_attr, trace_pid, fd = self._perf_event_open(event_attr, trace_pid,
trace_cpu, group_leader, 0) trace_cpu, group_leader, 0)
if fd == -1: if fd == -1:
err = ctypes.get_errno() err = ctypes.get_errno()
...@@ -497,12 +497,12 @@ class TracepointProvider(Provider): ...@@ -497,12 +497,12 @@ class TracepointProvider(Provider):
""" """
def __init__(self, pid, fields_filter): def __init__(self, pid, fields_filter):
self.group_leaders = [] self.group_leaders = []
self.filters = self.get_filters() self.filters = self._get_filters()
self.update_fields(fields_filter) self.update_fields(fields_filter)
self.pid = pid self.pid = pid
@staticmethod @staticmethod
def get_filters(): def _get_filters():
"""Returns a dict of trace events, their filter ids and """Returns a dict of trace events, their filter ids and
the values that can be filtered. the values that can be filtered.
...@@ -518,7 +518,7 @@ class TracepointProvider(Provider): ...@@ -518,7 +518,7 @@ class TracepointProvider(Provider):
filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons) filters['kvm_exit'] = ('exit_reason', ARCH.exit_reasons)
return filters return filters
def get_available_fields(self): def _get_available_fields(self):
"""Returns a list of available event's of format 'event name(filter """Returns a list of available event's of format 'event name(filter
name)'. name)'.
...@@ -546,11 +546,11 @@ class TracepointProvider(Provider): ...@@ -546,11 +546,11 @@ class TracepointProvider(Provider):
def update_fields(self, fields_filter): def update_fields(self, fields_filter):
"""Refresh fields, applying fields_filter""" """Refresh fields, applying fields_filter"""
self.fields = [field for field in self.get_available_fields() self.fields = [field for field in self._get_available_fields()
if self.is_field_wanted(fields_filter, field)] if self.is_field_wanted(fields_filter, field)]
@staticmethod @staticmethod
def get_online_cpus(): def _get_online_cpus():
"""Returns a list of cpu id integers.""" """Returns a list of cpu id integers."""
def parse_int_list(list_string): def parse_int_list(list_string):
"""Returns an int list from a string of comma separated integers and """Returns an int list from a string of comma separated integers and
...@@ -572,17 +572,17 @@ class TracepointProvider(Provider): ...@@ -572,17 +572,17 @@ class TracepointProvider(Provider):
cpu_string = cpu_list.readline() cpu_string = cpu_list.readline()
return parse_int_list(cpu_string) return parse_int_list(cpu_string)
def setup_traces(self): def _setup_traces(self):
"""Creates all event and group objects needed to be able to retrieve """Creates all event and group objects needed to be able to retrieve
data.""" data."""
fields = self.get_available_fields() fields = self._get_available_fields()
if self._pid > 0: if self._pid > 0:
# Fetch list of all threads of the monitored pid, as qemu # Fetch list of all threads of the monitored pid, as qemu
# starts a thread for each vcpu. # starts a thread for each vcpu.
path = os.path.join('/proc', str(self._pid), 'task') path = os.path.join('/proc', str(self._pid), 'task')
groupids = self.walkdir(path)[1] groupids = self.walkdir(path)[1]
else: else:
groupids = self.get_online_cpus() groupids = self._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.
...@@ -660,7 +660,7 @@ class TracepointProvider(Provider): ...@@ -660,7 +660,7 @@ class TracepointProvider(Provider):
# The garbage collector will get rid of all Event/Group # The garbage collector will get rid of all Event/Group
# objects and open files after removing the references. # objects and open files after removing the references.
self.group_leaders = [] self.group_leaders = []
self.setup_traces() self._setup_traces()
self.fields = self._fields self.fields = self._fields
def read(self, by_guest=0): def read(self, by_guest=0):
...@@ -689,9 +689,9 @@ class DebugfsProvider(Provider): ...@@ -689,9 +689,9 @@ class DebugfsProvider(Provider):
self.paths = [] self.paths = []
self.pid = pid self.pid = pid
if include_past: if include_past:
self.restore() self._restore()
def get_available_fields(self): def _get_available_fields(self):
""""Returns a list of available fields. """"Returns a list of available fields.
The fields are all available KVM debugfs files The fields are all available KVM debugfs files
...@@ -701,7 +701,7 @@ class DebugfsProvider(Provider): ...@@ -701,7 +701,7 @@ class DebugfsProvider(Provider):
def update_fields(self, fields_filter): def update_fields(self, fields_filter):
"""Refresh fields, applying fields_filter""" """Refresh fields, applying fields_filter"""
self._fields = [field for field in self.get_available_fields() self._fields = [field for field in self._get_available_fields()
if self.is_field_wanted(fields_filter, field)] if self.is_field_wanted(fields_filter, field)]
@property @property
...@@ -755,7 +755,7 @@ class DebugfsProvider(Provider): ...@@ -755,7 +755,7 @@ class DebugfsProvider(Provider):
paths.append(dir) paths.append(dir)
for path in paths: for path in paths:
for field in self._fields: for field in self._fields:
value = self.read_field(field, path) value = self._read_field(field, path)
key = path + field key = path + field
if reset == 1: if reset == 1:
self._baseline[key] = value self._baseline[key] = value
...@@ -776,7 +776,7 @@ class DebugfsProvider(Provider): ...@@ -776,7 +776,7 @@ class DebugfsProvider(Provider):
return results return results
def read_field(self, field, path): def _read_field(self, field, path):
"""Returns the value of a single field from a specific VM.""" """Returns the value of a single field from a specific VM."""
try: try:
return int(open(os.path.join(PATH_DEBUGFS_KVM, return int(open(os.path.join(PATH_DEBUGFS_KVM,
...@@ -791,7 +791,7 @@ class DebugfsProvider(Provider): ...@@ -791,7 +791,7 @@ class DebugfsProvider(Provider):
self._baseline = {} self._baseline = {}
self.read(1) self.read(1)
def restore(self): def _restore(self):
"""Reset field counters""" """Reset field counters"""
self._baseline = {} self._baseline = {}
self.read(2) self.read(2)
...@@ -808,13 +808,12 @@ class Stats(object): ...@@ -808,13 +808,12 @@ class Stats(object):
""" """
def __init__(self, options): def __init__(self, options):
self.providers = self.get_providers(options) self.providers = self._get_providers(options)
self._pid_filter = options.pid self._pid_filter = options.pid
self._fields_filter = options.fields self._fields_filter = options.fields
self.values = {} self.values = {}
@staticmethod def _get_providers(self, options):
def get_providers(options):
"""Returns a list of data providers depending on the passed options.""" """Returns a list of data providers depending on the passed options."""
providers = [] providers = []
...@@ -826,7 +825,7 @@ class Stats(object): ...@@ -826,7 +825,7 @@ class Stats(object):
return providers return providers
def update_provider_filters(self): def _update_provider_filters(self):
"""Propagates fields filters to providers.""" """Propagates fields filters to providers."""
# As we reset the counters when updating the fields we can # As we reset the counters when updating the fields we can
# also clear the cache of old values. # also clear the cache of old values.
...@@ -847,7 +846,7 @@ class Stats(object): ...@@ -847,7 +846,7 @@ class Stats(object):
def fields_filter(self, fields_filter): def fields_filter(self, fields_filter):
if fields_filter != self._fields_filter: if fields_filter != self._fields_filter:
self._fields_filter = fields_filter self._fields_filter = fields_filter
self.update_provider_filters() self._update_provider_filters()
@property @property
def pid_filter(self): def pid_filter(self):
...@@ -969,7 +968,7 @@ class Tui(object): ...@@ -969,7 +968,7 @@ class Tui(object):
return res return res
def print_all_gnames(self, row): def _print_all_gnames(self, row):
"""Print a list of all running guests along with their pids.""" """Print a list of all running guests along with their pids."""
self.screen.addstr(row, 2, '%8s %-60s' % self.screen.addstr(row, 2, '%8s %-60s' %
('Pid', 'Guest Name (fuzzy list, might be ' ('Pid', 'Guest Name (fuzzy list, might be '
...@@ -1032,7 +1031,7 @@ class Tui(object): ...@@ -1032,7 +1031,7 @@ class Tui(object):
return name return name
def update_drilldown(self): def _update_drilldown(self):
"""Sets or removes a filter that only allows fields without braces.""" """Sets or removes a filter that only allows fields without braces."""
if not self.stats.fields_filter: if not self.stats.fields_filter:
self.stats.fields_filter = DEFAULT_REGEX self.stats.fields_filter = DEFAULT_REGEX
...@@ -1040,11 +1039,11 @@ class Tui(object): ...@@ -1040,11 +1039,11 @@ class Tui(object):
elif self.stats.fields_filter == DEFAULT_REGEX: elif self.stats.fields_filter == DEFAULT_REGEX:
self.stats.fields_filter = None self.stats.fields_filter = None
def update_pid(self, pid): def _update_pid(self, pid):
"""Propagates pid selection to stats object.""" """Propagates pid selection to stats object."""
self.stats.pid_filter = pid self.stats.pid_filter = pid
def refresh_header(self, pid=None): def _refresh_header(self, pid=None):
"""Refreshes the header.""" """Refreshes the header."""
if pid is None: if pid is None:
pid = self.stats.pid_filter pid = self.stats.pid_filter
...@@ -1075,7 +1074,7 @@ class Tui(object): ...@@ -1075,7 +1074,7 @@ class Tui(object):
self.screen.addstr(4, 1, 'Collecting data...') self.screen.addstr(4, 1, 'Collecting data...')
self.screen.refresh() self.screen.refresh()
def refresh_body(self, sleeptime): def _refresh_body(self, sleeptime):
row = 3 row = 3
self.screen.move(row, 0) self.screen.move(row, 0)
self.screen.clrtobot() self.screen.clrtobot()
...@@ -1124,7 +1123,7 @@ class Tui(object): ...@@ -1124,7 +1123,7 @@ class Tui(object):
curses.A_BOLD) curses.A_BOLD)
self.screen.refresh() self.screen.refresh()
def show_msg(self, text): def _show_msg(self, text):
"""Display message centered text and exit on key press""" """Display message centered text and exit on key press"""
hint = 'Press any key to continue' hint = 'Press any key to continue'
curses.cbreak() curses.cbreak()
...@@ -1139,7 +1138,7 @@ class Tui(object): ...@@ -1139,7 +1138,7 @@ class Tui(object):
curses.A_STANDOUT) curses.A_STANDOUT)
self.screen.getkey() self.screen.getkey()
def show_help_interactive(self): def _show_help_interactive(self):
"""Display help with list of interactive commands""" """Display help with list of interactive commands"""
msg = (' b toggle events by guests (debugfs only, honors' msg = (' b toggle events by guests (debugfs only, honors'
' filters)', ' filters)',
...@@ -1165,9 +1164,9 @@ class Tui(object): ...@@ -1165,9 +1164,9 @@ class Tui(object):
self.screen.addstr(row, 0, line) self.screen.addstr(row, 0, line)
row += 1 row += 1
self.screen.getkey() self.screen.getkey()
self.refresh_header() self._refresh_header()
def show_filter_selection(self): def _show_filter_selection(self):
"""Draws filter selection mask. """Draws filter selection mask.
Asks for a valid regex and sets the fields filter accordingly. Asks for a valid regex and sets the fields filter accordingly.
...@@ -1189,18 +1188,18 @@ class Tui(object): ...@@ -1189,18 +1188,18 @@ class Tui(object):
curses.noecho() curses.noecho()
if len(regex) == 0: if len(regex) == 0:
self.stats.fields_filter = DEFAULT_REGEX self.stats.fields_filter = DEFAULT_REGEX
self.refresh_header() self._refresh_header()
return return
try: try:
re.compile(regex) re.compile(regex)
self.stats.fields_filter = regex self.stats.fields_filter = regex
self.refresh_header() self._refresh_header()
return return
except re.error: except re.error:
msg = '"' + regex + '": Not a valid regular expression' msg = '"' + regex + '": Not a valid regular expression'
continue continue
def show_vm_selection_by_pid(self): def _show_vm_selection_by_pid(self):
"""Draws PID selection mask. """Draws PID selection mask.
Asks for a pid until a valid pid or 0 has been entered. Asks for a pid until a valid pid or 0 has been entered.
...@@ -1216,7 +1215,7 @@ class Tui(object): ...@@ -1216,7 +1215,7 @@ class Tui(object):
'This might limit the shown data to the trace ' 'This might limit the shown data to the trace '
'statistics.') 'statistics.')
self.screen.addstr(5, 0, msg) self.screen.addstr(5, 0, msg)
self.print_all_gnames(7) self._print_all_gnames(7)
curses.echo() curses.echo()
self.screen.addstr(3, 0, "Pid [0 or pid]: ") self.screen.addstr(3, 0, "Pid [0 or pid]: ")
...@@ -1232,13 +1231,13 @@ class Tui(object): ...@@ -1232,13 +1231,13 @@ class Tui(object):
continue continue
else: else:
pid = 0 pid = 0
self.refresh_header(pid) self._refresh_header(pid)
self.update_pid(pid) self._update_pid(pid)
break break
except ValueError: except ValueError:
msg = '"' + str(pid) + '": Not a valid pid' msg = '"' + str(pid) + '": Not a valid pid'
def show_set_update_interval(self): def _show_set_update_interval(self):
"""Draws update interval selection mask.""" """Draws update interval selection mask."""
msg = '' msg = ''
while True: while True:
...@@ -1268,9 +1267,9 @@ class Tui(object): ...@@ -1268,9 +1267,9 @@ class Tui(object):
except ValueError: except ValueError:
msg = '"' + str(val) + '": Invalid value' msg = '"' + str(val) + '": Invalid value'
self.refresh_header() self._refresh_header()
def show_vm_selection_by_guest_name(self): def _show_vm_selection_by_guest_name(self):
"""Draws guest selection mask. """Draws guest selection mask.
Asks for a guest name until a valid guest name or '' is entered. Asks for a guest name until a valid guest name or '' is entered.
...@@ -1286,15 +1285,15 @@ class Tui(object): ...@@ -1286,15 +1285,15 @@ class Tui(object):
'This might limit the shown data to the trace ' 'This might limit the shown data to the trace '
'statistics.') 'statistics.')
self.screen.addstr(5, 0, msg) self.screen.addstr(5, 0, msg)
self.print_all_gnames(7) self._print_all_gnames(7)
curses.echo() curses.echo()
self.screen.addstr(3, 0, "Guest [ENTER or guest]: ") self.screen.addstr(3, 0, "Guest [ENTER or guest]: ")
gname = self.screen.getstr().decode(ENCODING) gname = self.screen.getstr().decode(ENCODING)
curses.noecho() curses.noecho()
if not gname: if not gname:
self.refresh_header(0) self._refresh_header(0)
self.update_pid(0) self._update_pid(0)
break break
else: else:
pids = [] pids = []
...@@ -1311,17 +1310,17 @@ class Tui(object): ...@@ -1311,17 +1310,17 @@ class Tui(object):
msg = '"' + gname + '": Multiple matches found, use pid ' \ msg = '"' + gname + '": Multiple matches found, use pid ' \
'filter instead' 'filter instead'
continue continue
self.refresh_header(pids[0]) self._refresh_header(pids[0])
self.update_pid(pids[0]) self._update_pid(pids[0])
break break
def show_stats(self): def show_stats(self):
"""Refreshes the screen and processes user input.""" """Refreshes the screen and processes user input."""
sleeptime = self._delay_initial sleeptime = self._delay_initial
self.refresh_header() self._refresh_header()
start = 0.0 # result based on init value never appears on screen start = 0.0 # result based on init value never appears on screen
while True: while True:
self.refresh_body(time.time() - start) self._refresh_body(time.time() - start)
curses.halfdelay(int(sleeptime * 10)) curses.halfdelay(int(sleeptime * 10))
start = time.time() start = time.time()
sleeptime = self._delay_regular sleeptime = self._delay_regular
...@@ -1330,32 +1329,33 @@ class Tui(object): ...@@ -1330,32 +1329,33 @@ class Tui(object):
if char == 'b': if char == 'b':
self._display_guests = not self._display_guests self._display_guests = not self._display_guests
if self.stats.toggle_display_guests(self._display_guests): if self.stats.toggle_display_guests(self._display_guests):
self.show_msg(['Command not available with tracepoints' self._show_msg(['Command not available with '
' enabled', 'Restart with debugfs only ' 'tracepoints enabled', 'Restart with '
'(see option \'-d\') and try again!']) 'debugfs only (see option \'-d\') and '
'try again!'])
self._display_guests = not self._display_guests self._display_guests = not self._display_guests
self.refresh_header() self._refresh_header()
if char == 'c': if char == 'c':
self.stats.fields_filter = DEFAULT_REGEX self.stats.fields_filter = DEFAULT_REGEX
self.refresh_header(0) self._refresh_header(0)
self.update_pid(0) self._update_pid(0)
if char == 'f': if char == 'f':
curses.curs_set(1) curses.curs_set(1)
self.show_filter_selection() self._show_filter_selection()
curses.curs_set(0) curses.curs_set(0)
sleeptime = self._delay_initial sleeptime = self._delay_initial
if char == 'g': if char == 'g':
curses.curs_set(1) curses.curs_set(1)
self.show_vm_selection_by_guest_name() self._show_vm_selection_by_guest_name()
curses.curs_set(0) curses.curs_set(0)
sleeptime = self._delay_initial sleeptime = self._delay_initial
if char == 'h': if char == 'h':
self.show_help_interactive() self._show_help_interactive()
if char == 'o': if char == 'o':
self._sorting = not self._sorting self._sorting = not self._sorting
if char == 'p': if char == 'p':
curses.curs_set(1) curses.curs_set(1)
self.show_vm_selection_by_pid() self._show_vm_selection_by_pid()
curses.curs_set(0) curses.curs_set(0)
sleeptime = self._delay_initial sleeptime = self._delay_initial
if char == 'q': if char == 'q':
...@@ -1364,11 +1364,11 @@ class Tui(object): ...@@ -1364,11 +1364,11 @@ class Tui(object):
self.stats.reset() self.stats.reset()
if char == 's': if char == 's':
curses.curs_set(1) curses.curs_set(1)
self.show_set_update_interval() self._show_set_update_interval()
curses.curs_set(0) curses.curs_set(0)
sleeptime = self._delay_initial sleeptime = self._delay_initial
if char == 'x': if char == 'x':
self.update_drilldown() self._update_drilldown()
# prevents display of current values on next refresh # prevents display of current values on next refresh
self.stats.get(self._display_guests) self.stats.get(self._display_guests)
except KeyboardInterrupt: except KeyboardInterrupt:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment