]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - tests/genhtml.py
Determine CPU clock frequencies dynamically
[can-benchmark.git] / tests / genhtml.py
1 #!/usr/bin/env python
2
3 import os;
4 import dircache;
5 import sys;
6
7 os.chdir(sys.argv[1])
8
9 class Axis:
10     def __init__(self, atype):
11         self.type = atype
12         self.values = dircache.listdir('by-%s'%atype)
13
14     def __str__(self):
15         if self.type == "kern": return "kernel"
16         elif self.type == "clck": return "CPU clock"
17         elif self.type == "test": return "test"
18         else: raise Exception, "Unknown type"
19
20     def __iter__(self):
21         return iter(self.values)
22
23     def __getitem__(self, key):
24         return self.values[key]
25
26     def getLabel(self, v):
27         if self.type == "clck": return v+" MHz"
28         elif self.type == "test": return "<a href='%s.sh.html'>%s</a>"%(v, v)
29         else: return v
30
31
32     def labels(self):
33         for v in self.values:
34             yield self.getLabel(v)
35         
36 kernels = Axis('kern')
37 clocks = Axis('clck')
38 tests = Axis('test')
39
40 class PageSet:
41     def __init__(self, values, x, y):
42         self.values = values
43         self.x = x
44         self.y = y
45
46     def getPages(self):
47         for v in self.values:
48             yield Page(self.values.type, str(self.values), v, self.x, self.y)
49
50 class Page:
51     def __init__(self, prefix, name, value, xvals, yvals):
52         self.prefix = prefix
53         self.name = name
54         self.value = value
55         self.xvals = xvals
56         self.yvals = yvals
57                  
58     def generate(self, pagesets):
59         html = open("%s-%s.html"%(self.prefix, self.value), "w")
60         print >> html, """<html>
61 <head>
62 <title>CAN driver benchmark for %s %s</title>
63 <style>
64 img { border: 0; }
65 table { border-collapse: collapse; }
66 td { border: 1px solid lightgray; padding: 4px;}
67 </style>
68 </head>
69 <body>
70 <h1>CAN driver benchmark for %s %s</h1>"""  % (self.name, self.value, self.name, self.value)
71         for ps in pagesets:
72             print >>html, "View by %s: " % str(ps.values)
73             for v in ps.values:
74                 print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, v, v)
75             print >>html, "<br>"
76         print >>html, "<table><thead><tr><td> </td>"
77         for x in self.xvals.labels():
78             print >>html, "<td>%s</td>" % x
79         print >>html, "</tr></thead>"
80         for y in self.yvals:
81             print >>html, "<tr><td>%s</td>" % self.yvals.getLabel(y)
82
83             for x in self.xvals:
84                 print >>html, "<td>"
85                 d="by-%s/%s/%s/%s/" % (self.prefix, self.value, y, x)
86                 dthumb = d+"thumb"
87                 try:
88                     for img in dircache.listdir(dthumb):
89                         print >>html, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % (d, img, d, img)
90                 except OSError:
91                     print "error"
92                     print >>html, "</td>"
93                     print >>html, "</tr>"
94                     print >> html, """
95 </table>
96 </body>
97 """
98
99
100 pagesets = [ PageSet(kernels, clocks, tests),
101              PageSet(tests, clocks, kernels),
102              PageSet(clocks, kernels, tests)]
103
104 for ps in pagesets:
105     for p in ps.getPages():
106         p.generate(pagesets)
107
108 try:
109     os.remove("index.html")
110 except OSError: pass
111
112 os.symlink("%s-%s.html"%(kernels.type, kernels[0]), "index.html")
113
114 os.system("source-highlight -d --output-dir=. ../*.sh")
115     
116
117