Skip to content

Commit

Permalink
Cache result table in reports
Browse files Browse the repository at this point in the history
  • Loading branch information
tobami committed Jan 14, 2011
1 parent e730d1f commit 35b09cd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
34 changes: 28 additions & 6 deletions speedcenter/codespeed/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.utils import simplejson as json
from codespeed import settings

class Project(models.Model):
Expand Down Expand Up @@ -101,15 +102,16 @@ class Report(models.Model):
executable = models.ForeignKey(Executable)
summary = models.CharField(max_length=30, default="none")
colorcode = models.CharField(max_length=10, default="none")
tablecache = models.CharField(max_length=10, default="none")
_tablecache = models.TextField(blank=True)

def __unicode__(self):
return "Report for " + str(self.revision.commitid)

class Meta:
unique_together = ("revision", "executable", "environment")

def save(self, *args, **kwargs):
tablelist = self.get_changes_table()
tablelist = self.get_changes_table(force_save=True)
max_change, max_change_ben, max_change_color = 0, None, "none"
max_trend, max_trend_ben, max_trend_color = 0, None, "none"
average_change, average_change_units, average_change_color = 0, None, "none"
Expand Down Expand Up @@ -153,7 +155,7 @@ def save(self, *args, **kwargs):
if self.is_big_change(val, color, max_change, max_change_color):
# Do update biggest single change
max_change = val
max_change_ben = row['benchmark']
max_change_ben = row['bench_name']
max_change_color = color
# Single trend
val = row['trend']
Expand All @@ -163,7 +165,7 @@ def save(self, *args, **kwargs):
if self.is_big_change(val, color, max_trend, max_trend_color):
# Do update biggest single trend change
max_trend = val
max_trend_ben = row['benchmark']
max_trend_ben = row['bench_name']
max_trend_color = color
# Reinitialize
self.summary = "none"
Expand Down Expand Up @@ -225,7 +227,16 @@ def getcolorcode(self, val, lessisbetter, threshold):
colorcode = "green"
return colorcode;

def get_changes_table(self, trend_depth=10):
def get_changes_table(self, trend_depth=10, force_save=False):
# Determine whether required trend value is the default one
default_trend = 10
if hasattr(settings, 'trend') and settings.trend:
default_trend = settings.trend
# If the trend is the default and a forced save is not required
# just return the cached changes table
if not force_save and trend_depth == default_trend:
return self._get_tablecache()

lastrevisions = Revision.objects.filter(
project=self.executable.project
).filter(
Expand Down Expand Up @@ -321,7 +332,8 @@ def get_changes_table(self, trend_depth=10):
smallest = result

currentlist.append({
'benchmark': bench,
'bench_name': bench.name,
'bench_description': bench.description,
'result': result,
'std_dev': std_dev,
'val_min': val_min,
Expand Down Expand Up @@ -359,4 +371,14 @@ def get_changes_table(self, trend_depth=10):
'totals': totals,
'rows': currentlist
})
if force_save:
self._save_tablecache(tablelist)
return tablelist

def _save_tablecache(self, data):
self._tablecache = json.dumps(data)

def _get_tablecache(self):
if self._tablecache == '':
return {}
return json.loads(self._tablecache)
3 changes: 3 additions & 0 deletions speedcenter/codespeed/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Given as the name of the executable and commitid of the revision
# Example: defaultbaseline = {'executable': 'myexe', 'revision': '21'}

trend = 10 # Default value for the depth of the trend
# Used by reports for the latest runs and changes view

# Threshold that determines when a performance change over the last result is significant
change_threshold = 3.0

Expand Down
2 changes: 1 addition & 1 deletion speedcenter/codespeed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def reports(request):
if request.method != 'GET': return HttpResponseNotAllowed('GET')

return render_to_response('codespeed/reports.html', {
'reports': Report.objects.all().order_by('-revision')[:15],
'reports': Report.objects.all().order_by('-revision')[:10],
})

def displaylogs(request):
Expand Down
4 changes: 2 additions & 2 deletions speedcenter/templates/codespeed/changes_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</tr>
</tfoot>
<tbody>
{% for row in units.rows %} <tr>
<td class="text" title="{{ row.benchmark.description }}">{{ row.benchmark.name }}</td>
{% for row in units.rows|dictsort:"bench_name" %} <tr>
<td class="text" title="{{ row.bench_description }}">{{ row.bench_name }}</td>
<td>{{ row.result|floatformat:units.precission }}</td>
{% if units.has_stddev %}<td>{{ row.std_dev|floatformat:units.precission }}</td>
{% endif%}{% if units.hasmin %}<td>{{ row.val_min|floatformat:units.precission }}</td>
Expand Down
11 changes: 11 additions & 0 deletions speedcenter/templates/codespeed/reports.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% if reports|length %}
<table class="reports">
<caption>Latest runs</caption>
<tbody>
{% for report in reports %} <tr class="status-{{ report.colorcode }}">
<td><label title="lessisbetter" style="display:none;">rev={{ report.revision.commitid }}&exe= {{ report.executable.id }}&env={{ report.environment.name }}</label>{{ report.revision }}</td><td>{{ report.executable }}@{{ report.environment}}</td>
<td class="summary">{% ifequal report.summary "none" %}<span class="nochanges">no significant changes</span>{% else %}{{ report.summary }}{% endifequal %}</td>
</tr>{% endfor %}
</tbody>
</table>
{% endif %}
7 changes: 3 additions & 4 deletions speedcenter/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% block body %}

{% block script %}
<script type="text/javascript">
function permalinkToChanges(permalink) {
Expand All @@ -26,13 +26,13 @@
$("#changes").click(function () { window.location="/changes/"; });
$("#timeline").click(function () { window.location="/timeline/"; });
$("#comparison").click(function () { window.location="/comparison/"; });
$("#reports")
.html(getLoadText("Loading...", 0, true))
$("#reports").html(getLoadText("Loading...", 0, true))
.load("reports/", function(responseText) { updateTable(); });
});
</script>
{% endblock %}

{% block body %}
<div id="presentation" class="clearfix">
<div id="changes" class="menubox">
<h2>Changes</h2>
Expand All @@ -49,5 +49,4 @@ <h2>Comparison</h2>
<br />
<div id="reports"></div>
</div>

{% endblock %}

0 comments on commit 35b09cd

Please sign in to comment.