tools/kvm_stat: add new interactive command 'o'

Add new interactive command 'o' to toggle sorting by 'CurAvg/s' (default)
and 'Total' columns.

Signed-off-by: Stefan Raspl <raspl@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Stefan Raspl 2017-06-07 21:08:41 +02:00 committed by Paolo Bonzini
parent 64eefad2cd
commit 6667ae8f39
2 changed files with 18 additions and 1 deletions

View File

@ -848,6 +848,7 @@ DELAY_DEFAULT = 3.0
MAX_GUEST_NAME_LEN = 48 MAX_GUEST_NAME_LEN = 48
MAX_REGEX_LEN = 44 MAX_REGEX_LEN = 44
DEFAULT_REGEX = r'^[^\(]*$' DEFAULT_REGEX = r'^[^\(]*$'
SORT_DEFAULT = 0
class Tui(object): class Tui(object):
@ -857,6 +858,7 @@ class Tui(object):
self.screen = None self.screen = None
self._delay_initial = 0.25 self._delay_initial = 0.25
self._delay_regular = DELAY_DEFAULT self._delay_regular = DELAY_DEFAULT
self._sorting = SORT_DEFAULT
def __enter__(self): def __enter__(self):
"""Initialises curses for later use. Based on curses.wrapper """Initialises curses for later use. Based on curses.wrapper
@ -994,14 +996,23 @@ class Tui(object):
self.screen.clrtobot() self.screen.clrtobot()
stats = self.stats.get() stats = self.stats.get()
def sortkey(x): def sortCurAvg(x):
# sort by current events if available
if stats[x][1]: if stats[x][1]:
return (-stats[x][1], -stats[x][0]) return (-stats[x][1], -stats[x][0])
else: else:
return (0, -stats[x][0]) return (0, -stats[x][0])
def sortTotal(x):
# sort by totals
return (0, -stats[x][0])
total = 0. total = 0.
for val in stats.values(): for val in stats.values():
total += val[0] total += val[0]
if self._sorting == SORT_DEFAULT:
sortkey = sortCurAvg
else:
sortkey = sortTotal
for key in sorted(stats.keys(), key=sortkey): for key in sorted(stats.keys(), key=sortkey):
if row >= self.screen.getmaxyx()[0]: if row >= self.screen.getmaxyx()[0]:
@ -1025,6 +1036,7 @@ class Tui(object):
' f filter by regular expression', ' f filter by regular expression',
' g filter by guest name', ' g filter by guest name',
' h display interactive commands reference', ' h display interactive commands reference',
' o toggle sorting order (Total vs CurAvg/s)',
' p filter by PID', ' p filter by PID',
' q quit', ' q quit',
' r reset stats', ' r reset stats',
@ -1215,6 +1227,8 @@ class Tui(object):
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':
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()
@ -1302,6 +1316,7 @@ Interactive Commands:
f filter by regular expression f filter by regular expression
g filter by guest name g filter by guest name
h display interactive commands reference h display interactive commands reference
o toggle sorting order (Total vs CurAvg/s)
p filter by PID p filter by PID
q quit q quit
r reset stats r reset stats

View File

@ -37,6 +37,8 @@ INTERACTIVE COMMANDS
*h*:: display interactive commands reference *h*:: display interactive commands reference
*o*:: toggle sorting order (Total vs CurAvg/s)
*p*:: filter by PID *p*:: filter by PID
*q*:: quit *q*:: quit