Commit 5a7d11f8 authored by Stefan Raspl's avatar Stefan Raspl Committed by Paolo Bonzini

tools/kvm_stat: simplify line print logic

Simplify line print logic for header and data lines in interactive mode
as previously suggested by Radim.
While at it, add a space between the first two columns to avoid the
total bleeding into the event name.
Furthermore, for column 'Current', differentiate between no events being
reported (empty 'Current' column) vs the case where events were reported
but the average was rounded down to zero ('0' in 'Current column), for
the folks who appreciate the difference.
Finally: Only skip events which were not reported at all yet, instead of
events that don't have a value in the current interval.
Considered using constants for the field widths in the format strings.
However, that would make things a bit more complicated, and considering
that there are only two places where output happens, I figured it isn't
worth the trouble.
Signed-off-by: default avatarStefan Raspl <raspl@linux.vnet.ibm.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2da9d4aa
...@@ -887,8 +887,6 @@ class Stats(object): ...@@ -887,8 +887,6 @@ class Stats(object):
self.values[key] = (newval, newdelta) self.values[key] = (newval, newdelta)
return self.values return self.values
LABEL_WIDTH = 40
NUMBER_WIDTH = 10
DELAY_INITIAL = 0.25 DELAY_INITIAL = 0.25
DELAY_REGULAR = 3.0 DELAY_REGULAR = 3.0
MAX_GUEST_NAME_LEN = 48 MAX_GUEST_NAME_LEN = 48
...@@ -970,13 +968,8 @@ class Tui(object): ...@@ -970,13 +968,8 @@ class Tui(object):
if len(regex) > MAX_REGEX_LEN: if len(regex) > MAX_REGEX_LEN:
regex = regex[:MAX_REGEX_LEN] + '...' regex = regex[:MAX_REGEX_LEN] + '...'
self.screen.addstr(1, 17, 'regex filter: {0}'.format(regex)) self.screen.addstr(1, 17, 'regex filter: {0}'.format(regex))
self.screen.addstr(2, 1, 'Event') self.screen.addstr(2, 1, '%-40s %10s%7s %7s' %
self.screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH - ('Event', 'Total', '%Total', 'Current'))
len('Total'), 'Total')
self.screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH + 7 -
len('%Total'), '%Total')
self.screen.addstr(2, 1 + LABEL_WIDTH + NUMBER_WIDTH + 7 + 8 -
len('Current'), 'Current')
self.screen.addstr(4, 1, 'Collecting data...') self.screen.addstr(4, 1, 'Collecting data...')
self.screen.refresh() self.screen.refresh()
...@@ -1001,16 +994,11 @@ class Tui(object): ...@@ -1001,16 +994,11 @@ class Tui(object):
values = stats[key] values = stats[key]
if not values[0] and not values[1]: if not values[0] and not values[1]:
break break
col = 1 if values[0] is not None:
self.screen.addstr(row, col, key) cur = int(round(values[1] / sleeptime)) if values[1] else ''
col += LABEL_WIDTH self.screen.addstr(row, 1, '%-40s %10d%7.1f %7s' %
self.screen.addstr(row, col, '%10d' % (values[0],)) (key, values[0], values[0] * 100 / total,
col += NUMBER_WIDTH cur))
self.screen.addstr(row, col, '%7.1f' % (values[0] * 100 / total,))
col += 7
if values[1] is not None:
self.screen.addstr(row, col, '%8d' %
round(values[1] / sleeptime))
row += 1 row += 1
self.screen.refresh() self.screen.refresh()
......
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