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 class DimValues(list):
28 def replace(self, val):
29 for i in xrange(len(self)):
30 if self[i].dim == val.dim:
32 def __add__(self, val):
36 def __sub__(self, dim):
37 result = DimValues(self)
43 return tuple([v.value for v in self])
45 class Dimension(dict):
46 def __init__(self, atype, name=None):
55 for i in xrange(len(self)):
56 yield self.getValue(i)
57 def getValue(self, index):
58 return self[self.sortedKeys[index]]
60 def addValue(self, value):
62 if isinstance(value, DimValue):
63 self[value.value] = value
65 raise Exception("Unsupported usage of addValue")
66 #self[value] = DimValue(self, value)
67 self.sortedKeys = self.keys()
68 self.sortedKeys.sort()
71 def htmlTableHeading(self, v):
72 return self.val2str(v)
76 return "Dimension(%s)"%self.type
78 class DimensionKern(Dimension):
80 Dimension.__init__(self, 'gwkern', 'GW kernel')
81 def htmlTableHeading(self, v):
85 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
93 class DimensionHostKern(Dimension):
95 Dimension.__init__(self, 'hostkern', 'Host kernel')
97 if v.find("host-") == 0:
100 def htmlTableHeading(self, v):
105 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
107 for v in self.values:
113 class DimensionTest(Dimension):
115 Dimension.__init__(self, 'test', 'Test')
116 def htmlTableHeading(self, v):
117 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
119 class DimensionLoad(Dimension):
121 Dimension.__init__(self, 'load', 'Load')
123 class DimensionTraffic(Dimension):
125 Dimension.__init__(self, 'traf', 'Traffic')
126 def val2str(self, v):
129 elif v == "oneatatime":
130 return "one message at a time"
133 def htmlTableHeading(self, v):
134 return self.val2str(v)
137 def isOnPath(cls, path):
138 f = os.path.join(path, 'plot.sh')
139 return os.path.isfile(f)
140 def __init__(self, path, values, tests=None):
142 self.name = os.path.basename(path)
145 def printThumbLink(self, file):
147 # imgs = [img for img in dircache.listdir(thumb)]
149 # imgs = [ self.name + ".png" ]
150 imgs = [ 'tgraph.png' ]
152 print >>file, "<a href='%s/results.html'><img src='%s/%s'></a>" % \
153 (urllib.quote(self.path), urllib.quote(self.path), img)
154 def fullImgLink(self, pngName):
155 return "<div><a href='%s'><img src='%s' /></a></div>" % \
156 (pngName[:-4]+".pdf", pngName)
158 def htmlPrintStats(self, html):
161 stats = glob.glob("*-stat.txt")
162 print >>html, "<h3>Statistics</h3>"
163 print >>html, "<table><tr>"
166 lines = open(i).readlines()
168 comment = l.find("#")
171 if l.find("cmdline=") == 0:
173 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, self.fullImgLink(i)
223 print >>html, "<hr />"
224 print >>html, "<a href='./'>Raw data</a><br />"
225 print >>html, "<a href='%s'>Script source</a><br />" % (cdup+self.name+".sh.html")
226 print >>html, "<a href='%s'>Back to top</a><br />" % cdup
231 """List of Dimensions()s (order matters)"""
232 def __init__(self, *dimensions):
233 self.extend(list(dimensions))
234 def path2dimValues(self, path):
235 coordinates = path.split("/")
236 if len(coordinates) != len(self):
237 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
239 dv = DimValues([DimValue(self[i], coordinates[i]) \
240 for i in xrange(len(coordinates))])
243 def iterValues(self):
244 idx = [0 for i in xrange(len(self))]
248 for i in xrange(len(self)):
249 values.append(self[i].values()[idx[i]])
252 for i in xrange(len(self)):
254 if idx[i] < len(self[i]):
258 def reorder(self, dimValues):
259 reordered = DimValues()
265 def iterDimensionPairs(self):
266 for i in xrange(len(self)):
267 for j in xrange(i+1, len(self)):
268 yield (self[i], self[j])
269 yield (self[j], self[i])
270 def iterRemainingDimensions(self, dimensionPair):
272 if d not in dimensionPair:
277 """Represents all tests organized along several dimensions"""
278 def __init__(self, rootpath, space):
282 self.populate(rootpath)
283 def getTest(self, key):
284 if len(key) != len(self.space):
285 raise KeyError("The coordinates in key do not match the dimension of the space")
286 realkey = self.space.reorder(key)
287 return self[realkey.key()]
289 def addTest(self, test):
290 self[test.values.key()] = test
292 def populate(self, rootpath):
293 for root, dirs, files in os.walk(rootpath):
294 if (root.find(rootpath) == 0):
295 path = root[len(rootpath):]
298 if Test.isOnPath(root):
299 dv = self.space.path2dimValues(path)
300 self.addTest(Test(root, dv, self))
301 def generateHtml(self):
302 for pair in self.space.iterDimensionPairs():
303 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
304 for vals in remDims.iterValues():
305 page = Page(pair, vals, self)
309 os.remove("index.html")
311 os.symlink(page.getName(), "index.html")
312 css = open("style.css", "w")
313 print >>css, """img { border: 0; }
314 table { border-collapse: collapse; }
315 th, td { border: 1px solid lightgray; padding: 4px;}
317 .otherview { margin: 1ex 0}
318 .otherview .value { color: black; padding: 0ex 1ex; -moz-border-radius: 1ex; border-radius: 1ex;}
319 .otherview .value a { color: inherit; text-decoration: none; }
320 .otherview .other:hover { background: #eee; }
321 .otherview .missing { color: gray; }
322 .otherview .current { background: #ccc; }
325 for test in self.values():
329 os.system("source-highlight -d --output-dir=. ../*.sh > /dev/null")
332 def __init__(self, dimPair, valsOther, tests):
333 self.dimy, self.dimx = dimPair
334 self.dimOther = [v.dim for v in valsOther]
335 self.valsOther = tests.space.reorder(valsOther)
338 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
339 "-".join([v.value for v in self.valsOther]))
341 html = open(self.getName(), "w")
342 title = "CAN gateway timing analysis"
343 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
344 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
346 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
348 <link rel="stylesheet" href="style.css" type="text/css" />
351 <h1>%s</h1>""" % (title, title)
352 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
353 print >>html, "<h3>Results for ", ", ".join(params), "</h3>"
354 print >>html, "<div class='otherview'><h4>Other views</h4>"
355 print >>html, "<table><tr>"
356 for d in self.dimOther:
357 print >>html, "<th>%s</th>" % d
358 print >>html, "<td><a href='%s'>→</a> " % \
359 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
360 print >>html, "<a href='%s'>↓</a></td>" % \
361 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
365 if v in self.valsOther:
366 links.append("<span class='value current'>%s</span>"%str(v))
368 vv = DimValues(self.valsOther)
370 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)))
371 print >>html, " ".join(links)
372 print >>html, "</td></tr>"
373 print >>html, "</table></div>"
375 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
377 print >>html, "<th>%s</th>" % x.htmlTableHeading()
378 print >>html, "</tr></thead>"
380 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
385 idx.extend(self.valsOther)
387 test = tests.getTest(idx)
388 test.printThumbLink(html)
391 print >>html, "</td>"
392 print >>html, "</tr>"
395 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
400 if __name__ == "__main__":
401 os.chdir(sys.argv[1])
402 os.system("rm *.html")
403 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionLoad(), DimensionTest()))