2 # -*- coding: utf-8 -*-
9 def __init__(self, dim, value):
12 self.dim.addValue(self)
14 return self.dim.val2str(self.value)
16 return "DimValue(%s, %s)" % (repr(self.dim), repr(self.value))
17 def htmlTableHeading(self):
18 return self.dim.htmlTableHeading(self.value)
20 class DimValues(list):
21 def replace(self, val):
22 for i in xrange(len(self)):
23 if self[i].dim == val.dim:
25 def __add__(self, val):
29 def __sub__(self, dim):
30 result = DimValues(self)
36 return tuple([v.value for v in self])
38 class Dimension(dict):
39 def __init__(self, atype, name=None):
48 for i in xrange(len(self)):
49 yield self.getValue(i)
50 def getValue(self, index):
51 return self[self.sortedKeys[index]]
53 def addValue(self, *values):
56 if isinstance(value, DimValue):
57 self[value.value] = value
59 raise Exception("Unsupported usage of addValue")
60 #self[value] = DimValue(self, value)
61 self.sortedKeys = self.keys()
62 self.sortedKeys.sort()
65 def htmlTableHeading(self, v):
66 return self.val2str(v)
70 return "Dimension(%s)"%self.type
72 class DimensionKern(Dimension):
74 Dimension.__init__(self, 'gwkern', 'GW kernel')
75 def htmlTableHeading(self, v):
79 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
87 class DimensionHostKern(Dimension):
89 Dimension.__init__(self, 'hostkern', 'Host kernel')
91 if v.find("host-") == 0:
94 def htmlTableHeading(self, v):
99 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
101 for v in self.values:
107 class DimensionTest(Dimension):
109 Dimension.__init__(self, 'test', 'Test')
110 def htmlTableHeading(self, v):
111 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
113 class DimensionTraffic(Dimension):
115 Dimension.__init__(self, 'traf', 'Traffic')
116 def val2str(self, v):
119 elif v == "oneatatime":
120 return "one message at a time"
123 def htmlTableHeading(self, v):
124 return self.val2str(v)
127 def isOnPath(cls, path):
128 f = os.path.join(path, '.results')
129 return os.path.isfile(f)
130 def __init__(self, path, values):
132 self.name = os.path.basename(path)
134 def printThumbLink(self, file):
135 thumb = self.path+'/thumb'
137 imgs = [img for img in dircache.listdir(thumb)]
139 imgs = [ self.name + ".png" ]
141 print >>file, "<a href='%s/results.html'><img src='%s/thumb/%s'></a>" % \
142 (urllib.quote(self.path), urllib.quote(self.path), img)
143 def generateHtml(self):
144 html = open(os.path.join(path, 'results.html'), "w")
145 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
146 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
148 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
150 <link rel="stylesheet" href="style.css" type="text/css" />
153 <h1>%s</h1>""" % (title, title)
154 params = ["%s %s" % (v.dim, v) for v in self.vals]
155 print >>html, "Results for:", ", ".join(params), "<hr />"
156 for d in self.dimOther:
157 print >>html, "%s: " % d
158 print >>html, "<a href='%s'>X axis</a>, " % \
159 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
160 print >>html, "<a href='%s'>Y axis</a>; " % \
161 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
164 if v in self.valsOther:
167 vv = DimValues(self.valsOther)
169 links.append("<a href='%s'>%s</a>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
170 print >>html, " | ".join(links)
173 print >>html, d.htmlPreamble()
181 """List of Dimensions()s (order matters)"""
182 def __init__(self, *dimensions):
183 self.extend(list(dimensions))
184 def iterValues(self):
185 idx = [0 for i in xrange(len(self))]
189 for i in xrange(len(self)):
190 values.append(self[i].values()[idx[i]])
193 for i in xrange(len(self)):
195 if idx[i] < len(self[i]):
199 def reorder(self, dimValues):
200 reordered = DimValues()
206 def iterDimensionPairs(self):
207 for i in xrange(len(self)):
208 for j in xrange(i+1, len(self)):
209 yield (self[i], self[j])
210 yield (self[j], self[i])
211 def iterRemainingDimensions(self, dimensionPair):
213 if d not in dimensionPair:
218 """Represents all tests organized along several dimensions"""
219 def __init__(self, rootpath, space):
223 self.populate(rootpath)
224 def getTest(self, key):
225 if len(key) != len(self.space):
226 raise KeyError("The coordinates in key do not match the dimension of the space")
227 realkey = self.space.reorder(key)
228 return self[realkey.key()]
230 def addTest(self, test):
231 self[test.values.key()] = test
233 def populate(self, rootpath):
234 for root, dirs, files in os.walk(rootpath):
235 if (root.find(rootpath) == 0):
236 coordinates = root[len(rootpath):].split("/")
238 coordinates = rootpath.split("/")
239 if Test.isOnPath(root):
240 if len(coordinates) != len(self.space):
241 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
242 dv = DimValues([DimValue(self.space[i], coordinates[i]) for i in xrange(len(coordinates))])
243 self.addTest(Test(root, dv))
244 def generateHtml(self):
245 for pair in self.space.iterDimensionPairs():
246 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
247 for vals in remDims.iterValues():
248 page = Page(pair, vals, self)
251 os.remove("index.html")
253 os.symlink(page.getName(), "index.html")
254 css = open("style.css", "w")
255 print >>css, """img { border: 0; }
256 table { border-collapse: collapse; }
257 th, td { border: 1px solid lightgray; padding: 4px;}
259 .box { border: 1px solid black; padding: 1ex; margin: 1ex 0}
263 #os.system("source-highlight -d --output-dir=. ../*.sh")
266 def __init__(self, dimPair, valsOther, tests):
267 self.dimy, self.dimx = dimPair
268 self.dimOther = [v.dim for v in valsOther]
269 self.valsOther = tests.space.reorder(valsOther)
272 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
273 "-".join([v.value for v in self.valsOther]))
275 html = open(self.getName(), "w")
276 title = "CAN gateway timing analysis"
277 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
278 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
280 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
282 <link rel="stylesheet" href="style.css" type="text/css" />
285 <h1>%s</h1>""" % (title, title)
286 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
287 print >>html, "<h3>Results for ", ", ".join(params), "</h3>"
288 print >>html, "<div class='box'><h4>Other views</h4>"
289 for d in self.dimOther:
290 print >>html, "%s: " % d
291 print >>html, "<a href='%s'>X axis</a>, " % \
292 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
293 print >>html, "<a href='%s'>Y axis</a>; " % \
294 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
297 if v in self.valsOther:
300 vv = DimValues(self.valsOther)
302 links.append("<a href='%s'>%s</a>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
303 print >>html, " | ".join(links)
306 print >>html, d.htmlPreamble()
309 print >>html, "</div>"
311 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
313 print >>html, "<th>%s</th>" % x.htmlTableHeading()
314 print >>html, "</tr></thead>"
316 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
321 idx.extend(self.valsOther)
323 test = tests.getTest(idx)
324 test.printThumbLink(html)
327 print >>html, "</td>"
328 print >>html, "</tr>"
331 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
336 if __name__ == "__main__":
337 os.chdir(sys.argv[1])
338 os.system("rm *.html")
339 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest()))