adopt for new qubes cpu usage stats API (all stats in one call)

This commit is contained in:
Marek Marczykowski 2011-06-02 01:15:24 +02:00
parent a10120cfb9
commit 0f957df4d0
2 changed files with 32 additions and 17 deletions

View File

@ -166,7 +166,7 @@ class VmInfoWidget (QWidget):
self.previous_outdated = outdated self.previous_outdated = outdated
class VmUsageWidget (QWidget): class VmUsageWidget (QWidget):
def __init__(self, vm, parent = None): def __init__(self, vm, cpu_load = 0, parent = None):
super (VmUsageWidget, self).__init__(parent) super (VmUsageWidget, self).__init__(parent)
self.cpu_widget = QProgressBar() self.cpu_widget = QProgressBar()
@ -174,7 +174,7 @@ class VmUsageWidget (QWidget):
self.cpu_widget.setMinimum(0) self.cpu_widget.setMinimum(0)
self.cpu_widget.setMaximum(100) self.cpu_widget.setMaximum(100)
self.mem_widget.setMinimum(0) self.mem_widget.setMinimum(0)
self.mem_widget.setMaximum(qubes_host.memory_total/(1024*1024)) self.mem_widget.setMaximum(qubes_host.memory_total/1024)
self.mem_widget.setFormat ("%v MB"); self.mem_widget.setFormat ("%v MB");
self.cpu_label = QLabel("CPU") self.cpu_label = QLabel("CPU")
self.mem_label = QLabel("MEM") self.mem_label = QLabel("MEM")
@ -193,11 +193,11 @@ class VmUsageWidget (QWidget):
self.setLayout(layout) self.setLayout(layout)
self.update_load(vm) self.update_load(vm, cpu_load)
def update_load(self, vm): def update_load(self, vm, cpu_load):
self.cpu_load = vm.get_cpu_total_load() if vm.last_power_state else 0 self.cpu_load = cpu_load if vm.last_power_state else 0
self.mem_load = vm.get_mem()/(1024*1024) if vm.last_power_state else 0 self.mem_load = vm.get_mem()/1024 if vm.last_power_state else 0
self.cpu_widget.setValue(self.cpu_load) self.cpu_widget.setValue(self.cpu_load)
self.mem_widget.setValue(self.mem_load) self.mem_widget.setValue(self.mem_load)
@ -210,14 +210,14 @@ class VmUsageWidget (QWidget):
class LoadChartWidget (QWidget): class LoadChartWidget (QWidget):
def __init__(self, vm, parent = None): def __init__(self, vm, cpu_load = 0, parent = None):
super (LoadChartWidget, self).__init__(parent) super (LoadChartWidget, self).__init__(parent)
self.load = vm.get_cpu_total_load() if vm.last_power_state else 0 self.load = cpu_load if vm.last_power_state else 0
assert self.load >= 0 and self.load <= 100, "load = {0}".format(self.load) assert self.load >= 0 and self.load <= 100, "load = {0}".format(self.load)
self.load_history = [self.load] self.load_history = [self.load]
def update_load (self, vm): def update_load (self, vm, cpu_load):
self.load = vm.get_cpu_total_load() if vm.last_power_state else 0 self.load = cpu_load if vm.last_power_state else 0
assert self.load >= 0 and self.load <= 100, "load = {0}".format(self.load) assert self.load >= 0 and self.load <= 100, "load = {0}".format(self.load)
self.load_history.append (self.load) self.load_history.append (self.load)
self.repaint() self.repaint()
@ -308,11 +308,11 @@ class VmRowInTable(object):
table.setCellWidget(row_no, 3, self.mem_widget) table.setCellWidget(row_no, 3, self.mem_widget)
def update(self, counter): def update(self, counter, cpu_load = None):
self.info_widget.update_vm_state(self.vm) self.info_widget.update_vm_state(self.vm)
if counter % 3 == 0: if cpu_load is not None:
self.usage_widget.update_load(self.vm) self.usage_widget.update_load(self.vm, cpu_load)
self.load_widget.update_load(self.vm) self.load_widget.update_load(self.vm, cpu_load)
self.mem_widget.update_load(self.vm) self.mem_widget.update_load(self.vm)
self.info_widget.update_outdated(self.vm) self.info_widget.update_outdated(self.vm)
@ -453,6 +453,8 @@ class VmManagerWindow(QMainWindow):
self.counter = 0 self.counter = 0
self.shutdown_monitor = {} self.shutdown_monitor = {}
self.last_measure_results = {}
self.last_measure_time = time.time()
QTimer.singleShot (self.update_interval, self.update_table) QTimer.singleShot (self.update_interval, self.update_table)
QTimer.singleShot (self.fw_rules_apply_check_interval, self.check_apply_fw_rules) QTimer.singleShot (self.fw_rules_apply_check_interval, self.check_apply_fw_rules)
@ -567,8 +569,21 @@ class VmManagerWindow(QMainWindow):
if self.reload_table or ((not self.show_inactive_vms) and some_vms_have_changed_power_state): if self.reload_table or ((not self.show_inactive_vms) and some_vms_have_changed_power_state):
self.fill_table() self.fill_table()
for vm_row in self.vms_in_table: if self.counter % 3 == 0 or out_of_schedule:
vm_row.update(self.counter) (self.last_measure_time, self.last_measure_results) = \
qubes_host.measure_cpu_usage(self.last_measure_results,
self.last_measure_time)
for vm_row in self.vms_in_table:
cur_cpu_load = None
if vm_row.vm.get_xid() in self.last_measure_results:
cur_cpu_load = self.last_measure_results[vm_row.vm.xid]['cpu_usage']
else:
cur_cpu_load = 0
vm_row.update(self.counter, cpu_load = cur_cpu_load)
else:
for vm_row in self.vms_in_table:
vm_row.update(self.counter)
self.table_selection_changed() self.table_selection_changed()

View File

@ -11,7 +11,7 @@ Group: Qubes
Vendor: Invisible Things Lab Vendor: Invisible Things Lab
License: GPL License: GPL
URL: http://fixme URL: http://fixme
Requires: python, PyQt4, qubes-core-dom0 >= 1.0.3, kdebase Requires: python, PyQt4, qubes-core-dom0 >= 1.3.1, kdebase
BuildRequires: PyQt4-devel BuildRequires: PyQt4-devel
AutoReq: 0 AutoReq: 0