Skip to content

Commit

Permalink
tools/kvm_stat: use a more pythonic way to iterate over dictionaries
Browse files Browse the repository at this point in the history
If it's clear that the values of a dictionary will be used then use
the '.items()' method.

Signed-off-by: Marc Hartmayer <[email protected]>
Tested-by: Stefan Raspl <[email protected]>
[Include fix for logging mode by Stefan Raspl]
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Marc Hartmayer authored and bonzini committed Feb 24, 2018
1 parent 006f154 commit 0eb5780
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tools/kvm/kvm_stat/kvm_stat
Original file line number Diff line number Diff line change
Expand Up @@ -1084,9 +1084,10 @@ class Tui(object):
self.screen.clrtobot()
stats = self.stats.get(self._display_guests)
total = 0.
for key in stats.keys():
for key, values in stats.items():
if key.find('(') is -1:
total += stats[key].value
total += values.value

if self._sorting == SORT_DEFAULT:
def sortkey((_k, v)):
# sort by (delta value, overall value)
Expand Down Expand Up @@ -1376,8 +1377,7 @@ def batch(stats):
s = stats.get()
time.sleep(1)
s = stats.get()
for key in sorted(s.keys()):
values = s[key]
for key, values in sorted(s.items()):
print('%-42s%10d%10d' % (key, values.value, values.delta))
except KeyboardInterrupt:
pass
Expand All @@ -1388,14 +1388,14 @@ def log(stats):
keys = sorted(stats.get().keys())

def banner():
for k in keys:
print(k, end=' ')
for key in keys:
print(key, end=' ')
print()

def statline():
s = stats.get()
for k in keys:
print(' %9d' % s[k].delta, end=' ')
for key in keys:
print(' %9d' % s[key].delta, end=' ')
print()
line = 0
banner_repeat = 20
Expand Down

0 comments on commit 0eb5780

Please sign in to comment.