diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index 8660abcb..1e197e41 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -712,6 +712,18 @@ class QubesVm(object): return 0 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): if dry_run: return 666 @@ -723,7 +735,8 @@ class QubesVm(object): def get_prefmem(self): # 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) if untrusted_meminfo_key is None or untrusted_meminfo_key == '': return 0 diff --git a/core/qubes.py b/core/qubes.py index 797e1e14..5b6a5e28 100755 --- a/core/qubes.py +++ b/core/qubes.py @@ -211,42 +211,41 @@ class QubesHost(object): return self._no_cpus # TODO - def get_free_xen_memory(self): - ret = self.physinfo['free_memory'] - return long(ret) - - # TODO - def measure_cpu_usage(self, previous=None, previous_time = None, + def measure_cpu_usage(self, qvmc, previous=None, previous_time = None, wait_time=1): """measure cpu usage for all domains at once""" if previous is None: previous_time = time.time() previous = {} - info = vmm.xc.domain_getinfo(0, qubes_max_qid) - for vm in info: - previous[vm['domid']] = {} - previous[vm['domid']]['cpu_time'] = ( - vm['cpu_time'] / vm['online_vcpus']) - previous[vm['domid']]['cpu_usage'] = 0 + for vm in qvmc.values(): + if not vm.is_running(): + continue + cputime = vm.get_cputime() + previous[vm.xid] = {} + previous[vm.xid]['cpu_time'] = ( + cputime / vm.vcpus) + previous[vm.xid]['cpu_usage'] = 0 time.sleep(wait_time) current_time = time.time() current = {} - info = vmm.xc.domain_getinfo(0, qubes_max_qid) - for vm in info: - current[vm['domid']] = {} - current[vm['domid']]['cpu_time'] = ( - vm['cpu_time'] / max(vm['online_vcpus'], 1)) - if vm['domid'] in previous.keys(): - current[vm['domid']]['cpu_usage'] = ( - float(current[vm['domid']]['cpu_time'] - - previous[vm['domid']]['cpu_time']) / + for vm in qvmc.values(): + if not vm.is_running(): + continue + cputime = vm.get_cputime() + current[vm.xid] = {} + current[vm.xid]['cpu_time'] = ( + cputime / max(vm.vcpus, 1)) + if vm.xid in previous.keys(): + current[vm.xid]['cpu_usage'] = ( + float(current[vm.xid]['cpu_time'] - + previous[vm.xid]['cpu_time']) / 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 - current[vm['domid']]['cpu_usage'] = 0 + current[vm.xid]['cpu_usage'] = 0 else: - current[vm['domid']]['cpu_usage'] = 0 + current[vm.xid]['cpu_usage'] = 0 return (current_time, current)