2 # -*- coding: utf-8 -*-
9 class DimValue(object):
10 def __new__(cls, dim, value):
16 return super(DimValue, cls).__new__(cls, dim, value)
17 def __init__(self, dim, value):
20 self.dim.addValue(self)
22 return self.dim.val2str(self.value)
24 return "DimValue(%s, %s)" % (repr(self.dim), repr(self.value))
25 def htmlTableHeading(self):
26 return self.dim.htmlTableHeading(self.value)
28 class DimValues(list):
29 def replace(self, val):
30 for i in xrange(len(self)):
31 if self[i].dim == val.dim:
33 def __add__(self, val):
37 def __sub__(self, dim):
38 result = DimValues(self)
44 return tuple([v.value for v in self])
46 class Dimension(dict):
47 def __init__(self, atype, name=None):
56 for i in xrange(len(self)):
57 yield self.getValue(i)
58 def getValue(self, index):
59 return self[self.sortedKeys[index]]
61 def addValue(self, value):
63 if isinstance(value, DimValue):
64 self[value.value] = value
66 raise Exception("Unsupported usage of addValue")
67 #self[value] = DimValue(self, value)
68 self.sortedKeys = self.keys()
69 self.sortedKeys.sort()
72 def htmlTableHeading(self, v):
73 return self.val2str(v)
77 return "Dimension(%s)"%self.type
79 class DimensionKern(Dimension):
81 Dimension.__init__(self, 'gwkern', 'GW kernel')
82 def htmlTableHeading(self, v):
86 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
94 class DimensionHostKern(Dimension):
96 Dimension.__init__(self, 'hostkern', 'Host kernel')
98 if v.find("host-") == 0:
101 def htmlTableHeading(self, v):
106 return v+"<br><a href='config-%s'>config</a>"%(urllib.quote(kver))
108 for v in self.values:
114 class DimensionTest(Dimension):
116 Dimension.__init__(self, 'test', 'Test')
117 def htmlTableHeading(self, v):
118 return v+"<br><a href='%s.sh.html'>source</a>"%(urllib.quote(v))
120 class DimensionTraffic(Dimension):
122 Dimension.__init__(self, 'traf', 'Traffic')
123 def val2str(self, v):
126 elif v == "oneatatime":
127 return "one message at a time"
130 def htmlTableHeading(self, v):
131 return self.val2str(v)
134 def isOnPath(cls, path):
135 f = os.path.join(path, '.results')
136 return os.path.isfile(f)
137 def __init__(self, path, values, tests=None):
139 self.name = os.path.basename(path)
142 def printThumbLink(self, file):
143 thumb = self.path+'/thumb'
145 imgs = [img for img in dircache.listdir(thumb)]
147 imgs = [ self.name + ".png" ]
149 print >>file, "<a href='%s/results.html'><img src='%s/thumb/%s'></a>" % \
150 (urllib.quote(self.path), urllib.quote(self.path), img)
151 def generateHtml(self):
152 html = open(os.path.join(self.path, 'results.html'), "w")
153 title = "CAN gateway timing analysis"
154 cdup = "../"*len(self.values)
155 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
156 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
158 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
160 <link rel="stylesheet" href="%sstyle.css" type="text/css" />
163 <h1>%s</h1>""" % (title, cdup, title)
164 params = ["%s %s" % (v.dim, v) for v in self.values]
165 print >>html, "Results for:", ", ".join(params)
166 print >>html, "<div class='box'><h4>Other results</h4>"
167 for d in self.tests.space:
174 vv = DimValues(self.values)
176 href = cdup + urllib.quote(self.tests[vv.key()].path+"/results.html")
177 links.append("<a href='%s'>%s</a>"%(href, str(v)))
178 print >>html, "%s: " % d, " | ".join(links), "<br>"
180 print >>html, "</div>"
181 print >>html, "<div><img src='%s' /></div>" % (self.name+".png")
182 print >>html, "<a href='./'>Raw data</a><br />"
183 print >>html, "<a href='%s'>Script source</a><br />" % (cdup+self.name+".sh.html")
184 print >>html, "<a href='%s'>Back to top</a><br />" % cdup
189 """List of Dimensions()s (order matters)"""
190 def __init__(self, *dimensions):
191 self.extend(list(dimensions))
192 def path2dimValues(self, path):
193 coordinates = path.split("/")
194 if len(coordinates) != len(self):
195 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
197 dv = DimValues([DimValue(self[i], coordinates[i]) \
198 for i in xrange(len(coordinates))])
201 def iterValues(self):
202 idx = [0 for i in xrange(len(self))]
206 for i in xrange(len(self)):
207 values.append(self[i].values()[idx[i]])
210 for i in xrange(len(self)):
212 if idx[i] < len(self[i]):
216 def reorder(self, dimValues):
217 reordered = DimValues()
223 def iterDimensionPairs(self):
224 for i in xrange(len(self)):
225 for j in xrange(i+1, len(self)):
226 yield (self[i], self[j])
227 yield (self[j], self[i])
228 def iterRemainingDimensions(self, dimensionPair):
230 if d not in dimensionPair:
235 """Represents all tests organized along several dimensions"""
236 def __init__(self, rootpath, space):
240 self.populate(rootpath)
241 def getTest(self, key):
242 if len(key) != len(self.space):
243 raise KeyError("The coordinates in key do not match the dimension of the space")
244 realkey = self.space.reorder(key)
245 return self[realkey.key()]
247 def addTest(self, test):
248 self[test.values.key()] = test
250 def populate(self, rootpath):
251 for root, dirs, files in os.walk(rootpath):
252 if (root.find(rootpath) == 0):
253 path = root[len(rootpath):]
256 if Test.isOnPath(root):
257 dv = self.space.path2dimValues(path)
258 self.addTest(Test(root, dv, self))
259 def generateHtml(self):
260 for pair in self.space.iterDimensionPairs():
261 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
262 for vals in remDims.iterValues():
263 page = Page(pair, vals, self)
267 os.remove("index.html")
269 os.symlink(page.getName(), "index.html")
270 css = open("style.css", "w")
271 print >>css, """img { border: 0; }
272 table { border-collapse: collapse; }
273 th, td { border: 1px solid lightgray; padding: 4px;}
275 .box { border: 1px solid black; padding: 1ex; margin: 1ex 0}
278 for test in self.values():
282 os.system("source-highlight -d --output-dir=. ../*.sh > /dev/null")
285 def __init__(self, dimPair, valsOther, tests):
286 self.dimy, self.dimx = dimPair
287 self.dimOther = [v.dim for v in valsOther]
288 self.valsOther = tests.space.reorder(valsOther)
291 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
292 "-".join([v.value for v in self.valsOther]))
294 html = open(self.getName(), "w")
295 title = "CAN gateway timing analysis"
296 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
297 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
299 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
301 <link rel="stylesheet" href="style.css" type="text/css" />
304 <h1>%s</h1>""" % (title, title)
305 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
306 print >>html, "<h3>Results for ", ", ".join(params), "</h3>"
307 print >>html, "<div class='box'><h4>Other views</h4>"
308 for d in self.dimOther:
309 print >>html, "%s: " % d
310 print >>html, "<a href='%s'>X axis</a>, " % \
311 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
312 print >>html, "<a href='%s'>Y axis</a>; " % \
313 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
316 if v in self.valsOther:
319 vv = DimValues(self.valsOther)
321 links.append("<a href='%s'>%s</a>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
322 print >>html, " | ".join(links)
325 print >>html, d.htmlPreamble()
328 print >>html, "</div>"
330 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
332 print >>html, "<th>%s</th>" % x.htmlTableHeading()
333 print >>html, "</tr></thead>"
335 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
340 idx.extend(self.valsOther)
342 test = tests.getTest(idx)
343 test.printThumbLink(html)
346 print >>html, "</td>"
347 print >>html, "</tr>"
350 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
355 if __name__ == "__main__":
356 os.chdir(sys.argv[1])
357 os.system("rm *.html")
358 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest()))