2 # -*- coding: utf-8 -*-
9 class DimValue(object):
10 def __new__(cls, dim, value):
14 return super(DimValue, cls).__new__(cls, dim, value)
15 def __init__(self, dim, value):
18 self.dim.addValue(self)
20 return self.dim.val2str(self.value)
22 return "DimValue(%s, %s)" % (repr(self.dim), repr(self.value))
23 def htmlTableHeading(self):
24 return self.dim.htmlTableHeading(self.value)
26 class DimValues(list):
27 def replace(self, val):
28 for i in xrange(len(self)):
29 if self[i].dim == val.dim:
31 def __add__(self, val):
35 def __sub__(self, dim):
36 result = DimValues(self)
42 return tuple([v.value for v in self])
44 class Dimension(dict):
45 def __init__(self, atype, name=None):
54 for i in xrange(len(self)):
55 yield self.getValue(i)
56 def getValue(self, index):
57 return self[self.sortedKeys[index]]
59 def addValue(self, value):
61 if isinstance(value, DimValue):
62 self[value.value] = value
64 raise Exception("Unsupported usage of addValue")
65 #self[value] = DimValue(self, value)
66 self.sortedKeys = self.keys()
67 self.sortedKeys.sort()
70 def htmlTableHeading(self, v):
71 return self.val2str(v)
75 return "Dimension(%s)"%self.type
77 class DimensionKern(Dimension):
79 Dimension.__init__(self, 'gwkern', 'GW kernel')
80 def htmlTableHeading(self, v):
84 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
92 class DimensionHostKern(Dimension):
94 Dimension.__init__(self, 'hostkern', 'Host kernel')
96 if v.find("host-") == 0:
99 def htmlTableHeading(self, v):
104 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
106 for v in self.values:
112 class DimensionTest(Dimension):
114 Dimension.__init__(self, 'test', 'Test')
115 def htmlTableHeading(self, v):
116 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
118 class DimensionLoad(Dimension):
120 Dimension.__init__(self, 'load', 'Load')
122 class DimensionTraffic(Dimension):
124 Dimension.__init__(self, 'traf', 'Traffic')
125 def val2str(self, v):
128 elif v == "oneatatime":
129 return "one message at a time"
132 def htmlTableHeading(self, v):
133 return self.val2str(v)
136 def isOnPath(cls, path):
137 f = os.path.join(path, '.results')
138 return os.path.isfile(f)
139 def __init__(self, path, values, tests=None):
141 self.name = os.path.basename(path)
144 def printThumbLink(self, file):
145 thumb = self.path+'/thumb'
147 imgs = [img for img in dircache.listdir(thumb)]
149 imgs = [ self.name + ".png" ]
151 print >>file, "<a href='%s/results.html'><img src='%s/thumb/%s'></a>" % \
152 (urllib.quote(self.path), urllib.quote(self.path), img)
153 def generateHtml(self):
154 html = open(os.path.join(self.path, 'results.html'), "w")
155 title = "CAN gateway timing analysis"
156 cdup = "../"*len(self.values)
157 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
158 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
160 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
162 <link rel="stylesheet" href="%sstyle.css" type="text/css" />
165 <h1>%s</h1>""" % (title, cdup, title)
166 params = ["%s %s" % (v.dim, v) for v in self.values]
167 print >>html, "Results for:", ", ".join(params)
168 print >>html, "<div class='otherview'><h4>Other results</h4><table>"
169 for d in self.tests.space:
173 links.append("<span class='value current'>%s</span>"%str(v))
175 vv = DimValues(self.values)
178 href = cdup + urllib.quote(self.tests[vv.key()].path+"/results.html")
179 links.append("<span class='value other'><a href='%s'>%s</a></span>"%(href, str(v)))
181 links.append("<span class='value missing'>%s</span>"%str(v))
182 print >>html, "<tr><th>%s</th><td>" % d, " ".join(links), "</td></tr>"
184 print >>html, "</table></div>"
185 print >>html, "<div><img src='%s' /></div>" % (self.name+".png")
186 print >>html, "<a href='./'>Raw data</a><br />"
187 print >>html, "<a href='%s'>Script source</a><br />" % (cdup+self.name+".sh.html")
188 print >>html, "<a href='%s'>Back to top</a><br />" % cdup
193 """List of Dimensions()s (order matters)"""
194 def __init__(self, *dimensions):
195 self.extend(list(dimensions))
196 def path2dimValues(self, path):
197 coordinates = path.split("/")
198 if len(coordinates) != len(self):
199 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
201 dv = DimValues([DimValue(self[i], coordinates[i]) \
202 for i in xrange(len(coordinates))])
205 def iterValues(self):
206 idx = [0 for i in xrange(len(self))]
210 for i in xrange(len(self)):
211 values.append(self[i].values()[idx[i]])
214 for i in xrange(len(self)):
216 if idx[i] < len(self[i]):
220 def reorder(self, dimValues):
221 reordered = DimValues()
227 def iterDimensionPairs(self):
228 for i in xrange(len(self)):
229 for j in xrange(i+1, len(self)):
230 yield (self[i], self[j])
231 yield (self[j], self[i])
232 def iterRemainingDimensions(self, dimensionPair):
234 if d not in dimensionPair:
239 """Represents all tests organized along several dimensions"""
240 def __init__(self, rootpath, space):
244 self.populate(rootpath)
245 def getTest(self, key):
246 if len(key) != len(self.space):
247 raise KeyError("The coordinates in key do not match the dimension of the space")
248 realkey = self.space.reorder(key)
249 return self[realkey.key()]
251 def addTest(self, test):
252 self[test.values.key()] = test
254 def populate(self, rootpath):
255 for root, dirs, files in os.walk(rootpath):
256 if (root.find(rootpath) == 0):
257 path = root[len(rootpath):]
260 if Test.isOnPath(root):
261 dv = self.space.path2dimValues(path)
262 self.addTest(Test(root, dv, self))
263 def generateHtml(self):
264 for pair in self.space.iterDimensionPairs():
265 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
266 for vals in remDims.iterValues():
267 page = Page(pair, vals, self)
271 os.remove("index.html")
273 os.symlink(page.getName(), "index.html")
274 css = open("style.css", "w")
275 print >>css, """img { border: 0; }
276 table { border-collapse: collapse; }
277 th, td { border: 1px solid lightgray; padding: 4px;}
279 .otherview { margin: 1ex 0}
280 .otherview .value { color: black; padding: 0ex 1ex; -moz-border-radius: 1ex; border-radius: 1ex;}
281 .otherview .value a { color: inherit; text-decoration: none; }
282 .otherview .other:hover { background: #eee; }
283 .otherview .missing { color: gray; }
284 .otherview .current { background: #ccc; }
287 for test in self.values():
291 os.system("source-highlight -d --output-dir=. ../*.sh > /dev/null")
294 def __init__(self, dimPair, valsOther, tests):
295 self.dimy, self.dimx = dimPair
296 self.dimOther = [v.dim for v in valsOther]
297 self.valsOther = tests.space.reorder(valsOther)
300 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
301 "-".join([v.value for v in self.valsOther]))
303 html = open(self.getName(), "w")
304 title = "CAN gateway timing analysis"
305 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
306 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
308 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
310 <link rel="stylesheet" href="style.css" type="text/css" />
313 <h1>%s</h1>""" % (title, title)
314 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
315 print >>html, "<h3>Results for ", ", ".join(params), "</h3>"
316 print >>html, "<div class='otherview'><h4>Other views</h4>"
317 print >>html, "<table><tr>"
318 for d in self.dimOther:
319 print >>html, "<th>%s</th>" % d
320 print >>html, "<td><a href='%s'>→</a> " % \
321 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
322 print >>html, "<a href='%s'>↓</a></td>" % \
323 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
327 if v in self.valsOther:
328 links.append("<span class='value current'>%s</span>"%str(v))
330 vv = DimValues(self.valsOther)
332 links.append("<span class='value other'><a href='%s'>%s</a></span>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
333 print >>html, " ".join(links)
334 print >>html, "</td></tr>"
335 print >>html, "</table></div>"
337 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
339 print >>html, "<th>%s</th>" % x.htmlTableHeading()
340 print >>html, "</tr></thead>"
342 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
347 idx.extend(self.valsOther)
349 test = tests.getTest(idx)
350 test.printThumbLink(html)
353 print >>html, "</td>"
354 print >>html, "</tr>"
357 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
362 if __name__ == "__main__":
363 os.chdir(sys.argv[1])
364 os.system("rm *.html")
365 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionLoad(), DimensionTest()))