Added stack trace to debug toolbar

This commit is contained in:
Alexander Pinnecke 2015-04-10 17:52:41 +02:00
parent c6e7355f7a
commit 2fc716467b
2 changed files with 66 additions and 1 deletions

View file

@ -64,6 +64,7 @@ class PropelLogger implements LoggerInterface
}
$add = true;
$stackTrace = $this->getStackTrace();
if (null !== $this->stopwatch) {
$trace = debug_backtrace();
@ -90,6 +91,7 @@ class PropelLogger implements LoggerInterface
'connection' => $connection->getName(),
'time' => $event->getDuration() / 1000,
'memory' => $event->getMemory(),
'stackTrace' => $stackTrace,
);
}
@ -100,4 +102,25 @@ class PropelLogger implements LoggerInterface
{
return $this->queries;
}
/**
* Returns the current stack trace.
*
* @return array
*/
private function getStackTrace()
{
$e = new \Exception();
$trace = explode("\n", $e->getTraceAsString());
$trace = array_reverse($trace);
array_shift($trace); // remove {main}
array_pop($trace); // remove call to this method
foreach ($trace as $i => &$value) {
$value = $i + 1 . ')' . substr($value, strpos($value, ' '));
$value = preg_replace('/\((\d+)\)/', ':$1', $value, 1);
}
return $trace;
}
}

View file

@ -65,8 +65,38 @@
font-size: 17px;
margin-bottom: 0;
}
.query-trace {
display: none;
overflow: auto;
padding: 5px;
border: 1px solid silver;
margin: 5px;
border-radius: 5px;
font-family: monospace;
white-space: nowrap;
color: #333;
}
.query-trace .gray {
color: silver;
}
.query-trace .gray + .regular {
margin-top: 3px;
}
.query-trace .regular + .gray {
margin-top: 3px;
}
</style>
<script>
function toggle(id) {
var el = document.getElementById(id);
el.style.display = el.style.display === 'block' ? 'none' : 'block';
}
</script>
<h2>Queries</h2>
<table summary="Show logged queries">
<thead>
@ -94,12 +124,24 @@
</div>
{% endif %}
<div class="SQLInfo">
Time: {{ query.time }} - Memory: {{ query.memory|format_memory }} - Connection: {{ query.connection }}
Time: {{ query.time }} - Memory: {{ query.memory|format_memory }} - Connection: {{ query.connection }} -
<a href="#" onclick="toggle('propel-stack-trace-{{ i }}'); return false;">Stacktrace</a>
{% if app.request.query.get('query', -1) != i %}
- <a href="{{ path('_profiler', {'panel': 'propel', 'token': token, 'connection': query.connection, 'query': i}) }}#propel-query-{{ i }}">Explain the query</a>
{% endif %}
</div>
<div id="propel-stack-trace-{{ i }}" class="query-trace">
{% for trace in query.stackTrace %}
<div class="{{
(': Symfony\\Component' in trace
or ': Propel\\Runtime' in trace
or ': Propel\\PropelBundle' in trace
or ': call_user_func(Object(Symfony\\Component' in trace
or ': call_user_func(Array, Object(Symfony\\Component' in trace
) ? 'gray' : 'regular' }}">{{ trace }}</div>
{% endfor %}
</div>
</td>
</tr>
{% endfor %}