Skip to content

Commit 9e18351

Browse files
committed
Refined the sql debug info, making the table of queries sortable and adding duplication counts and accumulated query time.
- Legacy-Id: 12068
1 parent ff58663 commit 9e18351

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

ietf/doc/templatetags/ietf_filters.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,22 @@ def comma_separated_list(seq, end_word="and"):
631631
@register.filter()
632632
def role_names(roles):
633633
return list(set([ "%s %s" % (r.group.name, r.name.name) for r in roles ]))
634+
635+
@register.filter()
636+
def annotate_sql_queries(queries):
637+
counts = {}
638+
timeacc = {}
639+
for q in queries:
640+
sql = q['sql']
641+
if not sql in counts:
642+
counts[sql] = 0;
643+
counts[sql] += 1
644+
if not sql in timeacc:
645+
timeacc[sql] = 0.0;
646+
timeacc[sql] += float(q['time'])
647+
for q in queries:
648+
sql = q['sql']
649+
q['count'] = str(counts[sql])
650+
q['time_accum'] = "%4.3f" % timeacc[sql]
651+
return queries
652+

ietf/templates/debug.html

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@
1313
onclick="$('#debug-query-table').toggleClass('hide');">Show</a>
1414
{% endif %}
1515
</p>
16-
<table class="table table-condensed table-striped hide" id="debug-query-table">
16+
<table class="table table-condensed table-striped tablesorter hide" id="debug-query-table">
1717
<thead>
1818
<tr>
19-
<th>#</th>
20-
<th>SQL</th>
21-
<th>Time</th>
19+
<th data-header="sequence">#</th>
20+
<th data-header="query">SQL</th>
21+
<th data-header="count">Count</th>
22+
<th data-header="time">Time</th>
23+
<th data-header="acc">Acc.</th>
2224
</tr>
2325
</thead>
2426
<tbody>
25-
{% for query in sql_queries %}
26-
<tr>
27-
<td>{{ forloop.counter }}</td>
28-
<td>{{ query.sql|expand_comma|escape }}</td>
29-
<td>{{ query.time }}</td>
30-
</tr>
31-
{% endfor %}
27+
{% with sql_queries|annotate_sql_queries as sql_query_info %}
28+
{% for query in sql_query_info %}
29+
<tr>
30+
<td>{{ forloop.counter }}</td>
31+
<td>{{ query.sql|expand_comma|escape }}</td>
32+
<td>{{ query.count }}</td>
33+
<td>{{ query.time }}</td>
34+
<td>{{ query.time_accum }}</td>
35+
</tr>
36+
{% endfor %}
37+
{% endwith %}
3238
</tbody>
3339
</table>
3440
</div>

0 commit comments

Comments
 (0)