Skip to content

Commit bfa466e

Browse files
committed
Pretty render backtrace
1 parent 077fd94 commit bfa466e

File tree

2 files changed

+64
-59
lines changed

2 files changed

+64
-59
lines changed

src/DataCollector/MongoDBDataCollector.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
use function array_map;
3434
use function array_sum;
3535
use function count;
36-
use function debug_backtrace;
37-
use function dump;
3836
use function iterator_to_array;
3937

4038
use const DEBUG_BACKTRACE_IGNORE_ARGS;
@@ -80,8 +78,6 @@ public function lateCollect(): void
8078
'errorCount' => array_sum(array_map(static fn (array $requests) => count(array_column($requests, 'error')), $this->requests)),
8179
'durationMicros' => array_sum(array_map(static fn (array $requests) => array_sum(array_column($requests, 'durationMicros')), $this->requests)),
8280
];
83-
84-
dump($this->data, array_column(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 'class'));
8581
}
8682

8783
public function getRequestCount(): int

templates/Collector/mongodb.html.twig

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22

33
{% import _self as helper %}
44

5+
{% block head %}
6+
{{ parent() }}
7+
8+
<style>
9+
10+
#collector-content .sf-toggle { cursor: pointer; position: relative; }
11+
#collector-content .sf-toggle-off .icon-close, .sf-toggle-on .icon-open { display: none; }
12+
#collector-content .sf-toggle-off .icon-open, .sf-toggle-on .icon-close { display: block; }
13+
14+
#collector-content .trace-details { background: var(--base-0); border: var(--border); box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); margin: 0 0 1em; table-layout: fixed; }
15+
16+
#collector-content .trace-line .icon { opacity: .4; position: absolute; left: 10px; }
17+
#collector-content .trace-line .icon svg { fill: var(--base-5); height: 16px; width: 16px; }
18+
#collector-content .trace { background: var(--base-0); padding: 10px; margin: 0.5em 0; overflow: auto; font-size: 12px; }
19+
#collector-content .trace-method { color: var(--highlight-keyword); font-weight: bold; }
20+
#collector-content .trace li { margin-bottom: 0; padding: 0; }
21+
#collector-content .trace li.selected { background: var(--trace-selected-background); margin-top: 2px; }
22+
#collector-content .trace + .trace { margin-top: 30px; }
23+
#collector-content .trace-line { position: relative; margin: 0; padding-top: 8px; padding-bottom: 8px; }
24+
#collector-content .trace-line + .trace-line { border-top: var(--border); }
25+
#collector-content .trace-line:hover { background: var(--base-1); }
26+
#collector-content .trace-line a { color: var(--base-6); }
27+
#collector-content .trace-line .icon { opacity: .4; position: absolute; left: 10px; }
28+
#collector-content .trace-line .icon svg { fill: var(--base-5); height: 16px; width: 16px; }
29+
#collector-content .trace-line .icon.icon-copy { left: auto; top: auto; padding-left: 5px; display: none }
30+
#collector-content .trace-line-header { padding-left: 36px; padding-right: 10px; }
31+
</style>
32+
{% endblock %}
33+
534
{% block toolbar %}
635
{% if collector.requestCount > 0 %}
736

@@ -112,19 +141,8 @@
112141
<div class="text-small font-normal">
113142
<a href="#" class="sf-toggle link-inverse" data-toggle-selector="#formatted-request-{{ i }}-{{ loop.parent.loop.index }}" data-toggle-alt-content="Hide formatted request">View formatted request</a>
114143

