Skip to content

Commit 3cbb394

Browse files
Stefan Rasplbonzini
authored andcommitted
tools/kvm_stat: add command line switch '-s' to set update interval
This now controls both, the refresh rate of the interactive mode as well as the logging mode. Which, as a consequence, means that the default of logging mode is now 3s, too (use command line switch '-s' to adjust to your liking). Signed-off-by: Stefan Raspl <raspl@linux.ibm.com> Message-Id: <20200306114250.57585-4-raspl@linux.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 0e6618f commit 3cbb394

2 files changed

Lines changed: 38 additions & 12 deletions

File tree

‎tools/kvm/kvm_stat/kvm_stat‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -974,15 +974,17 @@ DELAY_DEFAULT = 3.0
974974
MAX_GUEST_NAME_LEN = 48
975975
MAX_REGEX_LEN = 44
976976
SORT_DEFAULT = 0
977+
MIN_DELAY = 0.1
978+
MAX_DELAY = 25.5
977979

978980

979981
class Tui(object):
980982
"""Instruments curses to draw a nice text ui."""
981-
def __init__(self, stats):
983+
def __init__(self, stats, opts):
982984
self.stats = stats
983985
self.screen = None
984986
self._delay_initial = 0.25
985-
self._delay_regular = DELAY_DEFAULT
987+
self._delay_regular = opts.set_delay
986988
self._sorting = SORT_DEFAULT
987989
self._display_guests = 0
988990

@@ -1282,7 +1284,8 @@ class Tui(object):
12821284
' p filter by guest name/PID',
12831285
' q quit',
12841286
' r reset stats',
1285-
' s set update interval',
1287+
' s set delay between refreshs (value range: '
1288+
'%s-%s secs)' % (MIN_DELAY, MAX_DELAY),
12861289
' x toggle reporting of stats for individual child trace'
12871290
' events',
12881291
'Any other key refreshes statistics immediately')
@@ -1348,11 +1351,9 @@ class Tui(object):
13481351
try:
13491352
if len(val) > 0:
13501353
delay = float(val)
1351-
if delay < 0.1:
1352-
msg = '"' + str(val) + '": Value must be >=0.1'
1353-
continue
1354-
if delay > 25.5:
1355-
msg = '"' + str(val) + '": Value must be <=25.5'
1354+
err = is_delay_valid(delay)
1355+
if err is not None:
1356+
msg = err
13561357
continue
13571358
else:
13581359
delay = DELAY_DEFAULT
@@ -1488,7 +1489,7 @@ def batch(stats):
14881489
pass
14891490

14901491

1491-
def log(stats):
1492+
def log(stats, opts):
14921493
"""Prints statistics as reiterating key block, multiple value blocks."""
14931494
keys = sorted(stats.get().keys())
14941495

@@ -1506,7 +1507,7 @@ def log(stats):
15061507
banner_repeat = 20
15071508
while True:
15081509
try:
1509-
time.sleep(1)
1510+
time.sleep(opts.set_delay)
15101511
if line % banner_repeat == 0:
15111512
banner()
15121513
statline()
@@ -1515,6 +1516,16 @@ def log(stats):
15151516
break
15161517

15171518

1519+
def is_delay_valid(delay):
1520+
"""Verify delay is in valid value range."""
1521+
msg = None
1522+
if delay < MIN_DELAY:
1523+
msg = '"' + str(delay) + '": Delay must be >=%s' % MIN_DELAY
1524+
if delay > MAX_DELAY:
1525+
msg = '"' + str(delay) + '": Delay must be <=%s' % MAX_DELAY
1526+
return msg
1527+
1528+
15181529
def get_options():
15191530
"""Returns processed program arguments."""
15201531
description_text = """
@@ -1604,6 +1615,13 @@ Press any other key to refresh statistics immediately.
16041615
default=0,
16051616
help='restrict statistics to pid',
16061617
)
1618+
argparser.add_argument('-s', '--set-delay',
1619+
type=float,
1620+
default=DELAY_DEFAULT,
1621+
metavar='DELAY',
1622+
help='set delay between refreshs (value range: '
1623+
'%s-%s secs)' % (MIN_DELAY, MAX_DELAY),
1624+
)
16071625
argparser.add_argument('-t', '--tracepoints',
16081626
action='store_true',
16091627
default=False,
@@ -1675,6 +1693,10 @@ def main():
16751693
sys.stderr.write('Did you use a (unsupported) tid instead of a pid?\n')
16761694
sys.exit('Specified pid does not exist.')
16771695

1696+
err = is_delay_valid(options.set_delay)
1697+
if err is not None:
1698+
sys.exit('Error: ' + err)
1699+
16781700
stats = Stats(options)
16791701

16801702
if options.fields == 'help':
@@ -1686,9 +1708,9 @@ def main():
16861708
sys.exit(0)
16871709

16881710
if options.log:
1689-
log(stats)
1711+
log(stats, options)
16901712
elif not options.once:
1691-
with Tui(stats) as tui:
1713+
with Tui(stats, options) as tui:
16921714
tui.show_stats()
16931715
else:
16941716
batch(stats)

‎tools/kvm/kvm_stat/kvm_stat.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ OPTIONS
9292
--pid=<pid>::
9393
limit statistics to one virtual machine (pid)
9494

95+
-s::
96+
--set-delay::
97+
set delay between refreshs (value range: 0.1-25.5 secs)
98+
9599
-t::
96100
--tracepoints::
97101
retrieve statistics from tracepoints

0 commit comments

Comments
 (0)