Francesco Romani has uploaded a new change for review. Change subject: sampling: make PidCpuSample a function ......................................................................
sampling: make PidCpuSample a function make the PidCpuSample 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: Iaffb10fa48ee6876156a27c2ad132298fc9d72ae Signed-off-by: Francesco Romani <[email protected]> --- M vdsm/virt/sampling.py 1 file changed, 5 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/50/41250/1 diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py index fb99441..6b13913 100644 --- a/vdsm/virt/sampling.py +++ b/vdsm/virt/sampling.py @@ -179,16 +179,15 @@ self.nodesMemSample[nodeIndex] = nodeMemSample -class PidCpuSample(object): +def _get_pid_cpu_sample(pid): """ A sample of the CPU consumption of a process. The sample is taken at initialization time and can't be updated. """ - def __init__(self, pid): - with open('/proc/%s/stat' % pid) as stat: - self.user, self.sys = \ - map(int, stat.read().split()[13:15]) + with open('/proc/%s/stat' % pid) as stat: + user, sys = map(int, stat.read().split()[13:15]) + return CpuSample(user, 0, sys, 0) class TimedSample(object): @@ -260,7 +259,7 @@ """ super(HostSample, self).__init__() self.interfaces = _get_interfaces_and_samples() - self.pidcpu = PidCpuSample(pid) + self.pidcpu = _get_pid_cpu_sample(pid) self.totcpu = _get_total_cpu_sample() meminfo = utils.readMemInfo() freeOrCached = (meminfo['MemFree'] + -- To view, visit https://gerrit.ovirt.org/41250 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaffb10fa48ee6876156a27c2ad132298fc9d72ae 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
