Skip to content

Commit 12b0546

Browse files
committed
Added backtrace support to Amp SQL profiler.
1 parent 873c799 commit 12b0546

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/SqlProfiler/SqlQuery.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
final class SqlQuery
99
{
10+
public array $backtrace;
11+
1012
public function __construct(
1113
public string $sql,
1214
public float $executionMS,
1315
public array|Data $params = [],
1416
) {
17+
$this->backtrace = array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 1);
1518
}
1619
}

templates/amp sql profiler/amp sql profiler.html.twig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,44 @@
8080
<div>
8181
<strong class="font-normal text-small">Parameters</strong>: {{ profiler_dump(query.params, 2) }}
8282
</div>
83+
84+
<div class="text-small font-normal">
85+
<a href="#" class="sf-toggle link-inverse"
86+
data-toggle-selector="#backtrace-{{ loop.index }}"
87+
data-toggle-alt-content="Hide query backtrace">View query backtrace</a>
88+
</div>
89+
90+
<div id="backtrace-{{ loop.index }}" class="hidden">
91+
<table>
92+
<thead>
93+
<tr>
94+
<th scope="col">#</th>
95+
<th scope="col">File/Call</th>
96+
</tr>
97+
</thead>
98+
<tbody>
99+
{% for trace in query.backtrace %}
100+
<tr>
101+
<td>{{ loop.index }}</td>
102+
<td>
103+
<span class="text-small">
104+
{% set line_number = trace.line|default(1) %}
105+
{% if trace.file is defined %}
106+
<a href="{{ trace.file|file_link(line_number) }}">
107+
{% endif %}
108+
{{- trace.class is defined ? trace.class ~ trace.type|default('::') -}}
109+
<span class="status-warning">{{ trace.function }}</span>
110+
{%- if trace.file is defined -%}
111+
</a>
112+
{% endif %}
113+
(line {{ line_number }})
114+
</span>
115+
</td>
116+
</tr>
117+
{% endfor %}
118+
</tbody>
119+
</table>
120+
</div>
83121
</td>
84122
</tr>
85123
{% endfor %}

0 commit comments

Comments
 (0)