]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - tests/genhtml.py
cfd39071470f05fd98b465bd23549374689653b7
[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     
34
35 class AxisClck(Axis):
36     def __init__(self):
37         Axis.__init__(self, 'clck')
38     def getLabel(self, v):
39         return v+" MHz"
40
41 class AxisTest(Axis):
42     def __init__(self):
43         Axis.__init__(self, 'test')
44     def getLabel(self, v):
45         return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
46     
47 kernels = AxisKern()
48 clocks =  AxisClck()
49 tests =   AxisTest()
50
51 class PageSet:
52     def __init__(self, pageclass, values, x, y):
53         self.pageclass = pageclass
54         self.values = values
55         self.x = x
56         self.y = y
57
58     def getPages(self):
59         for v in self.values:
60             yield self.pageclass(v, self.x, self.y)
61
62 class Page:
63     def __init__(self, value, xvals, yvals):
64         self.value = value
65         self.xvals = xvals
66         self.yvals = yvals
67                  
68     def generate(self, pagesets):
69         html = open("%s-%s.html"%(self.prefix, self.value), "w")
70         print >> html, """<html>
71 <head>
72 <title>CAN driver benchmark for %s %s</title>
73 <style>
74 img { border: 0; }
75 table { border-collapse: collapse; }
76 th, td { border: 1px solid lightgray; padding: 4px;}
77 </style>
78 </head>
79 <body>
80 <h1>CAN driver benchmark for %s %s</h1>"""  % (self.name, self.value, self.name, self.value)
81         for ps in pagesets:
82             print >>html, "View only %s: " % str(ps.pageclass.name)
83             for v in ps.values:
84                 print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, urllib.quote(v), v)
85             print >>html, "<br>"
86         try:
87             print >>html, self.getPreambule()
88         except Exception:
89             pass
90         print >>html, "<table><thead><tr><td> </td>"
91         for x in self.xvals.labels():
92             print >>html, "<th>%s</th>" % x
93         print >>html, "</tr></thead>"
94         for y in self.yvals:
95             print >>html, "<tr><th>%s</th>" % self.yvals.getLabel(y)
96
97             for x in self.xvals:
98                 print >>html, "<td>"
99                 d="by-%s/%s/%s/%s/" % (self.prefix, self.value, y, x)
100                 dthumb = d+"thumb"
101                 try:
102                     for img in dircache.listdir(dthumb):
103                         print >>html, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % (urllib.quote(d), img, urllib.quote(d), img)
104                 except OSError:
105                     print "warning: no images in %s?"%dthumb
106                 print >>html, "</td>"
107             print >>html, "</tr>"
108         print >> html, """
109 </table>
110 </body>
111 """
112
113 class PageKern(Page):
114     prefix = 'kern'
115     name = 'kernel'
116     def __init__(self, value, xvals, yvals):
117         Page.__init__(self, value, xvals, yvals)
118     def getPreambule(self):
119         i=self.value.find(":")
120         if i>0: kver=self.value[:i]
121         else: kver=self.value
122         return "<p><a href='config-%s'>Kernel config</a></p>"%kver
123
124 class PageClck(Page):
125     prefix = 'clck'
126     name = 'CPU clock'
127     def __init__(self, value, xvals, yvals):
128         Page.__init__(self, value, xvals, yvals)
129
130 class PageTest(Page):
131     prefix = 'test'
132     name = 'test'
133     def __init__(self, value, xvals, yvals):
134         Page.__init__(self, value, xvals, yvals)
135     def getPreambule(self):
136         return "<p><a href='%s.sh.html'>Test source</a></p>"%(urllib.quote(self.value))
137
138
139
140 pagesets = [ PageSet(PageKern, kernels, clocks, tests),
141              PageSet(PageTest, tests, clocks, kernels),
142              PageSet(PageClck, clocks, kernels, tests)]
143
144 for ps in pagesets:
145     for p in ps.getPages():
146         p.generate(pagesets)
147
148 try:
149     os.remove("index.html")
150 except OSError: pass
151
152 os.symlink("%s-%s.html"%(kernels.type, kernels[0]), "index.html")
153
154 os.system("source-highlight -d --output-dir=. ../*.sh")
155     
156
157