Commit ab7ef193 authored by Stefan Raspl's avatar Stefan Raspl Committed by Paolo Bonzini
Browse files

tools/kvm_stat: add new command line switch '-i'



It might be handy to display the full history of event stats to compare
the current event distribution against any available historic data.
Since we have that available for debugfs, we offer a respective command
line option to display what's available.

Signed-off-by: default avatarStefan Raspl <raspl@linux.vnet.ibm.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 61f381bb
Loading
Loading
Loading
Loading
+30 −4
Original line number Original line Diff line number Diff line
@@ -681,12 +681,14 @@ class TracepointProvider(Provider):
class DebugfsProvider(Provider):
class DebugfsProvider(Provider):
    """Provides data from the files that KVM creates in the kvm debugfs
    """Provides data from the files that KVM creates in the kvm debugfs
    folder."""
    folder."""
    def __init__(self, pid, fields_filter):
    def __init__(self, pid, fields_filter, include_past):
        self.update_fields(fields_filter)
        self.update_fields(fields_filter)
        self._baseline = {}
        self._baseline = {}
        self.do_read = True
        self.do_read = True
        self.paths = []
        self.paths = []
        self.pid = pid
        self.pid = pid
        if include_past:
            self.restore()


    def get_available_fields(self):
    def get_available_fields(self):
        """"Returns a list of available fields.
        """"Returns a list of available fields.
@@ -730,7 +732,14 @@ class DebugfsProvider(Provider):
        self.reset()
        self.reset()


    def read(self, reset=0):
    def read(self, reset=0):
        """Returns a dict with format:'file name / field -> current value'."""
        """Returns a dict with format:'file name / field -> current value'.

        Parameter 'reset':
          0   plain read
          1   reset field counts to 0
          2   restore the original field counts

        """
        results = {}
        results = {}


        # If no debugfs filtering support is available, then don't read.
        # If no debugfs filtering support is available, then don't read.
@@ -747,8 +756,10 @@ class DebugfsProvider(Provider):
            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:
                if reset == 1:
                    self._baseline[key] = value
                    self._baseline[key] = value
                if reset == 2:
                    self._baseline[key] = 0
                if self._baseline.get(key, -1) == -1:
                if self._baseline.get(key, -1) == -1:
                    self._baseline[key] = value
                    self._baseline[key] = value
                results[field] = (results.get(field, 0) + value -
                results[field] = (results.get(field, 0) + value -
@@ -771,6 +782,11 @@ class DebugfsProvider(Provider):
        self._baseline = {}
        self._baseline = {}
        self.read(1)
        self.read(1)


    def restore(self):
        """Reset field counters"""
        self._baseline = {}
        self.read(2)



class Stats(object):
class Stats(object):
    """Manages the data providers and the data they provide.
    """Manages the data providers and the data they provide.
@@ -791,7 +807,8 @@ class Stats(object):
        providers = []
        providers = []


        if options.debugfs:
        if options.debugfs:
            providers.append(DebugfsProvider(options.pid, options.fields))
            providers.append(DebugfsProvider(options.pid, options.fields,
                                             options.dbgfs_include_past))
        if options.tracepoints or not providers:
        if options.tracepoints or not providers:
            providers.append(TracepointProvider(options.pid, options.fields))
            providers.append(TracepointProvider(options.pid, options.fields))


@@ -1270,6 +1287,8 @@ class Tui(object):
                    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
                    self.stats.get()
            except KeyboardInterrupt:
            except KeyboardInterrupt:
                break
                break
            except curses.error:
            except curses.error:
@@ -1381,6 +1400,13 @@ Press any other key to refresh statistics immediately.
                         dest='once',
                         dest='once',
                         help='run in batch mode for one second',
                         help='run in batch mode for one second',
                         )
                         )
    optparser.add_option('-i', '--debugfs-include-past',
                         action='store_true',
                         default=False,
                         dest='dbgfs_include_past',
                         help='include all available data on past events for '
                              'debugfs',
                         )
    optparser.add_option('-l', '--log',
    optparser.add_option('-l', '--log',
                         action='store_true',
                         action='store_true',
                         default=False,
                         default=False,
+4 −0
Original line number Original line Diff line number Diff line
@@ -70,6 +70,10 @@ OPTIONS
--debugfs::
--debugfs::
	retrieve statistics from debugfs
	retrieve statistics from debugfs


-i::
--debugfs-include-past::
	include all available data on past events for debugfs

-p<pid>::
-p<pid>::
--pid=<pid>::
--pid=<pid>::
	limit statistics to one virtual machine (pid)
	limit statistics to one virtual machine (pid)