4 # Copyright (C) 2012, 2014 Michal Sojka <sojka@os.inf.tu-dresden.de>
5 # Licensed under the GNU Library General Public License, version 2.
6 # See the included file named LICENSE for license information.
8 # This script converts a sequence of wvtest protocol outputs with
9 # results of performance measurements to interactive graphs (HTML +
10 # JavaScript). An example can be seen at
11 # http://os.inf.tu-dresden.de/~sojka/nul/performance.html.
13 from __future__ import print_function
20 from datetime import timedelta,datetime
25 re_prefix = "\([0-9]+\) (?:# )?"
26 re_date = re.compile('^! Date: (.*?) ok')
27 re_testing = re.compile('^('+re_prefix+')?\s*Testing "(.*)" in (.*):\s*$')
28 re_repo = re.compile('^! Repo (?P<url>[^ ]*) (?P<desc>[^ ]*) (?P<hash>[0-9a-f]*) ok')
29 re_assertion = re.compile('^('+re_prefix+')?!\s*(.*?)\s+(\S+)\s*$')
30 re_perf = re.compile('^('+re_prefix+')?!\s*(.*?)\s+PERF:\s*(.*?)\s+(\S+)\s*$')
31 re_perfaxis = re.compile('axis="([^"]+)"')
34 return int(time.mktime(date.timetuple()))*1000
38 def __init__(self, name=None, units=None):
43 if self.units and self.name:
44 return "%s [%s]" % (self.name, self.units)
49 def __repr__(self): return "Axis(name=%s units=%s, id=%s)" % (self.name, self.units, hex(id(self)))
52 def __init__(self, name, units, axis):
56 def __repr__(self): return "Column(name=%s units=%s axis=%s)" % (self.name, self.units, repr(self.axis))
59 def __init__(self, graph, date):
62 def __getitem__(self, column):
64 return dict.__getitem__(self, column)
68 return dateConv(self.date)
71 def __init__(self, id, title):
73 self.columns_ordered = []
79 self.axes_ordered = []
80 self.dataname = title.translate(string.maketrans(" /", "--"), "\"':,+()").lower()+".json"
82 def __getitem__(self, date):
84 rownum = self.date2row[date]
86 rownum = len(self.rows)
87 self.date2row[date] = rownum
89 return self.rows[rownum]
91 self.rows[rownum:rownum] = [Row(self, date)]
92 return self.rows[rownum]
94 def addValue(self, date, col, val, units):
95 if col == "gw_latency" and val == 0:
99 if col not in self.columns:
100 axis=self.getAxis(units) or self.addAxis(units, Axis(units=units))
101 column = Column(col, units, axis)
102 self.columns[col] = column
103 self.columns_ordered.append(column)
105 column = self.columns[col]
106 self.columns_ordered.remove(column)
107 self.columns_ordered.append(column)
108 self.columns[col].units=units
109 self.columns[col].axis.units=units
111 def addAxis(self, key, axis):
112 self.axes[key] = axis
115 def setAxis(self, col, key):
116 self.columns[col].axis = self.getAxis(key) or self.addAxis(key, Axis(name=key))
118 def getAxis(self, key):
119 if key not in self.axes: return None
120 return self.axes[key]
122 def findRanges(self):
123 for axis in list(self.axes.values()):
124 cols = [col for col in list(self.columns.values()) if col.axis == axis]
127 allvalues = np.array([row[col.name] for row in self.rows if row[col.name] != None], np.float64)
128 lastmonth = allvalues[-30:]
129 values.extend(lastmonth);
131 axis.minrange = np.mean(values)/10.0
133 def fixupAxisNumbers(self):
134 # Sort axes according to the columns and number them
136 for column in self.columns_ordered:
138 if axis not in self.axes_ordered:
139 self.axes_ordered.insert(0, axis)
143 for axis in self.axes_ordered:
147 def options_json(self):
161 'verticalAlign': "top",
166 'formatter': "FUN(tooltip_formatter)END",
168 'whiteSpace': 'normal',
175 'click': "FUN(series_onclick)END",
187 'labels': { 'align': 'right',
189 'title': { 'text': axis.getLabel() },
190 'minRange': axis.minrange,
191 'tickPixelInterval': 40,
192 } for axis in self.axes_ordered],
193 'series': [{ 'name': '%s [%s]' % (col.name, col.units),
194 'yAxis': col.axis.num }
195 for col in self.columns_ordered]
197 return json.dumps(options, indent=True).replace('"FUN(', '').replace(')END"', '')
200 data = [[[row.getDate(), row[col.name]] for row in sorted(self.rows, cmp, lambda r: r.date)] for col in self.columns_ordered]
201 return json.dumps(data).replace('], [', '],\n[')
211 date = datetime.now()
213 for line in sys.stdin:
216 match = re_date.match(line)
218 dstr = match.group(1)
221 date = datetime.strptime(string.join(words[0:2]), "%Y-%m-%d %H:%M:%S")
223 zone_hours = int(words[2])/100
224 date -= timedelta(hours = zone_hours)
227 match = re_repo.match(line)
229 url = match.group('url')
230 desc = match.group('desc')
231 hash = match.group('hash')
233 date2commit[date] = hash
234 commit2msg[hash] = desc
236 match = re_testing.match(line)
238 what = match.group(2)
239 where = match.group(3)
240 (basename, ext) = os.path.splitext(os.path.basename(where))
242 if what != "all": title = what
243 else: title = basename
245 graph = graphs[basename]
247 graph = Graph(basename, title)
248 graphs[basename] = graph
251 match = re_perf.match(line)
253 perfstr = match.group(3)
254 perf = perfstr.split()
262 if '=' in units: units = None
265 if match.group(4) != "ok":
268 graph.addValue(date, col, val, units)
270 match = re_perfaxis.search(perfstr)
272 graph.setAxis(col, match.group(1));
274 graphs = [g for g in list(graphs.values()) if len(g.columns)]
275 graphs = sorted(graphs, key=lambda g: g.title.lower())
281 pagetitle="Linux CAN subsystem performance plots"
286 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
287 <title>%(pagetitle)s</title>
289 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
290 <script type="text/javascript">
291 function tooltip_formatter() {
292 var s = '<b>'+ Highcharts.dateFormat('%%a, %%d %%b %%Y %%H:%%M:%%S', this.x) +'</b><br/>';
293 s += commit2msg[date2commit[this.x]];
294 $.each(this.points, function(i, point) {
295 s += '<br/><span style="color:'+ point.series.color+';">'+ point.series.name +'</span>: '+point.y;
299 function series_onclick(event) {
300 var prevpoint = null;
301 for (var i in this.data) {
302 if (event.point == this.data[i]) {
303 if (i > 0) prevpoint = this.data[i-1];
307 if (prevpoint && date2commit[prevpoint.x] != date2commit[event.point.x])
308 window.location = "https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?qt=range&q="+date2commit[prevpoint.x]+'..'+date2commit[event.point.x];
310 window.location = "https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?id="+date2commit[event.point.x];
313 def make_int_keys(json):
314 r = re.compile('"(\d+)"(.*)')
316 for match in r.finditer(json):
317 s += match.expand('\\1\\2')
320 print("var date2commit = {%s};" % ",\n".join(["%d: '%s'" % (dateConv(k), date2commit[k]) for k in sorted(date2commit.keys())]))
321 print("var commit2msg = %s;" % json.dumps(commit2msg, indent=True))
322 # for d in sorted(date2commit.keys()):
324 # print('\t%d: { msg: "%s", hash: "%s" },' % (1000*time.mktime(d), v[0].replace('"', '\\"'), str(v[1]).replace('"', '\\"')))
327 <script type="text/javascript" src="js/highstock.js"></script>
331 <h1>%(pagetitle)s</h1>
332 <p>The graphs below show performance numbers from various
333 CAN bus related benchmarks run on different Linux kernel versions.</p>
334 <p>Table of content:</p>
338 print(" <li><a href='#%s'>%s</a></li>" % (graph.id, graph.title))
342 <h2><a name='%(id)s'>%(title)s</a></h2>
343 <div id="%(id)s" style="height: 400px"></div>
345 $.getJSON('%(dataname)s', function(data) {
346 var options = %(options)s
347 for (var i=0; i < data.length; i++)
348 options['series'][i]['data'] = data[i];
349 $("#%(id)s").highcharts("StockChart", options);
352 """ % {'id': graph.id,
353 'title': graph.title,
354 'dataname': graph.dataname,
355 'options': graph.options_json()})
356 print(graph.getData(), file=open(graph.dataname, 'w'))
363 # compile-command: "make perf"