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, tests=None):
132 self.name = os.path.basename(path)
135 def printThumbLink(self, file):
136 thumb = self.path+'/thumb'
138 imgs = [img for img in dircache.listdir(thumb)]
140 imgs = [ self.name + ".png" ]
142 print >>file, "<a href='%s/results.html'><img src='%s/thumb/%s'></a>" % \
143 (urllib.quote(self.path), urllib.quote(self.path), img)
144 def generateHtml(self):
145 html = open(os.path.join(self.path, 'results.html'), "w")
146 title = "CAN gateway timing analysis"
147 cdup = "../"*len(self.values)
148 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
149 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
151 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
153 <link rel="stylesheet" href="%sstyle.css" type="text/css" />
156 <h1>%s</h1>""" % (title, cdup, title)
157 params = ["%s %s" % (v.dim, v) for v in self.values]
158 print >>html, "Results for:", ", ".join(params)
159 print >>html, "<div class='box'><h4>Other views</h4>"
160 for d in self.tests.space:
166 vv = DimValues(self.values)
168 href = cdup + urllib.quote(self.tests[vv.key()].path+"/results.html")
169 links.append("<a href='%s'>%s</a>"%(href, str(v)))
170 print >>html, "%s: " % d, " | ".join(links), "<br>"
172 print >>html, "</div>"
173 print >>html, "<div><img src='%s' /></div>" % (self.name+".png")
174 print >>html, "<a href='./'>Raw data</a><br />"
175 print >>html, "<a href='%s'>Back to top</a>" % cdup
180 """List of Dimensions()s (order matters)"""
181 def __init__(self, *dimensions):
182 self.extend(list(dimensions))
183 def iterValues(self):
184 idx = [0 for i in xrange(len(self))]
188 for i in xrange(len(self)):
189 values.append(self[i].values()[idx[i]])
192 for i in xrange(len(self)):
194 if idx[i] < len(self[i]):
198 def reorder(self, dimValues):
199 reordered = DimValues()
205 def iterDimensionPairs(self):
206 for i in xrange(len(self)):
207 for j in xrange(i+1, len(self)):
208 yield (self[i], self[j])
209 yield (self[j], self[i])
210 def iterRemainingDimensions(self, dimensionPair):
212 if d not in dimensionPair:
217 """Represents all tests organized along several dimensions"""
218 def __init__(self, rootpath, space):
222 self.populate(rootpath)
223 def getTest(self, key):
224 if len(key) != len(self.space):
225 raise KeyError("The coordinates in key do not match the dimension of the space")
226 realkey = self.space.reorder(key)
227 return self[realkey.key()]
229 def addTest(self, test):
230 self[test.values.key()] = test
232 def populate(self, rootpath):
233 for root, dirs, files in os.walk(rootpath):
234 if (root.find(rootpath) == 0):
235 coordinates = root[len(rootpath):].split("/")
237 coordinates = rootpath.split("/")
238 if Test.isOnPath(root):
239 if len(coordinates) != len(self.space):
240 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
241 dv = DimValues([DimValue(self.space[i], coordinates[i]) for i in xrange(len(coordinates))])
242 self.addTest(Test(root, dv, self))
243 def generateHtml(self):
244 for pair in self.space.iterDimensionPairs():
245 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
246 for vals in remDims.iterValues():
247 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}
262 for test in self.values():
266 #os.system("source-highlight -d --output-dir=. ../*.sh")
269 def __init__(self, dimPair, valsOther, tests):
270 self.dimy, self.dimx = dimPair
271 self.dimOther = [v.dim for v in valsOther]
272 self.valsOther = tests.space.reorder(valsOther)
275 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
276 "-".join([v.value for v in self.valsOther]))
278 html = open(self.getName(), "w")
279 title = "CAN gateway timing analysis"
280 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
281 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
283 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
285 <link rel="stylesheet" href="style.css" type="text/css" />
288 <h1>%s</h1>""" % (title, title)
289 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
290 print >>html, "<h3>Results for ", ", ".join(params), "</h3>"
291 print >>html, "<div class='box'><h4>Other views</h4>"
292 for d in self.dimOther:
293 print >>html, "%s: " % d
294 print >>html, "<a href='%s'>X axis</a>, " % \
295 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
296 print >>html, "<a href='%s'>Y axis</a>; " % \
297 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
300 if v in self.valsOther:
303 vv = DimValues(self.valsOther)
305 links.append("<a href='%s'>%s</a>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
306 print >>html, " | ".join(links)
309 print >>html, d.htmlPreamble()
312 print >>html, "</div>"
314 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
316 print >>html, "<th>%s</th>" % x.htmlTableHeading()
317 print >>html, "</tr></thead>"
319 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
324 idx.extend(self.valsOther)
326 test = tests.getTest(idx)
327 test.printThumbLink(html)
330 print >>html, "</td>"
331 print >>html, "</tr>"
334 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
339 if __name__ == "__main__":
340 os.chdir(sys.argv[1])
341 os.system("rm *.html")
342 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest()))