Change in vdsm[master]: sampling: make TotalCpuSample a function

fromani at redhat.com fromani at redhat.com
Thu May 21 07:29:08 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: sampling: make TotalCpuSample a function
......................................................................

sampling: make TotalCpuSample a function

make the TotalCpuSample class a function, which
returns a CpuSample namedtuple. The surrounding
code doesn't need to change, and the module is
now a tiny bit shorter and simpler.

Change-Id: I27a4248516811bb6e341e438228b828fa661a767
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/sampling.py
1 file changed, 5 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/49/41249/1

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index db10656..fb99441 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -122,17 +122,15 @@
                        ['user', 'userNice', 'sys', 'idle'])
 
 
-class TotalCpuSample(object):
+def _get_total_cpu_sample():
     """
     A sample of total CPU consumption.
 
     The sample is taken at initialization time and can't be updated.
     """
-    def __init__(self):
-        with open('/proc/stat') as f:
-            self.user, userNice, self.sys, self.idle = \
-                map(int, f.readline().split()[1:5])
-        self.user += userNice
+    with open('/proc/stat') as f:
+        user, userNice, sys, idle = map(int, f.readline().split()[1:5])
+        return CpuSample(user + userNice, userNice, sys, idle)
 
 
 class CpuCoreSample(object):
@@ -263,7 +261,7 @@
         super(HostSample, self).__init__()
         self.interfaces = _get_interfaces_and_samples()
         self.pidcpu = PidCpuSample(pid)
-        self.totcpu = TotalCpuSample()
+        self.totcpu = _get_total_cpu_sample()
         meminfo = utils.readMemInfo()
         freeOrCached = (meminfo['MemFree'] +
                         meminfo['Cached'] + meminfo['Buffers'])


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I27a4248516811bb6e341e438228b828fa661a767
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list