Commit f88dabeb by Harry Marr

Bold trace file names, insert traces

parent 6dca94d0
...@@ -42,10 +42,12 @@ def _insert(collection_self, doc_or_docs, manipulate=True, ...@@ -42,10 +42,12 @@ def _insert(collection_self, doc_or_docs, manipulate=True,
) )
total_time = (time.time() - start_time) * 1000 total_time = (time.time() - start_time) * 1000
__traceback_hide__ = True
inserts.append({ inserts.append({
'document': doc_or_docs, 'document': doc_or_docs,
'safe': safe, 'safe': safe,
'time': total_time, 'time': total_time,
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
}) })
return result return result
...@@ -65,6 +67,7 @@ def _update(collection_self, spec, document, upsert=False, ...@@ -65,6 +67,7 @@ def _update(collection_self, spec, document, upsert=False,
) )
total_time = (time.time() - start_time) * 1000 total_time = (time.time() - start_time) * 1000
__traceback_hide__ = True
updates.append({ updates.append({
'document': document, 'document': document,
'upsert': upsert, 'upsert': upsert,
...@@ -72,6 +75,7 @@ def _update(collection_self, spec, document, upsert=False, ...@@ -72,6 +75,7 @@ def _update(collection_self, spec, document, upsert=False,
'spec': spec, 'spec': spec,
'safe': safe, 'safe': safe,
'time': total_time, 'time': total_time,
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
}) })
return result return result
...@@ -87,10 +91,12 @@ def _remove(collection_self, spec_or_id, safe=False, **kwargs): ...@@ -87,10 +91,12 @@ def _remove(collection_self, spec_or_id, safe=False, **kwargs):
) )
total_time = (time.time() - start_time) * 1000 total_time = (time.time() - start_time) * 1000
__traceback_hide__ = True
removes.append({ removes.append({
'spec_or_id': spec_or_id, 'spec_or_id': spec_or_id,
'safe': safe, 'safe': safe,
'time': total_time, 'time': total_time,
'stack_trace': _tidy_stacktrace(reversed(inspect.stack())),
}) })
return result return result
......
...@@ -48,11 +48,11 @@ table.mongo-op-table tbody { ...@@ -48,11 +48,11 @@ table.mongo-op-table tbody {
<td><pre class="mongo-highlight">{% if query.ordering %}{{ query.ordering }}{% endif %}</pre></td> <td><pre class="mongo-highlight">{% if query.ordering %}{{ query.ordering }}{% endif %}</pre></td>
<td>{% if query.skip %}{{ query.skip }}{% endif %}</td> <td>{% if query.skip %}{{ query.skip }}{% endif %}</td>
<td>{% if query.limit %}{{ query.limit }}{% endif %}</td> <td>{% if query.limit %}{{ query.limit }}{% endif %}</td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="{{ forloop.counter }}">Toggle</a></td> <td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="queries-{{ forloop.counter }}">Toggle</a></td>
</tr> </tr>
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}"> <tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td colspan="8"> <td colspan="8">
<table class="mongo-stack-trace "id="mongo-stack-trace-{{ forloop.counter }}"> <table class="mongo-stack-trace "id="mongo-stack-trace-queries-{{ forloop.counter }}">
<thead> <thead>
<tr> <tr>
<th>Line</th> <th>Line</th>
...@@ -65,14 +65,13 @@ table.mongo-op-table tbody { ...@@ -65,14 +65,13 @@ table.mongo-op-table tbody {
{% for line in query.stack_trace %} {% for line in query.stack_trace %}
<tr> <tr>
<td class="lineno">{{ line.1 }}</td> <td class="lineno">{{ line.1 }}</td>
<td class="file">{{ line.0 }}</td> <td class="file">{{ line.0|embolden_file }}</td>
<td class="function">{{ line.2 }}</td> <td class="function">{{ line.2 }}</td>
<td class="code">{{ line.3|highlight:"python"|safe }}</td> <td class="code">{{ line.3|highlight:"python"|safe }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<!--<pre class="mongo-stack-trace">{{ query.stack_trace|format_stack_trace }}</pre>-->
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
...@@ -90,6 +89,7 @@ table.mongo-op-table tbody { ...@@ -90,6 +89,7 @@ table.mongo-op-table tbody {
<th>Time (ms)</th> <th>Time (ms)</th>
<th>Document</th> <th>Document</th>
<th>Safe</th> <th>Safe</th>
<th>Stack Trace</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -100,6 +100,31 @@ table.mongo-op-table tbody { ...@@ -100,6 +100,31 @@ table.mongo-op-table tbody {
<pre class="mongo-highlight">{{ insert.document|format_dict:120|highlight:"javascript"|safe }}</pre> <pre class="mongo-highlight">{{ insert.document|format_dict:120|highlight:"javascript"|safe }}</pre>
</td> </td>
<td>{{ insert.safe }}</td> <td>{{ insert.safe }}</td>
<td><a href="javascript:void(0);" class="mongo-toggle-trace" data-row="inserts-{{ forloop.counter }}">Toggle</a></td>
</tr>
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
<td colspan="4">
<table class="mongo-stack-trace "id="mongo-stack-trace-inserts-{{ forloop.counter }}">
<thead>
<tr>
<th>Line</th>
<th>File</th>
<th>Function</th>
<th>Code</th>
</tr>
</thead>
<tbody>
{% for line in insert.stack_trace %}
<tr>
<td class="lineno">{{ line.1 }}</td>
<td class="file">{{ line.0|embolden_file }}</td>
<td class="function">{{ line.2 }}</td>
<td class="code">{{ line.3|highlight:"python"|safe }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
......
...@@ -3,6 +3,7 @@ from django.utils.html import escape ...@@ -3,6 +3,7 @@ from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
import pprint import pprint
import os
register = template.Library() register = template.Library()
...@@ -20,6 +21,11 @@ def format_stack_trace(value): ...@@ -20,6 +21,11 @@ def format_stack_trace(value):
return mark_safe('\n'.join(stack_trace)) return mark_safe('\n'.join(stack_trace))
@register.filter @register.filter
def embolden_file(path):
head, tail = os.path.split(escape(path))
return mark_safe(os.sep.join([head, '<strong>{0}</strong>'.format(tail)]))
@register.filter
def format_dict(value, width=60): def format_dict(value, width=60):
return pprint.pformat(value, width=int(width)) return pprint.pformat(value, width=int(width))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment