Skip to content

Commit

Permalink
don't ask for domain state before asking for info
Browse files Browse the repository at this point in the history
info already contains domain state, so just use it, making a single
libvirtd call
  • Loading branch information
qubesuser committed Nov 10, 2017
1 parent 0cc53a8 commit 2df2c4d
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,9 +1580,10 @@ def get_mem(self):
return 0

try:
if not self.libvirt_domain.isActive():
info = self.libvirt_domain.info()
if info[0] == libvirt.VIR_DOMAIN_SHUTOFF:
return 0
return self.libvirt_domain.info()[1]
return info[1]

except libvirt.libvirtError as e:
if e.get_error_code() in (
Expand Down Expand Up @@ -1635,20 +1636,16 @@ def get_cputime(self):
if self.libvirt_domain is None:
return 0

if self.libvirt_domain is None:
return 0
if not self.libvirt_domain.isActive():
return 0

try:
if not self.libvirt_domain.isActive():
return 0

# this does not work, because libvirt
# return self.libvirt_domain.getCPUStats(
# libvirt.VIR_NODE_CPU_STATS_ALL_CPUS, 0)[0]['cpu_time']/10**9

return self.libvirt_domain.info()[4]
info = self.libvirt_domain.info()
if info[0] == libvirt.VIR_DOMAIN_SHUTOFF:
return 0

return info[4]

except libvirt.libvirtError as e:
if e.get_error_code() in (
Expand Down

0 comments on commit 2df2c4d

Please sign in to comment.