Skip to content

Commit f661d20

Browse files
Generate a page with baseline comparison for pypy.org
1 parent 7121c01 commit f661d20

4 files changed

Lines changed: 109 additions & 0 deletions

File tree

codespeed/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
]
1515

1616
urlpatterns += [
17+
re_path(r'^embed/comparison/$', views.embed_comparison, name='embed-comparison'),
1718
re_path(r'^historical/json/$', views.gethistoricaldata, name='gethistoricaldata'),
1819
re_path(r'^reports/$', views.reports, name='reports'),
1920
re_path(r'^changes/$', views.changes, name='changes'),

codespeed/views.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.shortcuts import get_object_or_404, render
1717
from django.views.decorators.http import require_GET, require_POST
1818
from django.views.decorators.csrf import csrf_exempt
19+
from django.views.decorators.clickjacking import xframe_options_exempt
1920
from django.views.generic.base import TemplateView
2021

2122
from .auth import basic_auth_required
@@ -93,6 +94,24 @@ def get_context_data(self, **kwargs):
9394
return context
9495

9596

97+
@require_GET
98+
@xframe_options_exempt
99+
def embed_comparison(request):
100+
"""Frame-exempt page rendering only the baseline-comparison
101+
for embedding on pypy.org"""
102+
context = {}
103+
try:
104+
context['baseline'] = Executable.objects.get(
105+
name=settings.DEF_BASELINES[0]['executable'])
106+
def_name = settings.DEF_EXECUTABLES[0]['name']
107+
def_project = Project.objects.get(name=settings.DEF_EXECUTABLES[0]['project'])
108+
context['default_exe'] = Executable.objects.get(
109+
name=def_name, project=def_project)
110+
except Exception as e:
111+
logger.error('embed_comparison: %s', e)
112+
return render(request, 'embed_comparison.html', context)
113+
114+
96115
@require_GET
97116
def gethistoricaldata(request):
98117
data = {'results': {}, 'benchmarks': []}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>PyPy vs CPython benchmark comparison</title>
8+
<style>
9+
html, body { margin: 0; padding: 0; background: transparent; }
10+
#baseline-comparison-plot {
11+
position: relative;
12+
width: 100%;
13+
height: 480px;
14+
font-family: sans-serif;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div id="baseline-comparison-plot"></div>
20+
21+
<script type="text/javascript" src="{% static 'js/jquery-1.12.3.min.js' %}"></script>
22+
<script type="text/javascript" src="{% static 'js/chart.umd.min.js' %}"></script>
23+
<script type="text/javascript">
24+
Chart.Tooltip.positioners.cursor = function(_items, eventPosition) {
25+
return {x: eventPosition.x, y: eventPosition.y};
26+
};
27+
28+
function renderplot(data) {
29+
var wrap = document.getElementById('baseline-comparison-plot');
30+
if (data === null || data.length === 0 ||
31+
typeof data === 'string' || data instanceof String) {
32+
wrap.innerHTML = 'Error retrieving data';
33+
return;
34+
}
35+
36+
var benchmarks = [], latestValues = [], baselineValues = [];
37+
var tagged_data = [];
38+
for (var i in data['tagged_revs']) { tagged_data[i] = []; }
39+
40+
for (var bench in data['benchmarks']) {
41+
var benchname = data['benchmarks'][bench];
42+
var add_to_tagged_data = true;
43+
for (var i in data['tagged_revs']) {
44+
var rev = data['tagged_revs'][i];
45+
if (data['results'][benchname][rev] === 0) { add_to_tagged_data = false; break; }
46+
tagged_data[i].push(data['results'][benchname][rev] / data['results'][benchname][data['baseline']]);
47+
}
48+
if (!add_to_tagged_data) { continue; }
49+
benchmarks.push(benchname);
50+
var rel = data['results'][benchname]['latest'] / data['results'][benchname][data['baseline']];
51+
latestValues.push(rel);
52+
baselineValues.push(1.0);
53+
}
54+
55+
var canvas1 = document.createElement('canvas');
56+
wrap.appendChild(canvas1);
57+
new Chart(canvas1, {
58+
type: 'bar',
59+
data: {
60+
labels: benchmarks,
61+
datasets: [
62+
{label: 'latest {{ default_exe }}', data: latestValues, backgroundColor: '#4e79a7'},
63+
{label: data['baseline'], data: baselineValues, type: 'line',
64+
borderColor: '#f28e2b', backgroundColor: 'transparent',
65+
pointRadius: 0, borderWidth: 2, fill: false}
66+
]
67+
},
68+
options: {
69+
animation: false,
70+
responsive: true,
71+
maintainAspectRatio: false,
72+
plugins: {
73+
tooltip: {position: 'cursor'}
74+
},
75+
scales: {
76+
x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false, font: {size: 11}}},
77+
y: {min: 0, max: 2.0, ticks: {callback: function(v) { return v.toFixed(2); }}}
78+
}
79+
}
80+
});
81+
}
82+
83+
$(function() {
84+
$.getJSON("{% url 'gethistoricaldata' %}", renderplot);
85+
});
86+
</script>
87+
</body>
88+
</html>

speed_pypy/templates/home.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ <h3>How has PyPy performance evolved over time?</h3>
102102
$('#geofaster').html((1 / trunk_geomean).toFixed(1));
103103

104104
// Plot 1: per-benchmark normalized comparison
105+
// Needs to be kept in sync with the plot in embed_comparison.html
105106
var wrap1 = document.getElementById('baseline-comparison-plot');
106107
var canvas1 = document.createElement('canvas');
107108
wrap1.appendChild(canvas1);

0 commit comments

Comments
 (0)