Merge pull request #336 from apinnecke/feature/stack-trace-in-debug-toolbar
Added stack trace to debug toolbar
This commit is contained in:
commit
e3398133b1
|
@ -64,6 +64,7 @@ class PropelLogger implements LoggerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
$add = true;
|
$add = true;
|
||||||
|
$stackTrace = $this->getStackTrace();
|
||||||
|
|
||||||
if (null !== $this->stopwatch) {
|
if (null !== $this->stopwatch) {
|
||||||
$trace = debug_backtrace();
|
$trace = debug_backtrace();
|
||||||
|
@ -90,6 +91,7 @@ class PropelLogger implements LoggerInterface
|
||||||
'connection' => $connection->getName(),
|
'connection' => $connection->getName(),
|
||||||
'time' => $event->getDuration() / 1000,
|
'time' => $event->getDuration() / 1000,
|
||||||
'memory' => $event->getMemory(),
|
'memory' => $event->getMemory(),
|
||||||
|
'stackTrace' => $stackTrace,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,4 +102,25 @@ class PropelLogger implements LoggerInterface
|
||||||
{
|
{
|
||||||
return $this->queries;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,38 @@
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
margin-bottom: 0;
|
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>
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function toggle(id) {
|
||||||
|
var el = document.getElementById(id);
|
||||||
|
el.style.display = el.style.display === 'block' ? 'none' : 'block';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<h2>Queries</h2>
|
<h2>Queries</h2>
|
||||||
<table summary="Show logged queries">
|
<table summary="Show logged queries">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -94,12 +124,24 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="SQLInfo">
|
<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 %}
|
{% 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>
|
- <a href="{{ path('_profiler', {'panel': 'propel', 'token': token, 'connection': query.connection, 'query': i}) }}#propel-query-{{ i }}">Explain the query</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue