core: convert memory/cpu stats to libvirt API
This commit is contained in:
parent
f9b2636c73
commit
869675c15c
@ -712,6 +712,18 @@ class QubesVm(object):
|
|||||||
return 0
|
return 0
|
||||||
return self.libvirt_domain.info()[1]
|
return self.libvirt_domain.info()[1]
|
||||||
|
|
||||||
|
def get_cputime(self):
|
||||||
|
if dry_run:
|
||||||
|
return 666
|
||||||
|
|
||||||
|
if self.libvirt_domain is None:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if not self.libvirt_domain.isActive():
|
||||||
|
return 0
|
||||||
|
return self.libvirt_domain.info()[4]
|
||||||
|
|
||||||
|
|
||||||
def get_mem_static_max(self):
|
def get_mem_static_max(self):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return 666
|
return 666
|
||||||
@ -723,7 +735,8 @@ class QubesVm(object):
|
|||||||
|
|
||||||
def get_prefmem(self):
|
def get_prefmem(self):
|
||||||
# TODO: qmemman is still xen specific
|
# TODO: qmemman is still xen specific
|
||||||
untrusted_meminfo_key = xs.read('', '/local/domain/%s/memory/meminfo'
|
untrusted_meminfo_key = vmm.xs.read('',
|
||||||
|
'/local/domain/%s/memory/meminfo'
|
||||||
% self.xid)
|
% self.xid)
|
||||||
if untrusted_meminfo_key is None or untrusted_meminfo_key == '':
|
if untrusted_meminfo_key is None or untrusted_meminfo_key == '':
|
||||||
return 0
|
return 0
|
||||||
|
@ -211,42 +211,41 @@ class QubesHost(object):
|
|||||||
return self._no_cpus
|
return self._no_cpus
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
def get_free_xen_memory(self):
|
def measure_cpu_usage(self, qvmc, previous=None, previous_time = None,
|
||||||
ret = self.physinfo['free_memory']
|
|
||||||
return long(ret)
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
def measure_cpu_usage(self, previous=None, previous_time = None,
|
|
||||||
wait_time=1):
|
wait_time=1):
|
||||||
"""measure cpu usage for all domains at once"""
|
"""measure cpu usage for all domains at once"""
|
||||||
if previous is None:
|
if previous is None:
|
||||||
previous_time = time.time()
|
previous_time = time.time()
|
||||||
previous = {}
|
previous = {}
|
||||||
info = vmm.xc.domain_getinfo(0, qubes_max_qid)
|
for vm in qvmc.values():
|
||||||
for vm in info:
|
if not vm.is_running():
|
||||||
previous[vm['domid']] = {}
|
continue
|
||||||
previous[vm['domid']]['cpu_time'] = (
|
cputime = vm.get_cputime()
|
||||||
vm['cpu_time'] / vm['online_vcpus'])
|
previous[vm.xid] = {}
|
||||||
previous[vm['domid']]['cpu_usage'] = 0
|
previous[vm.xid]['cpu_time'] = (
|
||||||
|
cputime / vm.vcpus)
|
||||||
|
previous[vm.xid]['cpu_usage'] = 0
|
||||||
time.sleep(wait_time)
|
time.sleep(wait_time)
|
||||||
|
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
current = {}
|
current = {}
|
||||||
info = vmm.xc.domain_getinfo(0, qubes_max_qid)
|
for vm in qvmc.values():
|
||||||
for vm in info:
|
if not vm.is_running():
|
||||||
current[vm['domid']] = {}
|
continue
|
||||||
current[vm['domid']]['cpu_time'] = (
|
cputime = vm.get_cputime()
|
||||||
vm['cpu_time'] / max(vm['online_vcpus'], 1))
|
current[vm.xid] = {}
|
||||||
if vm['domid'] in previous.keys():
|
current[vm.xid]['cpu_time'] = (
|
||||||
current[vm['domid']]['cpu_usage'] = (
|
cputime / max(vm.vcpus, 1))
|
||||||
float(current[vm['domid']]['cpu_time'] -
|
if vm.xid in previous.keys():
|
||||||
previous[vm['domid']]['cpu_time']) /
|
current[vm.xid]['cpu_usage'] = (
|
||||||
|
float(current[vm.xid]['cpu_time'] -
|
||||||
|
previous[vm.xid]['cpu_time']) /
|
||||||
long(1000**3) / (current_time-previous_time) * 100)
|
long(1000**3) / (current_time-previous_time) * 100)
|
||||||
if current[vm['domid']]['cpu_usage'] < 0:
|
if current[vm.xid]['cpu_usage'] < 0:
|
||||||
# VM has been rebooted
|
# VM has been rebooted
|
||||||
current[vm['domid']]['cpu_usage'] = 0
|
current[vm.xid]['cpu_usage'] = 0
|
||||||
else:
|
else:
|
||||||
current[vm['domid']]['cpu_usage'] = 0
|
current[vm.xid]['cpu_usage'] = 0
|
||||||
|
|
||||||
return (current_time, current)
|
return (current_time, current)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user