Skip to content

Commit 6667ae8

Browse files
Stefan Rasplbonzini
authored andcommitted
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 <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 64eefad commit 6667ae8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tools/kvm/kvm_stat/kvm_stat

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ DELAY_DEFAULT = 3.0
848848
MAX_GUEST_NAME_LEN = 48
849849
MAX_REGEX_LEN = 44
850850
DEFAULT_REGEX = r'^[^\(]*$'
851+
SORT_DEFAULT = 0
851852

852853

853854
class Tui(object):
@@ -857,6 +858,7 @@ class Tui(object):
857858
self.screen = None
858859
self._delay_initial = 0.25
859860
self._delay_regular = DELAY_DEFAULT
861+
self._sorting = SORT_DEFAULT
860862

861863
def __enter__(self):
862864
"""Initialises curses for later use. Based on curses.wrapper
@@ -994,14 +996,23 @@ class Tui(object):
994996
self.screen.clrtobot()
995997
stats = self.stats.get()
996998

997-
def sortkey(x):
999+
def sortCurAvg(x):
1000+
# sort by current events if available
9981001
if stats[x][1]:
9991002
return (-stats[x][1], -stats[x][0])
10001003
else:
10011004
return (0, -stats[x][0])
1005+
1006+
def sortTotal(x):
1007+
# sort by totals
1008+
return (0, -stats[x][0])
10021009
total = 0.
10031010
for val in stats.values():
10041011
total += val[0]
1012+
if self._sorting == SORT_DEFAULT:
1013+
sortkey = sortCurAvg
1014+
else:
1015+
sortkey = sortTotal
10051016
for key in sorted(stats.keys(), key=sortkey):
10061017

10071018
if row >= self.screen.getmaxyx()[0]:
@@ -1025,6 +1036,7 @@ class Tui(object):
10251036
' f filter by regular expression',
10261037
' g filter by guest name',
10271038
' h display interactive commands reference',
1039+
' o toggle sorting order (Total vs CurAvg/s)',
10281040
' p filter by PID',
10291041
' q quit',
10301042
' r reset stats',
@@ -1215,6 +1227,8 @@ class Tui(object):
12151227
sleeptime = self._delay_initial
12161228
if char == 'h':
12171229
self.show_help_interactive()
1230+
if char == 'o':
1231+
self._sorting = not self._sorting
12181232
if char == 'p':
12191233
curses.curs_set(1)
12201234
self.show_vm_selection_by_pid()
@@ -1302,6 +1316,7 @@ Interactive Commands:
13021316
f filter by regular expression
13031317
g filter by guest name
13041318
h display interactive commands reference
1319+
o toggle sorting order (Total vs CurAvg/s)
13051320
p filter by PID
13061321
q quit
13071322
r reset stats

tools/kvm/kvm_stat/kvm_stat.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ INTERACTIVE COMMANDS
3737

3838
*h*:: display interactive commands reference
3939

40+
*o*:: toggle sorting order (Total vs CurAvg/s)
41+
4042
*p*:: filter by PID
4143

4244
*q*:: quit

0 commit comments

Comments
 (0)