-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregressions.js
448 lines (376 loc) · 16.4 KB
/
regressions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
'use strict';
$(document).ready(function() {
/* Cached contents of downloaded regressions.json */
var regression_data = null;
/* Current page title */
var current_title = "All regressions";
/* Whether HTML5 local storage is available */
var local_storage_available = false;
/* Key prefix for ignored regressions. For each ignored regression,
a key "ignore_key_prefix + md5(benchmark_name + date_a + date_b)"
is added to HTML5 local storage.
*/
var ignore_key_prefix = null;
/* Set of ignored regressions, same information as in HTML5 local storage.
Useful if local storage runs out of space. */
var ignored_regressions = {};
function load_data(params) {
$("#title").text(current_title);
if (typeof(Storage) !== "undefined") {
/* html5 local storage available */
local_storage_available = true;
}
if (regression_data !== null) {
// already displayed
}
else {
var message = $('<div>Loading...</div>');
$('#regressions-body').append(message);
$.ajax({
url: 'regressions.json' + '?timestamp=' + $.asv.master_timestamp,
dataType: "json",
cache: true
}).done(function (data) {
regression_data = data;
var main_div = display_data(data, params);
$('#regressions-body').empty();
$('#regressions-body').append(main_div);
});
}
}
function update_url(params) {
var info = $.asv.parse_hash_string(window.location.hash);
$.each(params || {}, function(key, value) {
info.params[key] = value;
});
window.location.hash = $.asv.format_hash_string(info);
}
function display_data(data, params) {
var main_div = $('<div/>');
var branches = $.asv.master_json.params['branch'];
var all_ignored_keys = {};
ignore_key_prefix = 'asv-r-' + $.asv.master_json.project;
if (branches && branches.length > 1) {
/* Add a branch selector */
var dropdown_menu = $('<ul class="dropdown-menu" role="menu"/>');
var dropdown_div = $('<div class="dropdown">');
dropdown_div.append($('<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Branches ' +
'<span class="caret"/></button>'));
dropdown_div.append(dropdown_menu);
main_div.append(dropdown_div);
}
var feed_div = $('<div class="feed-div"><a class="btn" href="regressions.xml">Feed (Atom)</a></div>');
main_div.append(feed_div);
$.each(branches, function(i, branch) {
var branch_div = $('<div class="regression-div"/>')
var display_table = $('<table class="table table-hover"/>');
var ignored_table = $('<table class="table table-hover ignored"/>');
var ignored_button = $('<button class="btn btn-default">Show ignored regressions...</button>');
var ignored_conf_sample_div = $('<div class="ignored"/>');
if (branches && branches.length > 1) {
var branch_link = $('<a/>')
branch_link.text(branch);
dropdown_menu.append($('<li role="presentation"/>').append(branch_link));
branch_link.on('click', function(evt) {
current_title = "Regressions in " + branch + " branch";
update_url({'branch': [branch]});
$("#title").text(current_title);
$(".regression-div").hide();
$(".ignored").hide();
ignored_button.show();
$("#regression-div-" + i).show();
$("#regression-div-" + i + '-ignored').show();
});
}
else {
branch = null;
}
branch_div.attr('id', 'regression-div-' + i);
branch_div.hide();
main_div.append(branch_div);
create_data_table(display_table, ignored_table, ignored_conf_sample_div,
data, params, branch, all_ignored_keys);
branch_div.append(display_table);
ignored_table.hide();
ignored_conf_sample_div.hide();
branch_div.append(ignored_table);
branch_div.append(ignored_conf_sample_div);
update_ignore_conf_sample(data, ignored_conf_sample_div, branch);
branch_div.append(ignored_button);
ignored_button.on('click', function(evt) {
ignored_button.hide();
$(".ignored").show();
});
});
var branch_index = 0;
if (branches && branches.length > 1) {
if (params.branch) {
branch_index = branches.indexOf(params.branch[0]);
if (branch_index < 0) {
branch_index = 0;
}
}
current_title = "Regressions in " + branches[branch_index] + " branch";
}
$("#title").text(current_title);
main_div.find("#regression-div-" + branch_index).show();
main_div.show();
if (local_storage_available) {
/* Clear out local storage space */
var keys = Object.keys(localStorage);
$.each(keys, function(i, key) {
if (key.slice(0, ignore_key_prefix.length) == ignore_key_prefix &&
!all_ignored_keys[key]) {
delete localStorage[key];
}
});
}
return main_div;
}
function create_data_table(display_table, ignored_table, ignored_conf_sample_div,
data, params, branch, all_ignored_keys) {
var table_head = $('<thead><tr>' +
'<th data-sort="string">Benchmark</th>' +
'<th data-sort="string">Date</th>' +
'<th data-sort="string">Commit</th>' +
'<th data-sort="factor">Factor</th>' +
'<th data-sort="value">Before</th>' +
'<th data-sort="value">After</th>' +
'<th></th>' +
'</tr></thead>');
display_table.append(table_head);
ignored_table.append(table_head.clone());
var table_body = $('<tbody/>');
var ignored_table_body = $('<tbody/>');
var regressions = data['regressions'];
$.each(regressions, function (i, item) {
var benchmark_name = item[0];
var graph_url = item[1];
var param_dict = item[2];
var parameter_idx = item[3];
var last_value = item[4];
var best_value = item[5];
var jumps = item[6]; // [[rev1, rev2, before, after], ...]
if (jumps === null) {
return;
}
if (branch !== null && param_dict['branch'] != branch) {
return;
}
var benchmark_basename = benchmark_name.replace(/\(.*/, '');
var benchmark = $.asv.master_json.benchmarks[benchmark_basename];
var url_params = {};
$.each(param_dict, function (key, value) {
url_params[key] = [value];
});
if (parameter_idx !== null) {
$.each($.asv.param_selection_from_flat_idx(benchmark.params, parameter_idx).slice(1), function(i, param_values) {
url_params['p-'+benchmark.param_names[i]] = [benchmark.params[i][param_values[0]]];
});
}
$.each(jumps, function(i, revs) {
var row = $('<tr/>');
var commit_a = $.asv.get_commit_hash(revs[0]);
var commit_b = $.asv.get_commit_hash(revs[1]);
var old_value = revs[2];
var new_value = revs[3];
var factor = new_value / old_value;
if (commit_a) {
url_params.commits = [commit_a + '-' + commit_b];
}
else {
url_params.commits = [commit_b];
}
var benchmark_url = $.asv.format_hash_string({
location: [benchmark_basename],
params: url_params
});
new_value = $.asv.pretty_unit(new_value, benchmark.unit);
old_value = $.asv.pretty_unit(old_value, benchmark.unit);
var benchmark_link = $('<a/>').attr('href', benchmark_url).text(benchmark_name);
row.append($('<td/>').append(benchmark_link));
var date_fmt = new Date($.asv.master_json.revision_to_date[revs[1]]);
row.append($('<td class="date"/>').text($.asv.format_date_yyyymmdd_hhmm(date_fmt)));
var commit_td = $('<td/>');
if (commit_a) {
if ($.asv.master_json.show_commit_url.match(/.*\/\/github.com\//)) {
var commit_url = ($.asv.master_json.show_commit_url + '../compare/'
+ commit_a + '...' + commit_b);
commit_td.append(
$('<a/>').attr('href', commit_url).text(commit_a + '..' + commit_b));
}
else {
commit_td.append($('<span/>').text(commit_a + '..' + commit_b));
}
}
else {
var commit_url = $.asv.master_json.show_commit_url + commit_b;
commit_td.append(
$('<a/>').attr('href', commit_url).text(commit_b));
}
row.append(commit_td);
row.append($('<td/>').text(factor.toFixed(2) + 'x'));
row.append($('<td/>').text(old_value));
row.append($('<td/>').text(new_value));
/* html5 local storage has limited size, so store hashes
rather than potentially long strings */
var ignore_key = get_ignore_key(item, revs);
all_ignored_keys[ignore_key] = 1;
var is_ignored = is_key_ignored(ignore_key);
var ignore_button = $('<button class="btn btn-small"/>');
row.attr('id', ignore_key);
ignore_button.on('click', function(evt) {
if (is_key_ignored(ignore_key)) {
set_key_ignore_status(ignore_key, false);
var item = ignored_table_body.find('#' + ignore_key).detach();
ignore_button.text('Ignore');
table_body.append(item);
}
else {
set_key_ignore_status(ignore_key, true);
var item = table_body.find('#' + ignore_key).detach();
ignore_button.text('Unignore');
ignored_table_body.append(item);
}
update_ignore_conf_sample(data, ignored_conf_sample_div, branch);
});
row.append($('<td/>').append(ignore_button));
if (!is_ignored) {
ignore_button.text('Ignore');
table_body.append(row);
}
else {
ignore_button.text('Unignore');
ignored_table_body.append(row);
}
/* Show a graph as a popup */
$.asv.ui.hover_graph(benchmark_link, graph_url, benchmark_basename, parameter_idx, [revs]);
});
});
display_table.append(table_body);
ignored_table.append(ignored_table_body);
setup_sort(params, display_table);
setup_sort(params, ignored_table);
}
function get_ignore_key(item, revs) {
var benchmark_name = item[0];
var ignore_payload = benchmark_name;
if (revs[0] === null) {
ignore_payload = ignore_payload + ',';
}
else {
ignore_payload = (ignore_payload + ','
+ $.asv.master_json.revision_to_hash[revs[0]]);
}
ignore_payload = (ignore_payload + ','
+ $.asv.master_json.revision_to_hash[revs[1]]);
return ignore_key_prefix + md5(ignore_payload);
}
function is_key_ignored(ignore_key) {
if (local_storage_available) {
return (ignore_key in localStorage) || (ignore_key in ignored_regressions);
}
else {
return (ignore_key in ignored_regressions);
}
}
function set_key_ignore_status(ignore_key, is_ignored) {
if (is_ignored) {
if (local_storage_available) {
try {
localStorage[ignore_key] = 1;
} catch (err) {
/* Out of quota -- we're just going to ignore that */
}
}
ignored_regressions[ignore_key] = 1;
}
else {
if (local_storage_available) {
delete localStorage[ignore_key];
}
delete ignored_regressions[ignore_key];
}
}
function update_ignore_conf_sample(data, ignored_conf_sample_div, branch) {
var regressions = data['regressions'];
var entries = {};
var branch_suffix = "";
if (branch) {
branch_suffix = "@" + branch;
}
$.each(regressions, function (i, item) {
var param_dict = item[2];
if (branch !== null && param_dict['branch'] != branch) {
return;
}
$.each(item[6], function (i, revs) {
var ignore_key = get_ignore_key(item, revs);
if (is_key_ignored(ignore_key)) {
var benchmark_name = item[0];
var benchmark_name_re = (benchmark_name + branch_suffix).replace(/[.?*+^$[\]\\(){}|-]/g, "\\\\$&");
var commit = $.asv.get_commit_hash(revs[1]);
var entry = " \"^" + benchmark_name_re + "$\": \"" + commit + "\",\n";
entries[entry] = 1;
}
});
});
entries = Object.keys(entries);
entries.sort();
var text = "// asv.conf.json excerpt for ignoring the above permanently\n\n";
text += " \"regressions_first_commits\": {\n";
$.each(entries, function (i, entry) {
text += entry;
});
text += " }";
var pre = $('<pre/>');
pre.text(text);
ignored_conf_sample_div.empty();
ignored_conf_sample_div.append(pre);
}
function setup_sort(params, table) {
table.stupidtable({
'value': function(a, b) {
function key(s) {
for (var k = 0; k < $.asv.time_units.length; ++k) {
var entry = $.asv.time_units[k];
var m = s.match('^([0-9.]+)'+entry[0]+'$');
if (m) {
return parseFloat(m[1]) * entry[2] * 1e-30;
}
}
return 0;
}
return key(a) - key(b)
},
'factor': function(a, b) {
return parseFloat(a.replace(/x/, '')) - parseFloat(b.replace(/x/, ''));
}
});
table.on('aftertablesort', function (event, data) {
update_url({'sort': [data.column], 'dir': [data.direction]});
/* Update appearance */
table.find('thead th').removeClass('asc');
table.find('thead th').removeClass('desc');
var th_to_sort = table.find("thead th").eq(parseInt(data.column));
if (th_to_sort) {
th_to_sort.addClass(data.direction);
}
});
if (params.sort && params.dir) {
var th_to_sort = table.find("thead th").eq(parseInt(params.sort[0]));
th_to_sort.stupidsort(params.dir[0]);
}
else {
var th_to_sort = table.find("thead th").eq(3);
th_to_sort.stupidsort("desc");
}
}
/*
Setup display hooks
*/
$.asv.register_page('regressions', function(params) {
$('#regressions-display').show()
load_data(params);
});
});