Refined the sql debug info, making the table of queries sortable and adding duplication counts and accumulated query time.
- Legacy-Id: 12068
This commit is contained in:
parent
ff5866367b
commit
9e18351a0b
ietf
|
@ -631,3 +631,22 @@ def comma_separated_list(seq, end_word="and"):
|
|||
@register.filter()
|
||||
def role_names(roles):
|
||||
return list(set([ "%s %s" % (r.group.name, r.name.name) for r in roles ]))
|
||||
|
||||
@register.filter()
|
||||
def annotate_sql_queries(queries):
|
||||
counts = {}
|
||||
timeacc = {}
|
||||
for q in queries:
|
||||
sql = q['sql']
|
||||
if not sql in counts:
|
||||
counts[sql] = 0;
|
||||
counts[sql] += 1
|
||||
if not sql in timeacc:
|
||||
timeacc[sql] = 0.0;
|
||||
timeacc[sql] += float(q['time'])
|
||||
for q in queries:
|
||||
sql = q['sql']
|
||||
q['count'] = str(counts[sql])
|
||||
q['time_accum'] = "%4.3f" % timeacc[sql]
|
||||
return queries
|
||||
|
||||
|
|
|
@ -13,22 +13,28 @@
|
|||
onclick="$('#debug-query-table').toggleClass('hide');">Show</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
<table class="table table-condensed table-striped hide" id="debug-query-table">
|
||||
<table class="table table-condensed table-striped tablesorter hide" id="debug-query-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>SQL</th>
|
||||
<th>Time</th>
|
||||
<th data-header="sequence">#</th>
|
||||
<th data-header="query">SQL</th>
|
||||
<th data-header="count">Count</th>
|
||||
<th data-header="time">Time</th>
|
||||
<th data-header="acc">Acc.</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for query in sql_queries %}
|
||||
<tr>
|
||||
<td>{{ forloop.counter }}</td>
|
||||
<td>{{ query.sql|expand_comma|escape }}</td>
|
||||
<td>{{ query.time }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% with sql_queries|annotate_sql_queries as sql_query_info %}
|
||||
{% for query in sql_query_info %}
|
||||
<tr>
|
||||
<td>{{ forloop.counter }}</td>
|
||||
<td>{{ query.sql|expand_comma|escape }}</td>
|
||||
<td>{{ query.count }}</td>
|
||||
<td>{{ query.time }}</td>
|
||||
<td>{{ query.time_accum }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue