Change in vdsm[master]: sampling: decouple fetch from translation

fromani at redhat.com fromani at redhat.com
Fri Jan 9 12:34:50 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: sampling: decouple fetch from translation
......................................................................

sampling: decouple fetch from translation

Decouple the sample fetching from
the sample transformation in VM stats.

Future patch want to decouple further
sampling gathering from statistics production,
in order to make room for alternate
implementations (bulk stats).

Change-Id: I4e46a9f2ff96544ceac51ab011fa078859280287
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/numaUtils.py
M vdsm/virt/vm.py
2 files changed, 60 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/29/36729/1

diff --git a/vdsm/numaUtils.py b/vdsm/numaUtils.py
index df0c9b7..6207816 100644
--- a/vdsm/numaUtils.py
+++ b/vdsm/numaUtils.py
@@ -36,7 +36,7 @@
     return vCpuPids
 
 
-def getVmNumaNodeRuntimeInfo(vm):
+def getVmNumaNodeRuntimeInfo(vm, sample):
     """
     Collect vm numa nodes runtime pinning to which host numa nodes
     information.
@@ -69,7 +69,7 @@
 
     vmNumaNodeRuntimeMap = {}
     if 'guestNumaNodes' in vm.conf:
-        vCpuRuntimePinMap = _getVcpuRuntimePinMap(vm)
+        vCpuRuntimePinMap = _getVcpuRuntimePinMap(sample)
         if vCpuRuntimePinMap:
             vmName = vm.conf['vmName'].encode('utf-8')
             vCpuMemoryMapping = \
@@ -89,10 +89,9 @@
     return vmNumaNodeRuntimeMap
 
 
-def _getVcpuRuntimePinMap(vm):
+def _getVcpuRuntimePinMap(sample):
     vCpuRuntimePinMap = {}
-    if vm.stats:
-        sample = vm.stats.sampleVcpuPinning.getLastSample()
+    if sample:
         vCpuInfos = sample if sample is not None else []
         for vCpuInfo in vCpuInfos:
             vCpuRuntimePinMap[vCpuInfo[0]] = vCpuInfo[3]
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index fb46a54..c78c9cf 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -478,11 +478,9 @@
     def _usagePercentage(self, val, sampleInterval):
         return 100 * val / sampleInterval / 1000 ** 3
 
-    def _getCpuStats(self, stats):
+    def _getCpuStats(self, stats, sInfo, eInfo, interval):
         stats['cpuUser'] = 0.0
         stats['cpuSys'] = 0.0
-
-        sInfo, eInfo, sampleInterval = self.sampleCpu.getStats()
 
         if sInfo is None:
             return
@@ -491,20 +489,18 @@
             stats['cpuSys'] = self._usagePercentage(
                 self._diff(eInfo, sInfo, 'user_time') +
                 self._diff(eInfo, sInfo, 'system_time'),
-                sampleInterval)
+                interval)
             stats['cpuUser'] = self._usagePercentage(
                 self._diff(eInfo, sInfo, 'cpu_time')
                 - self._diff(eInfo, sInfo, 'user_time')
                 - self._diff(eInfo, sInfo, 'system_time'),
-                sampleInterval)
+                interval)
 
         except (TypeError, ZeroDivisionError) as e:
             self._log.exception("CPU stats not available: %s", e)
 
-    def _getBalloonStats(self, stats):
+    def _getBalloonStats(self, stats, sample):
         max_mem = int(self._vm.conf.get('memSize')) * 1024
-
-        sample = self.sampleBalloon.getLastSample()
 
         for dev in self._vm.getBalloonDevicesConf():
             if dev['specParams']['model'] != 'none':
@@ -527,10 +523,7 @@
                 'balloon_target': str(balloon_target)
             })
 
-    def _getCpuTuneInfo(self, stats):
-
-        sample = self.sampleCpuTune.getLastSample()
-
+    def _getCpuTuneInfo(self, stats, sample):
         # Handling the case when not enough samples exist
         if sample is None:
             return
@@ -547,9 +540,7 @@
         if sample.get('vcpu_period', _NO_CPU_PERIOD) != _NO_CPU_PERIOD:
             stats['vcpuPeriod'] = sample['vcpu_period']
 
-    def _getCpuCount(self, stats):
-        sample = self.sampleCpuTune.getLastSample()
-
+    def _getCpuCount(self, stats, sample):
         # Handling the case when not enough samples exist
         if sample is None:
             return
@@ -561,9 +552,7 @@
             else:
                 self._log.error('Failed to get VM cpu count')
 
-    def _getUserCpuTuneInfo(self, stats):
-        sample = self.sampleCpuTune.getLastSample()
-
+    def _getUserCpuTuneInfo(self, stats, sample):
         # Handling the case when not enough samples exist
         if sample is None:
             return
@@ -599,9 +588,8 @@
 
         return ifStats
 
-    def _getNetworkStats(self, stats):
+    def _getNetworkStats(self, stats, sInfo, eInfo, interval):
         stats['network'] = {}
-        sInfo, eInfo, sampleInterval = self.sampleNet.getStats()
 
         if sInfo is None:
             return
@@ -616,11 +604,9 @@
 
             stats['network'][nic.name] = self._getNicStats(
                 nic.name, nic.nicModel, nic.macAddr,
-                sInfo[nic.name], eInfo[nic.name], sampleInterval)
+                sInfo[nic.name], eInfo[nic.name], interval)
 
-    def _getDiskStats(self, stats):
-        sInfo, eInfo, sampleInterval = self.sampleDisk.getStats()
-
+    def _getDiskStats(self, stats, sInfo, eInfo, interval):
         for vmDrive in self._vm.getDiskDevices():
             dStats = {}
             try:
@@ -637,7 +623,7 @@
                         eInfo and vmDrive.name in eInfo):
                     # will be None if sampled during recovery
                     dStats.update(_calcDiskRate(vmDrive, sInfo, eInfo,
-                                                sampleInterval))
+                                                interval))
                     dStats.update(_calcDiskLatency(vmDrive, sInfo, eInfo))
 
             except (AttributeError, TypeError, ZeroDivisionError):
@@ -646,18 +632,39 @@
 
             stats[vmDrive.name] = dStats
 
-    def _getNumaStats(self, stats):
-        vmNumaNodeRuntimeMap = numaUtils.getVmNumaNodeRuntimeInfo(self._vm)
+    def _getNumaStats(self, stats, sample):
+        vmNumaNodeRuntimeMap = numaUtils.getVmNumaNodeRuntimeInfo(
+            self._vm, sample)
         if vmNumaNodeRuntimeMap:
             stats['vNodeRuntimeInfo'] = vmNumaNodeRuntimeMap
 
-    def _getVmJobs(self, stats):
-        info = self.sampleVmJobs.getLastSample()
-        if info is not None:
+    def _getVmJobs(self, stats, sample):
+        if sample is not None:
             # If we are unable to collect stats we must not return anything at
             # all since an empty dictionary would be interpreted as vm jobs
             # finishing.
-            stats['vmJobs'] = info
+            stats['vmJobs'] = sample
+
+    def _getSampleCpu(self):
+        return self.sampleCpu.getStats()
+
+    def _getSampleNet(self):
+        return self.sampleNet.getStats()
+
+    def _getSampleDisk(self):
+        return self.sampleDisk.getStats()
+
+    def _getSampleBalloon(self):
+        return self.sampleBalloon.getLastSample()
+
+    def _getSampleVmJobs(self):
+        return self.sampleVmJobs.getLastSample()
+
+    def _getSampleVcpu(self):
+        return self.sampleVcpuPinning.getLastSample()
+
+    def _getSampleCpuTune(self):
+        return self.sampleCpuTune.getLastSample()
 
     def get(self):
         stats = {}
@@ -668,15 +675,24 @@
             self._log.debug("Stats age not available")
             stats['statsAge'] = -1.0
 
-        self._getCpuStats(stats)
-        self._getNetworkStats(stats)
-        self._getDiskStats(stats)
-        self._getBalloonStats(stats)
-        self._getVmJobs(stats)
-        self._getNumaStats(stats)
-        self._getCpuTuneInfo(stats)
-        self._getCpuCount(stats)
-        self._getUserCpuTuneInfo(stats)
+        sCpu, eCpu, cpuInterval = self._getSampleCpu()
+        self._getCpuStats(stats, sCpu, eCpu, cpuInterval)
+
+        sNet, eNet, netInterval = self._getSampleNet()
+        self._getNetworkStats(stats, sNet, eNet, netInterval)
+
+        sDisk, eDisk, diskInterval = self._getSampleDisk()
+        self._getDiskStats(stats, sDisk, eDisk, diskInterval)
+
+        self._getBalloonStats(stats, self._getSampleBalloon())
+        self._getVmJobs(stats, self._getSampleVmJobs())
+        self._getNumaStats(stats, self._getSampleVcpu())
+
+        cpuTuneSample = self._getSampleCpuTune()
+        self._getCpuTuneInfo(stats, cpuTuneSample)
+        self._getCpuCount(stats, cpuTuneSample)
+        self._getUserCpuTuneInfo(stats, cpuTuneSample)
+
         self._getIoTuneStats(stats)
 
         return stats


-- 
To view, visit http://gerrit.ovirt.org/36729
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e46a9f2ff96544ceac51ab011fa078859280287
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