115-
{#
116-
{% if request.runnable %}
117-
&nbsp;&nbsp;
118-
<a href="#" class="sf-toggle link-inverse" data-toggle-selector="#original-request-{{ i }}-{{ loop.parent.loop.index }}" data-toggle-alt-content="Hide runnable request">View runnable request</a>
119-
{% endif %}
120-
121-
{% if request.explainable %}
122-
&nbsp;&nbsp;
123-
<a class="link-inverse" href="{{ path('_profiler', { panel: 'db', token: token, page: 'explain', connection: connection, request: i }) }}" onclick="return explain(this);" data-target-id="explain-{{ i }}-{{ loop.parent.loop.index }}">Explain request</a>
124-
{% endif %}
125-
#}
126-
127144
{% if request.backtrace is defined %}
145+
&nbsp;&nbsp;
128146
<a href="#" class="sf-toggle link-inverse" data-toggle-selector="#backtrace-{{ i }}-{{ loop.parent.loop.index }}" data-toggle-alt-content="Hide request backtrace">View request backtrace</a>
129147
{% endif %}
130148
</div>
@@ -134,51 +152,42 @@
134152
<button class="btn btn-sm label hidden" data-clipboard-text="{{ request.command|json_encode|e('html_attr') }}">Copy</button>
135153
</div>
136154

137-
{#
138-
{% if request.runnable %}
139-
<div id="original-request-{{ i }}-{{ loop.parent.loop.index }}" class="sql-runnable hidden">
140-
{% set runnable_sql = (request.sql ~ ';')|doctrine_replace_request_parameters(request.params) %}
141-
{{ runnable_sql|doctrine_prettify_sql }}
142-
<button class="btn btn-sm hidden" data-clipboard-text="{{ runnable_sql|e('html_attr') }}">Copy</button>
143-
</div>
144-
{% endif %}
145-
146-
{% if request.explainable %}
147-
<div id="explain-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div>
148-
{% endif %}
149-
#}
150-
151155
{% if request.backtrace is defined %}
152-
<div id="backtrace-{{ i }}-{{ loop.parent.loop.index }}" class="0hidden">
153-
<table>
154-
<thead>
155-
<tr>
156-
<th scope="col">#</th>
157-
<th scope="col">File/Call</th>
158-
</tr>
159-
</thead>
160-
<tbody>
161-
{% for trace in request.backtrace %}
162-
<tr>
163-
<td>{{ loop.index }}</td>
164-
<td>
165-
<span class="text-small">
166-
{% set line_number = trace.line|default(1) %}
167-
{% if trace.file is defined %}
168-
<a href="{{ trace.file|file_link(line_number) }}">
169-
{% endif %}
170-
{{- trace.class|default ~ (trace.class is defined ? trace.type|default('::')) -}}
171-
<span class="status-warning">{{ trace.function }}</span>
156+
<div id="backtrace-{{ i }}-{{ loop.parent.loop.index }}" class="trace-details hidden">
157+
{% set firstUserCode = true %}
158+
{% for trace in request.backtrace %}
159+
<div class="trace-line">
160+
{% set display = false %}
161+
{% if firstUserCode and trace.file is not empty and '/vendor/' not in trace.file and '/var/cache/' not in trace.file %}
162+
{% set firstUserCode = false %}
163+
{% set display = true %}
164+
{% endif %}
165+
<div class="trace-line-header break-long-words sf-toggle" data-toggle-selector="#trace-html-{{ i }}-{{ loop.index }}" data-toggle-initial="{{ display ? 'display' : 'hidden' }}">
166+
<span class="icon icon-close">{{ include('@WebProfiler/images/icon-minus-square.svg') }}</span>
167+
<span class="icon icon-open">{{ include('@WebProfiler/images/icon-plus-square.svg') }}</span>
168+
<span class="block trace-file-path">
169+
{% set line_number = trace.line|default(1) %}
172170
{% if trace.file is defined %}
173-
</a>
174-
{% endif %}
175-
(line {{ line_number }})
176-
</span>
177-
</td>
178-
</tr>
179-
{% endfor %}
180-
</tbody>
181-
</table>
171+
<a href="{{ trace.file|file_link(line_number) }}">
172+
{% endif %}
173+
{{- trace.file|file_relative|default('n/a') -}}
174+
{% if trace.file is defined %}
175+
</a>
176+
{% endif %}
177+
-> <span class="trace-method">{{ trace.function }}</span>
178+
(line {{ line_number }})
179+
</span>
180+
</div>
181+
<div id="trace-html-{{ i }}-{{ loop.index }}" class="trace sf-toggle-content">
182+
{{ trace.file|file_excerpt(trace.line)|replace({
183+
'#DD0000': 'var(--highlight-string)',
184+
'#007700': 'var(--highlight-keyword)',
185+
'#0000BB': 'var(--highlight-default)',
186+
'#FF8000': 'var(--highlight-comment)'
187+
})|raw }}
188+
</div>
189+
</div>
190+
{% endfor %}
182191
</div>
183192
{% endif %}
184193
</td>

0 commit comments

Comments
 (0)