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):
158 'verticalAlign': "top",
163 'formatter': "FUN(tooltip_formatter)END",
165 'whiteSpace': 'normal',
172 'click': "FUN(series_onclick)END",
184 'labels': { 'align': 'right',
186 'title': { 'text': axis.getLabel() },
187 'minRange': axis.minrange,
188 } for axis in self.axes_ordered],
189 'series': [{ 'name': '%s [%s]' % (col.name, col.units),
190 'yAxis': col.axis.num }
191 for col in self.columns_ordered]
193 return json.dumps(options, indent=True).replace('"FUN(', '').replace(')END"', '')
196 data = [[[row.getDate(), row[col.name]] for row in sorted(self.rows, cmp, lambda r: r.date)] for col in self.columns_ordered]
197 return json.dumps(data).replace('], [', '],\n[')
207 date = datetime.now()
209 for line in sys.stdin:
212 match = re_date.match(line)
214 dstr = match.group(1)
217 date = datetime.strptime(string.join(words[0:2]), "%Y-%m-%d %H:%M:%S")
219 zone_hours = int(words[2])/100
220 date -= timedelta(hours = zone_hours)
223 match = re_repo.match(line)
225 url = match.group('url')
226 desc = match.group('desc')
227 hash = match.group('hash')
229 date2commit[date] = hash
230 commit2msg[hash] = desc
232 match = re_testing.match(line)
234 what = match.group(2)
235 where = match.group(3)
236 (basename, ext) = os.path.splitext(os.path.basename(where))
238 if what != "all": title = what
239 else: title = basename
241 graph = graphs[basename]
243 graph = Graph(basename, title)
244 graphs[basename] = graph
247 match = re_perf.match(line)
249 perfstr = match.group(3)
250 perf = perfstr.split()
258 if '=' in units: units = None
261 if match.group(4) != "ok":
264 graph.addValue(date, col, val, units)
266 match = re_perfaxis.search(perfstr)
268 graph.setAxis(col, match.group(1));
270 graphs = [g for g in list(graphs.values()) if len(g.columns)]
271 graphs = sorted(graphs, key=lambda g: g.title.lower())
281 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
282 <title>NUL Performance Plots</title>
284 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
285 <script type="text/javascript">
286 function tooltip_formatter() {
287 var s = '<b>'+ Highcharts.dateFormat('%a, %d %b %Y %H:%M:%S', this.x) +'</b><br/>';
288 s += commit2msg[date2commit[this.x]];
289 $.each(this.points, function(i, point) {
290 s += '<br/><span style="color:'+ point.series.color+';">'+ point.series.name +'</span>: '+point.y;
294 function series_onclick(event) {
295 var prevpoint = null;
296 for (var i in this.data) {
297 if (event.point == this.data[i]) {
298 if (i > 0) prevpoint = this.data[i-1];
302 if (prevpoint && date2commit[prevpoint.x] != date2commit[event.point.x])
303 window.location = "https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?qt=range&q="+date2commit[prevpoint.x]+'..'+date2commit[event.point.x];
305 window.location = "https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/?id="+date2commit[event.point.x];
308 def make_int_keys(json):
309 r = re.compile('"(\d+)"(.*)')
311 for match in r.finditer(json):
312 s += match.expand('\\1\\2')
315 print("var date2commit = {%s};" % ",\n".join(["%d: '%s'" % (dateConv(k), date2commit[k]) for k in sorted(date2commit.keys())]))
316 print("var commit2msg = %s;" % json.dumps(commit2msg, indent=True))
317 # for d in sorted(date2commit.keys()):
319 # print('\t%d: { msg: "%s", hash: "%s" },' % (1000*time.mktime(d), v[0].replace('"', '\\"'), str(v[1]).replace('"', '\\"')))
322 <script type="text/javascript" src="js/highstock.js"></script>
326 <h1>Linux CAN subsystem performance plots</h1>
327 <p>The graphs below show performance numbers from various
328 CAN bus related benchmarks run on different Linux kernel versions.</p>
329 <p>Table of content:</p>
333 print(" <li><a href='#%s'>%s</a></li>" % (graph.id, graph.title))
337 <h2><a name='%(id)s'>%(title)s</a></h2>
338 <div id="%(id)s" style="height: 400px"></div>
340 $.getJSON('%(dataname)s', function(data) {
341 var options = %(options)s
342 for (var i=0; i < data.length; i++)
343 options['series'][i]['data'] = data[i];
344 $("#%(id)s").highcharts("StockChart", options);
347 """ % {'id': graph.id,
348 'title': graph.title,
349 'dataname': graph.dataname,
350 'options': graph.options_json()})
351 print(graph.getData(), file=open(graph.dataname, 'w'))
358 # compile-command: "make perf"