Francesco Romani has uploaded a new change for review.

Change subject: virt: sampling: extract disk latency calculation
......................................................................

virt: sampling: extract disk latency calculation

This is a preparation patch for the merge
of sampleDisk and sampleDiskLatency

Change-Id: I3f78e2a990aefe6095dd4ff54e21ab40006c0713
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm/virt/vm.py
1 file changed, 21 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/52/29952/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 4a3f629..1082d1c 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -538,7 +538,22 @@
     def _getDiskLatency(self, stats):
         sInfo, eInfo, sampleInterval = self.sampleDiskLatency.getStats()
 
-        def _avgLatencyCalc(sData, eData):
+        for vmDrive in self._vm.getDiskDevices():
+            if sInfo is not None:
+                dLatency = self._calcDiskLatency(vmDrive, sInfo, eInfo,
+                                                 sampleInterval)
+            else:
+                # will be None if sampled during recovery
+                dLatency = {'readLatency': '0',
+                            'writeLatency': '0',
+                            'flushLatency': '0'}
+
+            stats[dName].update(dLatency)
+
+    def _calcDiskLatency(self, vmDrive, sInfo, eInfo, sampleInterval):
+        try:
+            sData = sInfo[vmDrive.name]
+            eData = eInfo[vmDrive.name]
             readLatency = (0 if not (eData['rd_operations'] -
                                      sData['rd_operations'])
                            else (eData['rd_total_times'] -
@@ -561,21 +576,11 @@
                 'readLatency': str(readLatency),
                 'writeLatency': str(writeLatency),
                 'flushLatency': str(flushLatency)}
-
-        for vmDrive in self._vm.getDiskDevices():
-            dName = vmDrive.name
-            dLatency = {'readLatency': '0',
-                        'writeLatency': '0',
-                        'flushLatency': '0'}
-
-            if sInfo is not None:
-                # will be None if sampled during recovery
-                try:
-                    dLatency = _avgLatencyCalc(sInfo[dName], eInfo[dName])
-                except (KeyError, TypeError):
-                    self._log.exception("Disk %s latency not available", dName)
-
-            stats[dName].update(dLatency)
+        except (KeyError, TypeError):
+            self._log.exception("Disk %s latency not available", vmDrive.name)
+            return {'readLatency': '0',
+                    'writeLatency': '0',
+                    'flushLatency': '0'}
 
     def _getVmJobs(self, stats):
         sInfo, eInfo, sampleInterval = self.sampleVmJobs.getStats()


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

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