diff --git a/codespeed/static/js/comparison.js b/codespeed/static/js/comparison.js index 72016f5c..594c8928 100644 --- a/codespeed/static/js/comparison.js +++ b/codespeed/static/js/comparison.js @@ -41,16 +41,57 @@ function getConfiguration() { }; } +// (exe, env) combinations that have at least one result for the selected benchmarks +function pairsWithData(exes, enviros, bens) { + var pairs = []; + if (!compdata) { return pairs; } + for (var x = 0; x < exes.length; x++) { + for (var e = 0; e < enviros.length; e++) { + var d = compdata[exes[x]] && compdata[exes[x]][enviros[e]]; + if (!d) { continue; } + for (var b = 0; b < bens.length; b++) { + if (d[bens[b]] !== null && d[bens[b]] !== undefined) { + pairs.push([exes[x], enviros[e]]); + break; + } + } + } + } + return pairs; +} + function updateGraphTitle(exes, enviros, bens, baseline, chart, chartTitles) { var $title = $("#graph-title"); var isPair = (exes.length === 2 && enviros.length === 1) || (exes.length === 1 && enviros.length === 2); - if (isPair && chart !== "stacked bars" && compdata) { + var dataPairs = isPair ? [] : pairsWithData(exes, enviros, bens); + if ((isPair || dataPairs.length === 2) && chart !== "stacked bars" && compdata) { // Resolve which (exe, env) pair is "other" vs "base" var otherExe, otherEnv, baselineExe, baselineEnv; - if (exes.length === 1 && enviros.length === 2) { + if (!isPair) { + // Several exes/envs selected, but only two combinations have results + var baseIdx = 0; + if (baseline !== "none") { + var bp = baseline.split('@'); + baseIdx = -1; + for (var i = 0; i < dataPairs.length; i++) { + if (dataPairs[i][0] === bp[0] && (bp.length === 1 || dataPairs[i][1] === bp[1])) { + baseIdx = i; + break; + } + } + if (baseIdx === -1) { + $title.text(chartTitles.join(' / ')); + return; + } + } + baselineExe = dataPairs[baseIdx][0]; + baselineEnv = dataPairs[baseIdx][1]; + otherExe = dataPairs[1 - baseIdx][0]; + otherEnv = dataPairs[1 - baseIdx][1]; + } else if (exes.length === 1 && enviros.length === 2) { // Same exe, two environments — only show geomean when an explicit baseline env is set if (baseline === "none") { $title.text(chartTitles.join(' / ')); @@ -117,10 +158,10 @@ function updateGraphTitle(exes, enviros, bens, baseline, chart, chartTitles) { var otherLabel = getExeLabel(otherExe); var baselineLabel = getExeLabel(baselineExe); - if (exes.length === 1) { + if (exes.length === 1 || (!isPair && otherEnv !== envForBase)) { otherLabel += ' @ ' + $("label[for='env_" + otherEnv + "']").text().trim(); baselineLabel += ' @ ' + $("label[for='env_" + envForBase + "']").text().trim(); - } else if (baselineEnv !== null) { + } else if (baselineEnv !== null && isPair) { baselineLabel += ' @ ' + $("label[for='env_" + baselineEnv + "']").text().trim(); } diff --git a/codespeed/views.py b/codespeed/views.py index e74d3a37..cb760cc5 100644 --- a/codespeed/views.py +++ b/codespeed/views.py @@ -32,7 +32,7 @@ logger = logging.getLogger(__name__) -# Fraction of the plottable benchmark set a revision must have legacy results +# Fraction of the plottable benchmark set a revision must have results # for before gethistoricaldata() will render it as the 'latest' column. Runs # glitch and drop individual benchmarks, so this is deliberately below 1.0. LATEST_MIN_COVERAGE = 0.8 @@ -111,6 +111,9 @@ def gethistoricaldata(request): # 'labels' maps each key in tagged_revs (plus baseline and 'latest') to # a two-line label [tag, project] for the x axis of the history chart. data = {'results': {}, 'benchmarks': [], 'labels': {}} + source = request.GET.get('source', 'legacy') + if source not in ('legacy', 'pyperformance'): + return HttpResponseBadRequest('unknown source') env = Environment.objects.all() if settings.DEF_ENVIRONMENT: env = env.get(name=settings.DEF_ENVIRONMENT) @@ -133,13 +136,13 @@ def gethistoricaldata(request): data['labels'][resname] = [rev0.tag, baseline_exe.project.name] baseline_results.append((resname, Result.objects.filter( executable=baseline_exe, revision=rev0, environment=env, - benchmark__source='legacy'))) + benchmark__source=source))) if not baseline_results[-1][1]: logger.error('Could not find results for {} rev="{}" env="{}"'.format( baseline_exe, rev0, env)) default_results = {} - all_taggedrevs = [] + data['tagged_revs'] = [] for executable in settings.DEF_EXECUTABLES[::-1]: _def_name = executable['name'] _def_project = Project.objects.get(name=executable['project']) @@ -152,18 +155,19 @@ def gethistoricaldata(request): default_taggedrevs = Revision.objects.filter( branch=_default_branch ).exclude(tag="").order_by('date') - all_taggedrevs += default_taggedrevs for rev in default_taggedrevs: - # Filter to legacy only; pyperformance history can get its own panel later + # A tag can sit on several revisions (e.g. a re-tagged release) + if rev.tag in default_results: + continue res = Result.objects.filter( executable=_default_exe, revision=rev, environment=env, - benchmark__source='legacy') + benchmark__source=source) if not res: logger.info("no results for '%s' '%s' '%s'" % (str(_default_exe), str(rev), str(env))) continue default_results[rev.tag] = res data['labels'][rev.tag] = [rev.tag, _default_exe.project.name] - data['tagged_revs'] = [rev.tag for rev in all_taggedrevs if rev.tag in default_results] + data['tagged_revs'].append(rev.tag) # Fetch data for latest results executable = settings.DEF_EXECUTABLES[0] def_name = executable['name'] @@ -176,27 +180,27 @@ def gethistoricaldata(request): revs = Revision.objects.filter( branch=default_branch).order_by('-date')[:100] # The benchmarks the plots can actually use: those the baseline and every - # tagged revision all have legacy results for. A benchmark missing from any + # tagged revision all have results for. A benchmark missing from any # of them is dropped client side, so it cannot count towards coverage. plottable = {res.benchmark.name for res in baseline_results[0][1]} for tag in data['tagged_revs']: plottable &= {res.benchmark.name for res in default_results[tag]} required = len(plottable) * LATEST_MIN_COVERAGE - # Accept a revision as 'latest' only once its legacy run has covered enough + # Accept a revision as 'latest' only once its run has covered enough # of that set, otherwise fall back to the previous one that has. for rev in revs: latest_results = Result.objects.filter( executable=default_exe, revision=rev, environment=env, - benchmark__source='legacy') + benchmark__source=source) covered = plottable & {res.benchmark.name for res in latest_results} if covered and len(covered) >= required: default_results['latest'] = latest_results break logger.info( "skipping '%s' as 'latest': %d of %d plottable benchmarks have " - "legacy results for '%s'" % ( - str(rev), len(covered), len(plottable), str(env))) + "%s results for '%s'" % ( + str(rev), len(covered), len(plottable), source, str(env))) else: logger.error( "no revision covers %.0f%% of the %d plottable benchmarks for " diff --git a/speed_pypy/templates/embed_comparison.html b/speed_pypy/templates/embed_comparison.html index 13acb984..919011d5 100644 --- a/speed_pypy/templates/embed_comparison.html +++ b/speed_pypy/templates/embed_comparison.html @@ -21,9 +21,18 @@ font-family: sans-serif; color: var(--chart-text); } + #full-results { + position: absolute; + top: 4px; + right: 8px; + z-index: 1; + font: 12px sans-serif; + color: var(--chart-text); + }
+ {% if full_results_url %}All benchmarks →{% endif %} @@ -61,6 +70,17 @@ }); applyTheme(resolveTheme()); + // Only the fastest and slowest few benchmarks fit; the rest collapse into a gap + // A phone counts as narrow even when the embedding page has no viewport + // meta and lays itself (and so this frame) out at desktop width + function isNarrow() { return Math.min(window.innerWidth, screen.width) <= 760; } + var wasNarrow = isNarrow(); + // Such a page is shrunk to fit the phone, so grow the text to match + function fontScale() { + return isNarrow() ? Math.min(2.5, Math.max(1, window.innerWidth / screen.width)) : 1; + } + var plotData = null; + function renderplot(data) { var wrap = document.getElementById('baseline-comparison-plot'); if (data === null || data.length === 0 || @@ -69,43 +89,86 @@ return; } - var benchmarks = [], latestValues = [], baselineValues = []; - var tagged_data = []; - for (var i in data['tagged_revs']) { tagged_data[i] = []; } - + var rows = []; for (var bench in data['benchmarks']) { var benchname = data['benchmarks'][bench]; - var add_to_tagged_data = true; + var complete = true; for (var i in data['tagged_revs']) { - var rev = data['tagged_revs'][i]; - if (data['results'][benchname][rev] === 0) { add_to_tagged_data = false; break; } - tagged_data[i].push(data['results'][benchname][rev] / data['results'][benchname][data['baseline']]); + if (data['results'][benchname][data['tagged_revs'][i]] === 0) { complete = false; break; } } - if (!add_to_tagged_data) { continue; } + if (!complete) { continue; } var rel = data['results'][benchname]['latest'] / data['results'][benchname][data['baseline']]; - // Drop a benchmark the latest run is missing before pushing its - // label, so the bars stay aligned with the x axis ticks. - // (!(rel > 0) also catches the NaN from a missing value.) + // (!(rel > 0) also catches the NaN from a missing value) if (!(rel > 0)) { continue; } - benchmarks.push(benchname); - latestValues.push(rel); - baselineValues.push(1.0); + rows.push({name: benchname, rel: rel}); } - if (benchmarks.length === 0) { + if (rows.length === 0) { wrap.innerHTML = 'No complete benchmark run available yet'; return; } + rows.sort(function(x, y) { return x.rel - y.rel; }); + plotData = {rows: rows, baseline: data['baseline']}; + drawChart(); + } + + // On our own home page the title carries this link; elsewhere (pypy.org) + // it is the only way to the benchmarks the plot leaves out + function embeddedOnOwnSite() { + try { return window.parent !== window && !!window.parent.document; } + catch (e) { return false; } + } + + function drawChart() { + var rows = plotData.rows; + var keep = isNarrow() ? 10 : 20; + var shown = rows; + if (rows.length > 2 * keep) { + shown = rows.slice(0, keep).concat([null], rows.slice(rows.length - keep)); + } + var labels = shown.map(function(r) { return r ? r.name : '\u2026'; }); + // Floating bars from the baseline at 1.0, so faster runs hang below it + var bars = shown.map(function(r) { return r ? [1, r.rel] : null; }); + var gap = shown.indexOf(null); + var scale = fontScale(); + Chart.defaults.font.size = Math.round(12 * scale); + // Mark the gap on the plot itself, not just on the axis + var gapMarker = { + id: 'gapMarker', + afterDatasetsDraw: function(chart) { + if (gap === -1) { return; } + var ctx = chart.ctx; + ctx.save(); + ctx.font = 'bold ' + Math.round(32 * scale) + 'px sans-serif'; + ctx.fillStyle = Chart.defaults.color; + ctx.textAlign = 'center'; + ctx.textBaseline = 'bottom'; + ctx.fillText('\u2026', chart.scales.x.getPixelForValue(gap), + chart.scales.y.getPixelForValue(1) - 4); + ctx.restore(); + } + }; + if (comparisonChart) { comparisonChart.destroy(); } + var wrap = document.getElementById('baseline-comparison-plot'); + wrap.innerHTML = ''; var canvas1 = document.createElement('canvas'); wrap.appendChild(canvas1); + $('#full-results').prop('hidden', embeddedOnOwnSite() || shown.length === rows.length); + // Let the embedding page title the plot with how much of it is shown + if (window.parent !== window) { + window.parent.postMessage({codespeedBenchmarks: { + total: rows.length, shown: shown.length - (gap === -1 ? 0 : 1) + }}, '*'); + } comparisonChart = new Chart(canvas1, { type: 'bar', + plugins: [gapMarker], data: { - labels: benchmarks, + labels: labels, datasets: [ - {label: 'latest {{ default_exe }}', data: latestValues, backgroundColor: '#4e79a7'}, - {label: data['baseline'], data: baselineValues, type: 'line', + {label: 'latest {{ default_exe }}', data: bars, backgroundColor: '#4e79a7'}, + {label: plotData.baseline, data: shown.map(function() { return 1; }), type: 'line', borderColor: '#f28e2b', backgroundColor: 'transparent', pointRadius: 0, borderWidth: 2, fill: false} ] @@ -115,18 +178,44 @@ responsive: true, maintainAspectRatio: false, plugins: { - tooltip: {position: 'cursor'} + tooltip: { + position: 'cursor', + filter: function(item) { return item.datasetIndex === 0; }, + callbacks: { + label: function(ctx) { + var rel = ctx.raw[1]; + return rel.toFixed(2) + ' (' + (rel < 1 + ? (1 / rel).toFixed(1) + 'x faster)' + : rel.toFixed(1) + 'x slower)'); + } + } + } }, scales: { - x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false, font: {size: 11}}}, - y: {min: 0, max: 2.0, ticks: {callback: function(v) { return v.toFixed(2); }}} + x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false, + font: function(c) { + return c.index === gap ? {size: Math.round(20 * scale), weight: 'bold'} + : {size: Math.round(11 * scale)}; + }}}, + y: {type: 'logarithmic', + min: 0.005, max: 5, + title: {display: true, + text: 'Relative time (log scale)'}, + ticks: {callback: function(v) { + var m = v / Math.pow(10, Math.floor(Math.log10(v) + 1e-9)); + return [1, 2, 5].some(function(k) { return Math.abs(m - k) < 1e-6; }) + ? String(+v.toPrecision(2)) : ''; + }}} } } }); } + window.addEventListener('resize', function() { + if (plotData && isNarrow() !== wasNarrow) { wasNarrow = isNarrow(); drawChart(); } + }); $(function() { - $.getJSON("{% url 'gethistoricaldata' %}", renderplot); + $.getJSON("{% url 'gethistoricaldata' %}", {source: '{{ source }}'}, renderplot); }); diff --git a/speed_pypy/templates/home.html b/speed_pypy/templates/home.html index 9b3fc228..eb17720f 100644 --- a/speed_pypy/templates/home.html +++ b/speed_pypy/templates/home.html @@ -28,21 +28,55 @@Plot 1: The above plot represents {{ default_exe.project }} ({{ default_exe }}) benchmark times normalized to {{ baseline }}. Smaller is better.
-It depends greatly on the type of task being performed. The geometric average of all benchmarks is or times faster than {{ baseline }}
+ {% for source, label, url in sources %} +{{ default_exe.project }} ({{ default_exe }}) benchmark times normalized to {{ baseline }}. Smaller is better.
+Performance depends greatly on the type of task being performed. The geometric average is{% for source, label, url in sources %}{% if not forloop.first %}{% if forloop.last %} and{% else %},{% endif %}{% endif %} or times faster for the {{ label }} benchmarks{% endfor %}, compared to {{ baseline }}.
Plot 2: Speedup compared to {{ baseline }}, using the inverse of the geometric average of normalized times, out of benchmarks (see paper on why the geometric mean is better for normalized results).
+Speedup compared to {{ baseline }}, using the inverse of the geometric average of normalized times, out of{% for source, label, url in sources %}{% if not forloop.first %} and{% endif %} {{ label }}{% endfor %} benchmarks (see paper on why the geometric mean is better for normalized results). Larger is better.