Francesco Romani has uploaded a new change for review.
Change subject: sampling: add 'ncpus' property to HostSample
......................................................................
sampling: add 'ncpus' property to HostSample
to decouple HostStatsThread and hoststats.produce().
Change-Id: I0e7d549b7772e3f38eec2dd9b91bbc6416b549bf
Signed-off-by: Francesco Romani <fromani(a)redhat.com>
---
M vdsm/virt/hoststats.py
M vdsm/virt/sampling.py
2 files changed, 7 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/35/42035/1
diff --git a/vdsm/virt/hoststats.py b/vdsm/virt/hoststats.py
index 57c6954..7a23743 100644
--- a/vdsm/virt/hoststats.py
+++ b/vdsm/virt/hoststats.py
@@ -26,7 +26,7 @@
import v2v
-def produce(ncpus, first_sample, last_sample):
+def produce(first_sample, last_sample):
stats = _empty_stats()
if first_sample is None:
@@ -45,10 +45,10 @@
jiffies = (
last_sample.totcpu.user - first_sample.totcpu.user) % (2 ** 32)
- stats['cpuUser'] = jiffies / interval / ncpus
+ stats['cpuUser'] = jiffies / interval / last_sample.ncpus
jiffies = (
last_sample.totcpu.sys - first_sample.totcpu.sys) % (2 ** 32)
- stats['cpuSys'] = jiffies / interval / ncpus
+ stats['cpuSys'] = jiffies / interval / last_sample.ncpus
stats['cpuIdle'] = max(0.0,
100.0 - stats['cpuUser'] - stats['cpuSys'])
stats['memUsed'] = last_sample.memUsed
diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 5729a54..401bae9 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -232,7 +232,7 @@
d[p] = {'free': str(free)}
return d
- def __init__(self, pid):
+ def __init__(self, pid, ncpus):
"""
Initialize a HostSample.
@@ -242,6 +242,7 @@
super(HostSample, self).__init__()
self.interfaces = _get_interfaces_and_samples()
self.pidcpu = PidCpuSample(pid)
+ self.ncpus = ncpus
self.totcpu = TotalCpuSample()
meminfo = utils.readMemInfo()
freeOrCached = (meminfo['MemFree'] +
@@ -553,7 +554,7 @@
time.sleep(self._sampleInterval)
while not self._stopEvent.isSet():
try:
- sample = HostSample(self._pid)
+ sample = HostSample(self._pid, self._ncpus)
self._samples.append(sample)
second_last = self._samples.last(nth=2)
if second_last is None:
@@ -571,7 +572,7 @@
def get(self):
first_sample, last_sample, _ = self._samples.stats()
- return hoststats.produce(self._ncpus, first_sample, last_sample)
+ return hoststats.produce(first_sample, last_sample)
def _getLinkSpeed(dev):
--
To view, visit
https://gerrit.ovirt.org/42035
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e7d549b7772e3f38eec2dd9b91bbc6416b549bf
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani(a)redhat.com>