dom0/qvm-ls: improve performance
Do not evaluate each field twice - some of them (eg. disk usage) are expensive.
This commit is contained in:
parent
c7f3b1a685
commit
ac246d3d6a
@ -167,15 +167,27 @@ def main():
|
|||||||
assert len(vms_to_display) == no_vms
|
assert len(vms_to_display) == no_vms
|
||||||
|
|
||||||
# First calculate the maximum width of each field we want to display
|
# First calculate the maximum width of each field we want to display
|
||||||
total_width = 0;
|
# also collect data to display
|
||||||
for f in fields_to_display:
|
for f in fields_to_display:
|
||||||
fields[f]["max_width"] = len(f)
|
fields[f]["max_width"] = len(f)
|
||||||
|
data_to_display = []
|
||||||
for vm in vms_to_display:
|
for vm in vms_to_display:
|
||||||
l = len(str(eval(fields[f]["func"])))
|
data_row = {}
|
||||||
|
for f in fields_to_display:
|
||||||
|
data_row[f] = str(eval(fields[f]["func"]))
|
||||||
|
l = len(data_row[f])
|
||||||
if l > fields[f]["max_width"]:
|
if l > fields[f]["max_width"]:
|
||||||
fields[f]["max_width"] = l
|
fields[f]["max_width"] = l
|
||||||
total_width += fields[f]["max_width"]
|
data_to_display.append(data_row)
|
||||||
|
try:
|
||||||
|
vm.verify_files()
|
||||||
|
except QubesException as err:
|
||||||
|
print >> sys.stderr, "WARNING: VM '{0}' has corrupted files!".format(vm.name)
|
||||||
|
|
||||||
|
# XXX: For what?
|
||||||
|
total_width = 0;
|
||||||
|
for f in fields_to_display:
|
||||||
|
total_width += fields[f]["max_width"]
|
||||||
|
|
||||||
# Display the header
|
# Display the header
|
||||||
s = ""
|
s = ""
|
||||||
@ -195,16 +207,11 @@ def main():
|
|||||||
print s
|
print s
|
||||||
|
|
||||||
# ... and the actual data
|
# ... and the actual data
|
||||||
for vm in vms_to_display:
|
for row in data_to_display:
|
||||||
s = ""
|
s = ""
|
||||||
for f in fields_to_display:
|
for f in fields_to_display:
|
||||||
fmt="{{0:>{0}}} |".format(fields[f]["max_width"] + 1)
|
fmt="{{0:>{0}}} |".format(fields[f]["max_width"] + 1)
|
||||||
s += fmt.format(eval(fields[f]["func"]))
|
s += fmt.format(row[f])
|
||||||
print s
|
print s
|
||||||
|
|
||||||
try:
|
|
||||||
vm.verify_files()
|
|
||||||
except QubesException as err:
|
|
||||||
print >> sys.stderr, "WARNING: VM '{0}' has corrupted files!".format(vm.name)
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user