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):
132 self.name = os.path.basename(path)
133 def printThumbLink(self, file):
134 thumb = self.path+'/thumb'
136 imgs = [img for img in dircache.listdir(thumb)]
138 imgs = [ self.name + ".png" ]
140 print >>file, "<a href='%s/%s'><img src='%s/thumb/%s'></a>" % \
141 (urllib.quote(self.path), img, urllib.quote(self.path), img)
144 """List of Dimensions()s (order matters)"""
145 def __init__(self, *dimensions):
146 self.extend(list(dimensions))
147 def iterValues(self):
148 idx = [0 for i in xrange(len(self))]
152 for i in xrange(len(self)):
153 values.append(self[i].values()[idx[i]])
156 for i in xrange(len(self)):
158 if idx[i] < len(self[i]):
162 def reorder(self, dimValues):
163 reordered = DimValues()
169 def iterDimensionPairs(self):
170 for i in xrange(len(self)):
171 for j in xrange(i+1, len(self)):
172 yield (self[i], self[j])
173 yield (self[j], self[i])
174 def iterRemainingDimensions(self, dimensionPair):
176 if d not in dimensionPair:
181 """Represents all tests organized along several dimensions"""
182 def __init__(self, rootpath, space):
186 self.populate(rootpath)
187 def getTest(self, key):
188 if len(key) != len(self.space):
189 raise KeyError("The coordinates in key do not match the dimension of the space")
190 realkey = self.space.reorder(key)
191 return self[realkey.key()]
193 def addTest(self, test, coordinates):
194 if len(coordinates) != len(self.space):
195 raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
196 self[tuple(coordinates)] = test
197 for i in xrange(len(coordinates)):
198 DimValue(self.space[i], coordinates[i])
200 def populate(self, rootpath):
201 for root, dirs, files in os.walk(rootpath):
202 if (root.find(rootpath) == 0):
203 coordinates = root[len(rootpath):]
205 coordinates = rootpath
206 if Test.isOnPath(root):
207 self.addTest(Test(root), coordinates.split("/"))
208 def generateHtml(self):
209 for pair in self.space.iterDimensionPairs():
210 remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
211 for vals in remDims.iterValues():
212 page = Page(pair, vals, self)
215 os.remove("index.html")
217 os.symlink(page.getName(), "index.html")
219 #os.system("source-highlight -d --output-dir=. ../*.sh")
222 def __init__(self, dimPair, valsOther, tests):
223 self.dimy, self.dimx = dimPair
224 self.dimOther = [v.dim for v in valsOther]
225 self.valsOther = tests.space.reorder(valsOther)
228 return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
229 "-".join([v.value for v in self.valsOther]))
231 html = open(self.getName(), "w")
232 title = "CAN gateway timing analysis"
233 print >> html, """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
234 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
236 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
240 table { border-collapse: collapse; }
241 th, td { border: 1px solid lightgray; padding: 4px;}
245 <h1>%s</h1>""" % (title, title)
246 params = ["%s %s" % (v.dim, v) for v in self.valsOther]
247 print >>html, "Results for:", ", ".join(params), "<hr />"
248 for d in self.dimOther:
249 print >>html, "%s: " % d
250 print >>html, "<a href='%s'>X axis</a>, " % \
251 Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
252 print >>html, "<a href='%s'>Y axis</a>; " % \
253 Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
256 if v in self.valsOther:
259 vv = DimValues(self.valsOther)
261 links.append("<a href='%s'>%s</a>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
262 print >>html, " | ".join(links)
265 print >>html, d.htmlPreamble()
269 print >>html, "<table><thead><tr><td>%s → <br />%s ↓</td>" % (self.dimx.name, self.dimy.name)
271 print >>html, "<th>%s</th>" % x.htmlTableHeading()
272 print >>html, "</tr></thead>"
274 print >>html, "<tr><th>%s</th>" % y.htmlTableHeading()
279 idx.extend(self.valsOther)
281 test = tests.getTest(idx)
282 test.printThumbLink(html)
285 print >>html, "</td>"
286 print >>html, "</tr>"
289 <div style="font-size: small; color: gray; margin-top: 1em;">Authors: Michal Sojka, Pavel Píša, Copyright © 2010 Czech Technical University in Prague</div>
294 if __name__ == "__main__":
295 os.chdir(sys.argv[1])
296 os.system("rm *.html")
297 tests = Tests("./", Space(DimensionHostKern(), DimensionKern(), DimensionTraffic(), DimensionTest()))