]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - tests/genhtml.py
run.pl redirects stdout rather than stderr in order to not loose error messages
[can-benchmark.git] / tests / genhtml.py
1 #!/usr/bin/env python
2
3 import os;
4 import dircache;
5 import sys;
6 import urllib
7
8 os.chdir(sys.argv[1])
9
10 class Axis:
11     def __init__(self, atype):
12         self.type = atype
13         self.values = dircache.listdir('by-%s'%atype)
14
15     def __iter__(self):
16         return iter(self.values)
17
18     def __getitem__(self, key):
19         return self.values[key]
20
21     def labels(self):
22         for v in self.values:
23             yield self.getLabel(v)
24
25 class AxisKern(Axis):
26     def __init__(self):
27         Axis.__init__(self, 'kern')
28     def getLabel(self, v):
29         i=v.find(":")
30         if i>0: kver=v[:i]
31         else: kver=v
32         return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
33     def versions(self):
34         for v in self.values:
35             i=v.find(":")
36             if i>0: kver=v[:i]
37             else: kver=v
38             yield kver
39         
40     
41
42 class AxisClck(Axis):
43     def __init__(self):
44         Axis.__init__(self, 'clck')
45     def getLabel(self, v):
46         return v+" MHz"
47
48 class AxisTest(Axis):
49     def __init__(self):
50         Axis.__init__(self, 'test')
51     def getLabel(self, v):
52         return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
53     
54 kernels = AxisKern()
55 clocks =  AxisClck()
56 tests =   AxisTest()
57
58 class PageSet:
59     def __init__(self, pageclass, values, x, y):
60         self.pageclass = pageclass
61         self.values = values
62         self.x = x
63         self.y = y
64
65     def getPages(self):
66         for v in self.values:
67             yield self.pageclass(v, self.x, self.y)
68
69 class Page:
70     def __init__(self, value, xvals, yvals):
71         self.value = value
72         self.xvals = xvals
73         self.yvals = yvals
74                  
75     def generate(self, pagesets):
76         html = open("%s-%s.html"%(self.prefix, self.value), "w")
77         print >> html, """<html>
78 <head>
79 <title>CAN driver benchmark for %s %s</title>
80 <style>
81 img { border: 0; }
82 table { border-collapse: collapse; }
83 th, td { border: 1px solid lightgray; padding: 4px;}
84 </style>
85 </head>
86 <body>
87 <h1>CAN driver benchmark for %s %s</h1>"""  % (self.name, self.value, self.name, self.value)
88         for ps in pagesets:
89             print >>html, "View only %s: " % str(ps.pageclass.name)
90             for v in ps.values:
91                 print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, urllib.quote(v), v)
92             print >>html, "<br>"
93         try:
94             print >>html, self.getPreambule()
95         except Exception:
96             pass
97         print >>html, "<table><thead><tr><td> </td>"
98         for x in self.xvals.labels():
99             print >>html, "<th>%s</th>" % x
100         print >>html, "</tr></thead>"
101         for y in self.yvals:
102             print >>html, "<tr><th>%s</th>" % self.yvals.getLabel(y)
103
104             for x in self.xvals:
105                 print >>html, "<td>"
106                 d="by-%s/%s/%s/%s/" % (self.prefix, self.value, y, x)
107                 dthumb = d+"thumb"
108                 try:
109                     for img in dircache.listdir(dthumb):
110                         print >>html, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % (urllib.quote(d), img, urllib.quote(d), img)
111                 except OSError:
112                     print "warning: no images in %s?"%dthumb
113                 print >>html, "</td>"
114             print >>html, "</tr>"
115         print >> html, """
116 </table>
117 </body>
118 """
119
120 class PageKern(Page):
121     prefix = 'kern'
122     name = 'kernel'
123     def __init__(self, value, xvals, yvals):
124         Page.__init__(self, value, xvals, yvals)
125     def getPreambule(self):
126         i=self.value.find(":")
127         if i>0: kver=self.value[:i]
128         else: kver=self.value
129         return "<p><a href='config-%s'>Kernel config</a></p>"%kver
130
131 class PageClck(Page):
132     prefix = 'clck'
133     name = 'CPU clock'
134     def __init__(self, value, xvals, yvals):
135         Page.__init__(self, value, xvals, yvals)
136
137 class PageTest(Page):
138     prefix = 'test'
139     name = 'test'
140     def __init__(self, value, xvals, yvals):
141         Page.__init__(self, value, xvals, yvals)
142     def getPreambule(self):
143         return "<p><a href='%s.sh.html'>Test source</a></p>"%(urllib.quote(self.value))
144
145
146
147 pagesets = [ PageSet(PageKern, kernels, clocks, tests),
148              PageSet(PageTest, tests, clocks, kernels),
149              PageSet(PageClck, clocks, kernels, tests)]
150
151 for ps in pagesets:
152     for p in ps.getPages():
153         p.generate(pagesets)
154
155 try:
156     os.remove("index.html")
157 except OSError: pass
158
159 os.symlink("%s-%s.html"%(clocks.type, clocks[0]), "index.html")
160
161 os.system("source-highlight -d --output-dir=. ../*.sh")
162     
163
164 for v in kernels.versions():
165     os.system("cp /boot/config-%s ."%v)