Francesco Romani has uploaded a new change for review.

Change subject: perf: add xml benchmark script
......................................................................

perf: add xml benchmark script

Add the script used for the performance tests on this thread:

http://lists.ovirt.org/pipermail/devel/2014-June/007888.html
http://lists.ovirt.org/pipermail/devel/2014-June/007920.html

This is the very first babystep toward an automated
performance test/regression suite.

Change-Id: Ifd166b248532e73ca51fe868d22b909c1237404f
Signed-off-by: Francesco Romani <[email protected]>
---
M contrib/Makefile.am
A contrib/xmlbench.py
2 files changed, 111 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/29402/1

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 537966e..49745bf 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -23,4 +23,5 @@
 dist_noinst_PYTHON = \
        nfs-check.py \
        ivdsm.py \
+       xmlbench.py \
        $(NULL)
diff --git a/contrib/xmlbench.py b/contrib/xmlbench.py
new file mode 100755
index 0000000..3f5d47e
--- /dev/null
+++ b/contrib/xmlbench.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+
+import sys
+import threading
+import time
+import xml.dom.minidom
+import xml.etree.cElementTree
+import xml.etree.ElementTree
+
+def eprint(s):
+    sys.stderr.write('%s\n' % s)
+
+try:
+    import psutil
+except ImportError:
+    eprint("you need psutil from https://pypi.python.org/pypi/psutil";)
+
+
+
+class Worker(threading.Thread):
+    def __init__(self, func, xml, delay, numruns):
+        super(Worker, self).__init__()
+        self.daemon = True
+        self.func = func
+        self.xml = xml
+        self.delay = delay
+        self.numruns = numruns
+
+    def mustgo(self):
+        if self.numruns is not None:
+            self.numruns -= 1
+            if self.numruns <= 0:
+                return False
+        return True
+
+    def run(self):
+        while self.mustgo():
+            time.sleep(self.delay)
+            self.func(self.xml)
+
+
+PARSERS = {
+    'md': xml.dom.minidom.parseString,
+    'et': xml.etree.ElementTree.fromstring,
+    'cet': xml.etree.cElementTree.fromstring
+}
+
+
+def runner(xml, mode, nthreads, delay, numruns):
+    workers = []
+    for i in range(nthreads):
+        w = Worker(PARSERS[mode], xml, delay, numruns)
+        w.start()
+        workers.append(w)
+
+    p = psutil.Process()
+    p.cpu_percent()  # see psutil docs. Discard the first one
+    samples = []
+
+    ts = 0.0
+    while any(w.is_alive() for w in workers):
+        time.sleep(0.5)
+        ts += 0.5
+        samples.append((ts, p.cpu_percent()))
+
+    return samples
+
+
+GNUPLOT_RECIPE = \
+"""
+set datafile separator ","
+set terminal png size 900,400
+set title "XML Processing CPU usage"
+set ylabel "CPU percentage (100% = 1 core)"
+set xlabel "Time"
+#set xdata time
+#set timefmt "%s"
+#set format x "%m/%d"
+set key left top
+set grid
+plot "md.txt" using 1:2 with lines lw 2 lt 3 title 'minidom', \
+     "cet.txt" using 1:2 with lines lw 2 lt 1 title 'cElementTree'
+"""
+
+def _usage():
+    eprint("usage: xmlbench xmlpath mode nthreads [delay [numruns]]")
+    eprint("available modes: %s" % ' '.join(PARSERS.keys()))
+    eprint("plot data using:\n=== CUT HERE ===\n%s\n=== CUT HERE ===\n",
+           GNUPLOT_RECIPE)
+
+def _main(args):
+    if len(args) < 3:
+        _usage()
+        sys.exit(1)
+    else:
+        xmlpath = args[0]
+        mode = args[1]
+        nthreads = int(args[2])
+        delay = int(args[3]) if len(args) > 3 else 15
+        numruns = int(args[4]) if len(args) > 4 else None
+        if mode not in PARSERS:
+            _usage()
+            sys.exit(2)
+        with open(xmlpath, 'rt') as xml:
+            samples = runner(xml.read(), mode, nthreads, delay, numruns)
+            for (ts, value) in samples:
+                print '%f,%f' % (ts, value)
+
+if __name__ == "__main__":
+    _main(sys.argv[1:])


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

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