]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - tests/genhtml.py
2c7aa8dae295f41d0b22a8fdaaebd777d3a4d83b
[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, values, x, y):
53         self.values = values
54         self.x = x
55         self.y = y
56
57     def getPages(self):
58         for v in self.values:
59             yield Page(self.values.type, str(self.values), v, self.x, self.y)
60
61 class Page:
62     def __init__(self, prefix, name, value, xvals, yvals):
63         self.prefix = prefix
64         self.name = name
65         self.value = value
66         self.xvals = xvals
67         self.yvals = yvals
68                  
69     def generate(self, pagesets):
70         html = open("%s-%s.html"%(self.prefix, self.value), "w")
71         print >> html, """<html>
72 <head>
73 <title>CAN driver benchmark for %s %s</title>
74 <style>
75 img { border: 0; }
76 table { border-collapse: collapse; }
77 td { border: 1px solid lightgray; padding: 4px;}
78 </style>
79 </head>
80 <body>
81 <h1>CAN driver benchmark for %s %s</h1>"""  % (self.name, self.value, self.name, self.value)
82         for ps in pagesets:
83             print >>html, "View only %s: " % str(ps.values)
84             for v in ps.values:
85                 print >>html, "<a href='%s-%s.html'>%s</a> | "%(ps.values.type, urllib.quote(v), v)
86             print >>html, "<br>"
87         print >>html, "<table><thead><tr><td> </td>"
88         for x in self.xvals.labels():
89             print >>html, "<th>%s</th>" % x
90         print >>html, "</tr></thead>"
91         for y in self.yvals:
92             print >>html, "<tr><td>%s</td>" % self.yvals.getLabel(y)
93
94             for x in self.xvals:
95                 print >>html, "<td>"
96                 d="by-%s/%s/%s/%s/" % (self.prefix, self.value, y, x)
97                 dthumb = d+"thumb"
98                 try:
99                     for img in dircache.listdir(dthumb):
100                         print >>html, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % (urllib.quote(d), img, urllib.quote(d), img)
101                 except OSError:
102                     print "warning: no images in %s?"%dthumb
103                 print >>html, "</td>"
104             print >>html, "</tr>"
105         print >> html, """
106 </table>
107 </body>
108 """
109
110
111 pagesets = [ PageSet(kernels, clocks, tests),
112              PageSet(tests, clocks, kernels),
113              PageSet(clocks, kernels, tests)]
114
115 for ps in pagesets:
116     for p in ps.getPages():
117         p.generate(pagesets)
118
119 try:
120     os.remove("index.html")
121 except OSError: pass
122
123 os.symlink("%s-%s.html"%(kernels.type, kernels[0]), "index.html")
124
125 os.system("source-highlight -d --output-dir=. ../*.sh")
126     
127
128