Francesco Romani has uploaded a new change for review.

Change subject: sampling: use CpuSample to store samples
......................................................................

sampling: use CpuSample to store samples

To unlock more refactoring and to make code
more consistent, introduce CpuSample namedtuple,
to have a common consistent container for both
PidCpuSample and CoreCpuSample.

Change-Id: Ide56027ed979751c80c4733aa2ca5e3b0795f2dd
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/virt/sampling.py
1 file changed, 13 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/48/41248/1

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index 79f6af5..db10656 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -118,6 +118,10 @@
             if getattr(self, attr) != getattr(other, attr))
 
 
+CpuSample = namedtuple('CpuSample',
+                       ['user', 'userNice', 'sys', 'idle'])
+
+
 class TotalCpuSample(object):
     """
     A sample of total CPU consumption.
@@ -145,14 +149,10 @@
             for line in src:
                 match = self.CPU_CORE_STATS_PATTERN.match(line)
                 if match:
-                    coreSample = {}
                     user, userNice, sys, idle = \
                         map(int, match.group(2).split()[0:4])
-                    coreSample['user'] = user
-                    coreSample['userNice'] = userNice
-                    coreSample['sys'] = sys
-                    coreSample['idle'] = idle
-                    self.coresSample[match.group(1)] = coreSample
+                    self.coresSample[match.group(1)] = CpuSample(
+                        user, userNice, sys, idle)
 
     def getCoreSample(self, coreId):
         strCoreId = str(coreId)
@@ -654,14 +654,15 @@
                 coreStat['nodeIndex'] = int(nodeIndex)
                 hs0, hs1 = self._samples[0], self._samples[-1]
                 interval = hs1.timestamp - hs0.timestamp
-                jiffies = (hs1.cpuCores.getCoreSample(cpuCore)['user'] -
-                           hs0.cpuCores.getCoreSample(cpuCore)['user']) % \
-                    (2 ** 32)
+                sample0 = hs0.cpuCores.getCoreSample(cpuCore)
+                sample1 = hs1.cpuCores.getCoreSample(cpuCore)
+
+                jiffies = (sample1.user - sample0.user) % (2 ** 32)
                 coreStat['cpuUser'] = ("%.2f" % (jiffies / interval))
-                jiffies = (hs1.cpuCores.getCoreSample(cpuCore)['sys'] -
-                           hs0.cpuCores.getCoreSample(cpuCore)['sys']) % \
-                    (2 ** 32)
+
+                jiffies = (sample1.sys - sample0.sys) % (2 ** 32)
                 coreStat['cpuSys'] = ("%.2f" % (jiffies / interval))
+
                 coreStat['cpuIdle'] = ("%.2f" %
                                        max(0.0, 100.0 -
                                            float(coreStat['cpuUser']) -


-- 
To view, visit https://gerrit.ovirt.org/41248
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide56027ed979751c80c4733aa2ca5e3b0795f2dd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to