Laszlo Hornyak has uploaded a new change for review. Change subject: report cpuUser and cpuSys separately ......................................................................
report cpuUser and cpuSys separately Uses virDomainGetCPUStats to get the CPU information instead of info() Change-Id: I663ad25ff3ff5ce426b5159b6c9a65b7f5167605 Signed-off-by: Laszlo Hornyak <[email protected]> --- M vdsm/libvirtvm.py 1 file changed, 14 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/18/7718/1 diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py index 6323d0c..1f68446 100644 --- a/vdsm/libvirtvm.py +++ b/vdsm/libvirtvm.py @@ -23,6 +23,7 @@ from xml.dom.minidom import parseString as _domParseStr import time import threading +import os import vm from vdsm.define import ERROR, doneCode, errCode @@ -129,8 +130,9 @@ vmDrive.apparentsize = int(volSize['apparentsize']) def _sampleCpu(self): - state, maxMem, memory, nrVirtCpu, cpuTime = self._vm._dom.info() - return cpuTime / 1000 ** 3 + cpuStats = self._vm._dom.getCPUStats(True, 0) + self._log.info(cpuStats) + return cpuStats[0] def _sampleDisk(self): if not self._vm._volumesPrepared: @@ -164,16 +166,21 @@ return netSamples def _getCpuStats(self, stats): - stats['cpuSys'] = 0.0 sInfo, eInfo, sampleInterval = self.sampleCpu.getStats() + ticks=os.sysconf('SC_CLK_TCK') + nanos=10000000 + cpuTime=0 try: - stats['cpuUser'] = 100.0 * (eInfo - sInfo) / sampleInterval - except (TypeError, ZeroDivisionError): - self._log.debug("CPU stats not available") + stats['cpuUser'] = 100 * (eInfo['user_time'] - sInfo['user_time']) / sampleInterval / nanos + stats['cpuSys'] = 100 * (eInfo['system_time'] - sInfo['system_time']) / sampleInterval / nanos + cpuTime = 100 * (eInfo['cpu_time'] - sInfo['cpu_time']) / sampleInterval / (nanos * ticks) + except (TypeError, ZeroDivisionError) as e: + self._log.debug("CPU stats not available: %s", e) stats['cpuUser'] = 0.0 + stats['cpuSys'] = 0.0 - stats['cpuIdle'] = max(0.0, 100.0 - stats['cpuUser']) + stats['cpuIdle'] = max(0.0, 100.0 - cpuTime) def _getNetworkStats(self, stats): stats['network'] = {} -- To view, visit http://gerrit.ovirt.org/7718 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I663ad25ff3ff5ce426b5159b6c9a65b7f5167605 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Laszlo Hornyak <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
