]> rtime.felk.cvut.cz Git - can-benchmark.git/blobdiff - tests/genhtml.py
HTML report + many modifications
[can-benchmark.git] / tests / genhtml.py
diff --git a/tests/genhtml.py b/tests/genhtml.py
new file mode 100755 (executable)
index 0000000..8fd6da2
--- /dev/null
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+
+import os;
+import dircache;
+import sys;
+
+os.chdir(sys.argv[1])
+
+class Axis:
+    def __init__(self, atype):
+        self.type = atype
+        self.values = dircache.listdir('by-%s'%atype)
+
+    def __str__(self):
+        if self.type == "kern": return "kernel"
+        elif self.type == "clck": return "CPU clock"
+        elif self.type == "test": return "test"
+        else: raise Exception, "Unknown type"
+
+    def __iter__(self):
+        return iter(self.values)
+
+    def __getitem__(self, key):
+        return self.values[key]
+
+    def getLabel(self, v):
+        if self.type == "clck": return v+" MHz"
+        elif self.type == "test": return "<a href='%s.sh.html'>%s</a>"%(v, v)
+        else: return v
+
+
+    def labels(self):
+        for v in self.values:
+            yield self.getLabel(v)
+        
+kernels = Axis('kern')
+clocks = Axis('clck')
+tests = Axis('test')
+
+class PageSet:
+    def __init__(self, values, x, y):
+        self.values = values
+        self.x = x
+        self.y = y
+
+    def getPages(self):
+        for v in self.values:
+            yield Page(self.values.type, str(self.values), v, self.x, self.y)
+
+class Page:
+    def __init__(self, prefix, name, value, xvals, yvals):
+        self.prefix = prefix
+        self.name = name
+        self.value = value
+        self.xvals = xvals
+        self.yvals = yvals
+                 
+    def generate(self, pagesets):
+        html = open("%s-%s.html"%(self.prefix, self.value), "w")
+        print >> html, """<html>
+<head>
+<title>CAN driver benchmark for %s %s</title>
+<style>
+img { border: 0; }
+table { border-collapse: collapse; }
+td { border: 1px solid lightgray; padding: 4px;}
+</style>
+</head>
+<body>
+<h1>CAN driver benchmark for %s %s</h1>"""  % (self.name, self.value, self.name, self.value)
+        for ps in pagesets:
+            print >>html, "View by %s: " % str(ps.values)
+            for v in ps.values:
+                print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, v, v)
+            print >>html, "<br>"
+        print >>html, "<table><thead><tr><td> </td>"
+        for x in self.xvals.labels():
+            print >>html, "<td>%s</td>" % x
+        print >>html, "</tr></thead>"
+        for y in self.yvals:
+            print >>html, "<tr><td>%s</td>" % self.yvals.getLabel(y)
+
+            for x in self.xvals:
+                print >>html, "<td>"
+                d="by-%s/%s/%s/%s/" % (self.prefix, self.value, y, x)
+                dthumb = d+"thumb"
+                try:
+                    for img in dircache.listdir(dthumb):
+                        print >>html, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % (d, img, d, img)
+                except OSError:
+                    print "error"
+                    print >>html, "</td>"
+                    print >>html, "</tr>"
+                    print >> html, """
+</table>
+</body>
+"""
+
+
+pagesets = [ PageSet(kernels, clocks, tests),
+             PageSet(tests, clocks, kernels),
+             PageSet(clocks, kernels, tests)]
+
+for ps in pagesets:
+    for p in ps.getPages():
+        p.generate(pagesets)
+
+try:
+    os.remove("index.html")
+except OSError: pass
+
+os.symlink("%s-%s.html"%(kernels.type, kernels[0]), "index.html")
+
+os.system("source-highlight -d --output-dir=. ../*.sh")
+    
+
+