Change in vdsm[master]: domain: use the dd statistics for the domain delay

fsimonce at redhat.com fsimonce at redhat.com
Fri May 24 11:21:43 UTC 2013


Federico Simoncelli has uploaded a new change for review.

Change subject: domain: use the dd statistics for the domain delay
......................................................................

domain: use the dd statistics for the domain delay

The previous implementation of getReadDelay was calculating the reading
time (for the domain statistics) checking the execution time of dd.
This patch introduces a low level readspeed command to parse the more
accurate statistics provided by dd in the stderr.

Bug-Url: http://bugzilla.redhat.com/show_bug.cgi?id=948232
Change-Id: Ib3fa54dbbe3475b74bcfe5cbc0c60895818f8b3e
Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
---
M tests/miscTests.py
M vdsm/storage/blockSD.py
M vdsm/storage/misc.py
3 files changed, 61 insertions(+), 7 deletions(-)


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

diff --git a/tests/miscTests.py b/tests/miscTests.py
index 96549c8..5011b91 100644
--- a/tests/miscTests.py
+++ b/tests/miscTests.py
@@ -883,6 +883,24 @@
         self.assertRaises(misc.se.MiscFileReadException, misc.readfile, path)
 
 
+class ReadSpeed(TestCaseBase):
+    STATS_TEMPLATE = "%s byte%s (%s %sB) copied, %s s, %s %sB/s"
+    STATS_TESTS = (
+        ("1", "", "1", "", "1", "1", ""),
+        ("1024", "s", "1", "k", "1", "1", "k"),
+        ("1572864", "s", "1.5", "M", "1.5", "1", "M"),
+        ("1610612736", "s", "1.5", "G", "1000.5", "1.53", "M"),
+    )
+
+    def checkReadSpeedRegExp(self):
+        for stats in self.STATS_TESTS:
+            m = misc._readspeed_regex.match(self.STATS_TEMPLATE % stats)
+            self.assertNotEqual(m, None)
+
+            self.assertEqual(m.group("bytes"), stats[0])
+            self.assertEqual(m.group("seconds"), stats[4])
+
+
 class PidExists(TestCaseBase):
     def testPidExists(self):
         """
diff --git a/vdsm/storage/blockSD.py b/vdsm/storage/blockSD.py
index e8ce11c..86a22ee 100644
--- a/vdsm/storage/blockSD.py
+++ b/vdsm/storage/blockSD.py
@@ -591,9 +591,8 @@
         return bsd
 
     def getReadDelay(self):
-        t = time.time()
-        misc.readfile(lvm.lvPath(self.sdUUID, sd.METADATA), 4096)
-        return time.time() - t
+        stats = misc.readspeed(lvm.lvPath(self.sdUUID, sd.METADATA), 4096)
+        return stats['seconds']
 
     def getVolumeClass(self):
         """
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index 37dba7c..4c6ce2a 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -191,10 +191,7 @@
     return str(ctime)
 
 
-def readfile(name, buffersize=None):
-    """
-    Read the content of the file using /bin/dd command
-    """
+def _readfile(name, buffersize=None):
     cmd = [constants.EXT_DD]
 
     if fileUtils.pathRequiresFlagForDirectIO(name):
@@ -206,9 +203,49 @@
     (rc, out, err) = execCmd(cmd, sudo=False)
     if rc:
         raise se.MiscFileReadException(name)
+
+    return rc, out, err
+
+
+def readfile(name, buffersize=None):
+    """
+    Read the content of the file using /bin/dd command
+    """
+    rc, out, err = _readfile(name, buffersize)
     return out
 
 
+_readspeed_regex = re.compile(
+    "(?P<bytes>\d+) bytes? \([\d.]+ [kMGT]*B\) copied, "
+    "(?P<seconds>[\d.]+) s, "
+    "[\d.]+ [kMGT]*B/s"
+)
+
+
+def readspeed(path, buffersize=None):
+    """
+    Measures the amount of bytes transferred and the time elapsed
+    reading the content of the file/device
+    """
+    rc, out, err = _readfile(path, buffersize)
+
+    try:
+        # The statistics are located in the last line:
+        m = _readspeed_regex.match(err[-1])
+    except IndexError:
+        log.error("Unable to find dd statistics to parse")
+        raise se.MiscFileReadException(path)
+
+    if m is None:
+        log.error("Unable to parse dd output: '%s'", err[-1])
+        raise se.MiscFileReadException(path)
+
+    return {
+        'bytes': int(m.group('bytes')),
+        'seconds': float(m.group('seconds')),
+    }
+
+
 def readblock(name, offset, size):
     '''
     Read (direct IO) the content of device 'name' at offset, size bytes


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib3fa54dbbe3475b74bcfe5cbc0c60895818f8b3e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce at redhat.com>


More information about the vdsm-patches mailing list