2 # -*- coding: utf-8 -*-
10 class DimValue(object):
11 def __new__(cls, dim, value):
15 return super(DimValue, cls).__new__(cls)
16 def __init__(self, dim, value):
19 self.dim.addValue(self)
21 return self.dim.val2str(self.value)
23 return "DimValue(%s, %s)" % (repr(self.dim), repr(self.value))
24 def htmlTableHeading(self):
25 return self.dim.htmlTableHeading(self.value)
27 return self.dim.sortedKeys.index(self.value)
29 class DimValues(list):
30 def replace(self, val):
31 for i in xrange(len(self)):
32 if self[i].dim == val.dim:
34 def __add__(self, val):
38 def __sub__(self, dim):
39 result = DimValues(self)
45 return tuple([v.value for v in self])
47 class Dimension(dict):
48 def __init__(self, atype, name=None):
57 for i in xrange(len(self)):
58 yield self.getValue(i)
59 def getValue(self, index):
60 return self[self.sortedKeys[index]]
62 def addValue(self, value):
64 if isinstance(value, DimValue):
65 self[value.value] = value
67 raise Exception("Unsupported usage of addValue")
68 #self[value] = DimValue(self, value)
69 self.sortedKeys = self.keys()
70 self.sortedKeys.sort()
73 def htmlTableHeading(self, v):
74 return self.val2str(v)
78 return "Dimension(%s)"%self.type
80 class DimensionKern(Dimension):
82 Dimension.__init__(self, 'gwkern', 'GW kernel')
83 def htmlTableHeading(self, v):
87 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
95 class DimensionHostKern(Dimension):
97 Dimension.__init__(self, 'hostkern', 'Host kernel')
99 if v.find("host-") == 0:
102 def htmlTableHeading(self, v):
107 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
109 for v in self.values:
115 class DimensionTest(Dimension):
117 Dimension.__init__(self, 'test', 'Test')
118 def htmlTableHeading(self, v):
119 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
121 class DimensionLoad(Dimension):
123 Dimension.__init__(self, 'load', 'Load')
125 class DimensionTraffic(Dimension):
127 Dimension.__init__(self, 'traf', 'Traffic')
128 def val2str(self, v):
131 elif v == "oneatatime":
132 return "one message at a time"
135 def htmlTableHeading(self, v):
136 return self.val2str(v)
139 def isOnPath(cls, path):
140 f = os.path.join(path, 'plot.sh')
141 return os.path.isfile(f)
142 def __init__(self, path, values, tests=None):
144 self.name = os.path.basename(path)
147 def printThumbLink(self, file):
149 # imgs = [img for img in dircache.listdir(thumb)]
151 # imgs = [ self.name + ".png" ]
152 imgs = [ 'tgraph.png' ]
154 print >>file, "<a href='%s/results.html'><img src='%s/%s'></a>" % \
155 (urllib.quote(self.path), urllib.quote(self.path), img)
156 def fullImgLink(self, pngName):
157 return "<div><a href='%s'><img src='%s' /></a></div>" % \
158 (pngName[:-4]+".pdf", pngName)
160 def htmlPrintStats(self, html):
163 stats = glob.glob("*-stat.txt")
164 print >>html, "<h3>Statistics</h3>"
165 print >>html, "<table><tr>"
168 lines = open(i).readlines()
170 comment = l.find("#")
173 if l.find("cmdline=") == 0:
174 l = "<abbr title=%s>cmdline=...</abbr>" % str(l[8:])
176 lines = [fixupLine(l) for l in lines]
177 print >>html, "<td><h4>%s</h4>%s</td>" % (i, "<br />".join(lines))
178 print >>html, "</tr></table>"
181 def generateHtml(self):
182 html = open(os.path.join(self.path, 'results.html'), "w")
183 title = "CAN gateway timing analysis"
184 cdup = "../"*len(self.values)
185 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
186 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
188 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
190 <link rel="stylesheet" href="%sstyle.css" type="text/css" />
193 <h1>%s</h1>""" % (title, cdup, title)
194 params = ["%s %s" % (v.dim, v) for v in self.values]
195 print >>html, "Results for:", ", ".join(params)
196 print >>html, "<div class='otherview'><h4>Other results</h4><table>"
197 for d in self.tests.space:
201 links.append("<span class='value current'>%s</span>"%str(v))
203 vv = DimValues(self.values)
206 href = cdup + urllib.quote(self.tests[vv.key()].path+"/results.html")
207 links.append("<span class='value other'><a href='%s'>%s</a></span>"%(href, str(v)))
209 links.append("<span class='value missing'>%s</span>"%str(v))
210 print >>html, "<tr><th>%s</th><td>" % d, " ".join(links), "</td></tr>"
212 print >>html, "</table></div>"
213 print >>html, self.fullImgLink("graph.png")
214 self.htmlPrintStats(html)
217 additionalImgs = glob.glob("graph?*.png")
218 if additionalImgs: print >>html, "<h3>Additional graphs</h3>"
219 for i in additionalImgs:
220 print >>html, "<h4>%s</h4>" % i[5:-4]
221 print >>html, self.fullImgLink(i)
224 print >>html, "<hr />"
225 print >>html, "<a href='./'>Raw data</a><br />"
226 print >>html, "<a href='%s'>Script source</a><br />" % (cdup+self.name+".sh.html")
227 print >>html, "<a href='%s'>Back to top</a><br />" % cdup
232 """List of Dimensions()s (order matters)"""
233 def __init__(self, *dimensions):
234 self.extend(list(dimensions))
235 def path2dimValues(self, path):
236 coordinates = path.split("/")
237 if len(coordinates) != len(self):
238 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
240 dv = DimValues([DimValue(self[i], coordinates[i]) \
241 for i in xrange(len(coordinates))])
244 def iterValues(self):
245 idx = [0 for i in xrange(len(self))]
249 for i in xrange(len(self)):
250 values.append(self[i].values()[idx[i]])
253 for i in xrange(len(self)):
255 if idx[i] < len(self[i]):
259 def reorder(self, dimValues):
260 reordered = DimValues()
266 def iterDimensionPairs(self):
267 for i in xrange(len(self)):
268 for j in xrange(i+1, len(self)):
269 yield (self[i], self[j])
270 yield (self[j], self[i])
271 def iterRemainingDimensions(self, dimensionPair):
273 if d not in dimensionPair:
278 """Represents all tests organized along several dimensions"""
279 def __init__(self, rootpath, space):
283 self.populate(rootpath)
284 def getTest(self, key):
285 if len(key) != len(self.space):
286 raise KeyError("The coordinates in key do not match the dimension of the space")
287 realkey = self.space.reorder(key)
288 return self[realkey.key()]
290 def addTest(self, test):
291 self[test.values.key()] = test
293 def populate(self, rootpath):
294 for root, dirs, files in os.walk(rootpath):
295 if (root.find(rootpath) == 0):
296 path = root[len(rootpath):]
299 if Test.isOnPath(root):
300 dv = self.space.path2dimValues(path)
301 self.addTest(Test(root, dv, self))
302 def generateHtml(self):
303 for pair in self.space.iterDimensionPairs():
304 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
305 for vals in remDims.iterValues():
306 page = Page(pair, vals, self)
310 os.remove("index.html")
312 os.symlink(page.getName(), "index.html")
313 css = open("style.css", "w")
314 print >>css, """img { border: 0; }
315 table { border-collapse: collapse; }
316 th, td { border: 1px solid lightgray; padding: 4px;}
318 .otherview { margin: 1ex 0}
319 .otherview .value { color: black; padding: 0ex 1ex; -moz-border-radius: 1ex; border-radius: 1ex;}
320 .otherview .value a { color: inherit; text-decoration: none; }
321 .otherview .other:hover { background: #eee; }
322 .otherview .missing { color: gray; }
323 .otherview .current { background: #ccc; }
326 for test in self.values():
330 os.system("source-highlight -d --output-dir=. ../*.sh > /dev/null")
333 def __init__(self, dimPair, valsOther, tests):
334 self.dimy, self.dimx = dimPair
335 self.dimOther = [v.dim for v in valsOther]
336 self.valsOther = tests.space.reorder(valsOther)
339 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
340 "-".join(["%02d"%v.index() for v in self.valsOther]))
342 html = open(self.getName(), "w")
343 title = "CAN gateway timing analysis"
344 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
345 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
347 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
349 <link rel="stylesheet" href="style.css" type="text/css" />
352 <h1>%s</h1>""" % (title, title)
353 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
354 print >>html, "<h3>Results for ", ", ".join(params), "</h3>"
355 print >>html, "<div class='otherview'><h4>Other views</h4>"
356 print >>html, "<table><tr>"
357 for d in self.dimOther:
358 print >>html, "<th>%s</th>" % d
359 print >>html, "<td><a href='%s'>→</a> " % \
360 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
361 print >>html, "<a href='%s'>↓</a></td>" % \
362 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
366 if v in self.valsOther:
367 links.append("<span class='value current'>%s</span>"%str(v))
369 vv = DimValues(self.valsOther)
371 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)))
372 print >>html, " ".join(links)
373 print >>html, "</td></tr>"
374 print >>html, "</table></div>"
376 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
378 print >>html, "<th>%s</th>" % x.htmlTableHeading()
379 print >>html, "</tr></thead>"
381 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
386 idx.extend(self.valsOther)
388 test = tests.getTest(idx)
389 test.printThumbLink(html)
392 print >>html, "</td>"
393 print >>html, "</tr>"
396 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
401 if __name__ == "__main__":
402 os.chdir(sys.argv[1])
403 os.system("rm *.html")
404 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionLoad(), DimensionTest()))