mirror of https://github.com/torvalds/linux.git
tools/kvm_stat: use a more pythonic way to iterate over dictionaries
If it's clear that the values of a dictionary will be used then use the '.items()' method. Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com> Tested-by: Stefan Raspl <raspl@linux.vnet.ibm.com> [Include fix for logging mode by Stefan Raspl] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
006f1548ac
commit
0eb578009a
|
|
@ -1084,9 +1084,10 @@ class Tui(object):
|
||||||
self.screen.clrtobot()
|
self.screen.clrtobot()
|
||||||
stats = self.stats.get(self._display_guests)
|
stats = self.stats.get(self._display_guests)
|
||||||
total = 0.
|
total = 0.
|
||||||
for key in stats.keys():
|
for key, values in stats.items():
|
||||||
if key.find('(') is -1:
|
if key.find('(') is -1:
|
||||||
total += stats[key].value
|
total += values.value
|
||||||
|
|
||||||
if self._sorting == SORT_DEFAULT:
|
if self._sorting == SORT_DEFAULT:
|
||||||
def sortkey((_k, v)):
|
def sortkey((_k, v)):
|
||||||
# sort by (delta value, overall value)
|
# sort by (delta value, overall value)
|
||||||
|
|
@ -1376,8 +1377,7 @@ def batch(stats):
|
||||||
s = stats.get()
|
s = stats.get()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
s = stats.get()
|
s = stats.get()
|
||||||
for key in sorted(s.keys()):
|
for key, values in sorted(s.items()):
|
||||||
values = s[key]
|
|
||||||
print('%-42s%10d%10d' % (key, values.value, values.delta))
|
print('%-42s%10d%10d' % (key, values.value, values.delta))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
@ -1388,14 +1388,14 @@ def log(stats):
|
||||||
keys = sorted(stats.get().keys())
|
keys = sorted(stats.get().keys())
|
||||||
|
|
||||||
def banner():
|
def banner():
|
||||||
for k in keys:
|
for key in keys:
|
||||||
print(k, end=' ')
|
print(key, end=' ')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def statline():
|
def statline():
|
||||||
s = stats.get()
|
s = stats.get()
|
||||||
for k in keys:
|
for key in keys:
|
||||||
print(' %9d' % s[k].delta, end=' ')
|
print(' %9d' % s[key].delta, end=' ')
|
||||||
print()
|
print()
|
||||||
line = 0
|
line = 0
|
||||||
banner_repeat = 20
|
banner_repeat = 20
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue