Skip to content

Commit 6226def

Browse files
committed
feature #46569 [Serializer][WebProfilerBundle] Collect & show caller source code (ogizanagi)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [Serializer][WebProfilerBundle] Collect & show caller source code | Q | A | ------------- | --- | Branch? | 6.2 <!-- see below --> | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A | License | MIT | Doc PR | N/A As for the Messenger and Validator panels, knowing from which code was called the Serializer's methods and jumping to it in one click is useful to get a better understanding of each collected rows and their context. ![Capture d’écran 2022-06-03 à 09 32 00](https://user-images.githubusercontent.com/2211145/171818770-5be7e8a6-d35e-47d4-92e1-f170375ffe41.png) ![Capture d’écran 2022-06-03 à 09 46 43](https://user-images.githubusercontent.com/2211145/171818809-47f562e5-0356-41db-ac6a-3fbd52bf3651.png) ![Capture d’écran 2022-06-03 à 10 34 26](https://user-images.githubusercontent.com/2211145/171819170-cfc39261-a7e7-412f-8fdc-07ee1771d5ee.png) --- the second commit relates to #46565 Commits ------- 0a20712 Fix dark theme highlight color & reuse css vars 83412d2 [Serializer][WebProfilerBundle] Collect & show caller source code
2 parents 0140746 + 0a20712 commit 6226def

File tree

5 files changed

+194
-71
lines changed

5 files changed

+194
-71
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/serializer.html.twig

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,36 @@
1111

1212
{% block panel %}
1313
<h2>Serializer</h2>
14-
{% if not collector.handledCount %}
15-
<div class="empty">
16-
<p>Nothing was handled by the serializer for this request.</p>
17-
</div>
18-
{% else %}
19-
<div class="metrics">
20-
<div class="metric">
21-
<span class="value">{{ collector.handledCount }}</span>
22-
<span class="label">Handled</span>
14+
<div class="sf-serializer sf-reset">
15+
{% if not collector.handledCount %}
16+
<div class="empty">
17+
<p>Nothing was handled by the serializer for this request.</p>
2318
</div>
19+
{% else %}
20+
<div class="metrics">
21+
<div class="metric">
22+
<span class="value">{{ collector.handledCount }}</span>
23+
<span class="label">Handled</span>
24+
</div>
2425

25-
<div class="metric">
26-
<span class="value">{{ '%.2f'|format(collector.totalTime * 1000) }} <span class="unit">ms</span></span>
27-
<span class="label">Total time</span>
26+
<div class="metric">
27+
<span class="value">{{ '%.2f'|format(collector.totalTime * 1000) }} <span class="unit">ms</span></span>
28+
<span class="label">Total time</span>
29+
</div>
2830
</div>
29-
</div>
3031

31-
<div class="sf-tabs">
32-
{{ helper.render_serialize_tab(collector.data, true) }}
33-
{{ helper.render_serialize_tab(collector.data, false) }}
32+
<div class="sf-tabs">
33+
{{ helper.render_serialize_tab(collector.data, true) }}
34+
{{ helper.render_serialize_tab(collector.data, false) }}
3435

35-
{{ helper.render_normalize_tab(collector.data, true) }}
36-
{{ helper.render_normalize_tab(collector.data, false) }}
36+
{{ helper.render_normalize_tab(collector.data, true) }}
37+
{{ helper.render_normalize_tab(collector.data, false) }}
3738

38-
{{ helper.render_encode_tab(collector.data, true) }}
39-
{{ helper.render_encode_tab(collector.data, false) }}
40-
</div>
41-
{% endif %}
39+
{{ helper.render_encode_tab(collector.data, true) }}
40+
{{ helper.render_encode_tab(collector.data, false) }}
41+
</div>
42+
{% endif %}
43+
</div>
4244
{% endblock %}
4345

4446
{% macro render_serialize_tab(collectorData, serialize) %}
@@ -61,6 +63,7 @@
6163
<th>Normalizer</th>
6264
<th>Encoder</th>
6365
<th>Time</th>
66+
<th>Caller</th>
6467
</tr>
6568
</thead>
6669
<tbody>
@@ -71,6 +74,7 @@
7174
<td>{{ helper.render_normalizer_cell(item, loop.index, cellPrefix) }}</td>
7275
<td>{{ helper.render_encoder_cell(item, loop.index, cellPrefix) }}</td>
7376
<td>{{ helper.render_time_cell(item) }}</td>
77+
<td>{{ helper.render_caller_cell(item, loop.index, cellPrefix) }}</td>
7478
</tr>
7579
{% endfor %}
7680
</tbody>
@@ -80,6 +84,36 @@
8084
</div>
8185
{% endmacro %}
8286

87+
{% macro render_caller_cell(item, index, method) %}
88+
{% if item.caller is defined %}
89+
<span class="metadata">
90+
{% set caller = item.caller %}
91+
{% if caller.line %}
92+
{% set link = caller.file|file_link(caller.line) %}
93+
{% if link %}
94+
<a href="{{ link }}" title="{{ caller.file }}">{{ caller.name }}</a>
95+
{% else %}
96+
<abbr title="{{ caller.file }}">{{ caller.name }}</abbr>
97+
{% endif %}
98+
{% else %}
99+
{{ caller.name }}
100+
{% endif %}
101+
line <a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ method }}-{{ index }}">{{ caller.line }}</a>
102+
</span>
103+
104+
<div class="sf-serializer-compact hidden" id="sf-trace-{{ method }}-{{ index }}">
105+
<div class="trace">
106+
{{ caller.file|file_excerpt(caller.line)|replace({
107+
'#DD0000': 'var(--highlight-string)',
108+
'#007700': 'var(--highlight-keyword)',
109+
'#0000BB': 'var(--highlight-default)',
110+
'#FF8000': 'var(--highlight-comment)'
111+
})|raw }}
112+
</div>
113+
</div>
114+
{% endif %}
115+
{% endmacro %}
116+
83117
{% macro render_normalize_tab(collectorData, normalize) %}
84118
{% set data = normalize ? collectorData.normalize : collectorData.denormalize %}
85119
{% set cellPrefix = normalize ? 'normalize' : 'denormalize' %}
@@ -99,6 +133,7 @@
99133
<th>Context</th>
100134
<th>Normalizer</th>
101135
<th>Time</th>
136+
<th>Caller</th>
102137
</tr>
103138
</thead>
104139
<tbody>
@@ -108,6 +143,7 @@
108143
<td>{{ helper.render_context_cell(item, loop.index, cellPrefix) }}</td>
109144
<td>{{ helper.render_normalizer_cell(item, loop.index, cellPrefix) }}</td>
110145
<td>{{ helper.render_time_cell(item) }}</td>
146+
<td>{{ helper.render_caller_cell(item, loop.index, cellPrefix) }}</td>
111147
</tr>
112148
{% endfor %}
113149
</tbody>
@@ -136,6 +172,7 @@
136172
<th>Context</th>
137173
<th>Encoder</th>
138174
<th>Time</th>
175+
<th>Caller</th>
139176
</tr>
140177
</thead>
141178
<tbody>
@@ -145,6 +182,7 @@
145182
<td>{{ helper.render_context_cell(item, loop.index, cellPrefix) }}</td>
146183
<td>{{ helper.render_encoder_cell(item, loop.index, cellPrefix) }}</td>
147184
<td>{{ helper.render_time_cell(item) }}</td>
185+
<td>{{ helper.render_caller_cell(item, loop.index, cellPrefix) }}</td>
148186
</tr>
149187
{% endfor %}
150188
</tbody>
@@ -188,7 +226,9 @@
188226
{% macro render_normalizer_cell(item, index, method) %}
189227
{% set nested_normalizers_id = 'nested-normalizers-' ~ method ~ '-' ~ index %}
190228

191-
<span class="nowrap"><a href="{{ item.normalizer.file|file_link(item.normalizer.line) }}" title="{{ item.normalizer.file }}">{{ item.normalizer.class }}</a> ({{ '%.2f'|format(item.normalizer.time * 1000) }} ms)</span>
229+
{% if item.normalizer is defined %}
230+
<span class="nowrap"><a href="{{ item.normalizer.file|file_link(item.normalizer.line) }}" title="{{ item.normalizer.file }}">{{ item.normalizer.class }}</a> ({{ '%.2f'|format(item.normalizer.time * 1000) }} ms)</span>
231+
{% endif %}
192232

193233
{% if item.normalization|length > 1 %}
194234
<div>
@@ -207,7 +247,9 @@
207247
{% macro render_encoder_cell(item, index, method) %}
208248
{% set nested_encoders_id = 'nested-encoders-' ~ method ~ '-' ~ index %}
209249

210-
<span class="nowrap"><a href="{{ item.encoder.file|file_link(item.encoder.line) }}" title="{{ item.encoder.file }}">{{ item.encoder.class }}</a> ({{ '%.2f'|format(item.encoder.time * 1000) }} ms)</span>
250+
{% if item.encoder is defined %}
251+
<span class="nowrap"><a href="{{ item.encoder.file|file_link(item.encoder.line) }}" title="{{ item.encoder.file }}">{{ item.encoder.class }}</a> ({{ '%.2f'|format(item.encoder.time * 1000) }} ms)</span>
252+
{% endif %}
211253

212254
{% if item.encoding|length > 1 %}
213255
<div>

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
--highlight-default: #222222;
5252
--highlight-keyword: #a71d5d;
5353
--highlight-string: #183691;
54+
--highlight-selected-line: rgba(255, 255, 153, 0.5);
5455
--base-0: #fff;
5556
--base-1: #f5f5f5;
5657
--base-2: #e0e0e0;
@@ -104,6 +105,7 @@
104105
--highlight-default: var(--base-6);
105106
--highlight-keyword: #ff413c;
106107
--highlight-string: #70a6fd;
108+
--highlight-selected-line: rgba(14, 14, 14, 0.5);
107109
--base-0: #2e3136;
108110
--base-1: #444;
109111
--base-2: #666;
@@ -1296,15 +1298,40 @@ tr.log-status-silenced {
12961298
padding: 0;
12971299
}
12981300
#collector-content .sf-validator .trace li.selected {
1299-
background: rgba(255, 255, 153, 0.5);
1301+
background: var(--highlight-selected-line);
1302+
}
1303+
1304+
{# Serializer panel
1305+
========================================================================= #}
1306+
1307+
#collector-content .sf-serializer {
1308+
margin-bottom: 2em;
1309+
}
1310+
1311+
#collector-content .sf-serializer .trace {
1312+
border: var(--border);
1313+
background: var(--base-0);
1314+
padding: 10px;
1315+
margin: 0.5em 0;
1316+
overflow: auto;
1317+
}
1318+
#collector-content .sf-serializer .trace {
1319+
font-size: 12px;
1320+
}
1321+
#collector-content .sf-serializer .trace li {
1322+
margin-bottom: 0;
1323+
padding: 0;
1324+
}
1325+
#collector-content .sf-serializer .trace li.selected {
1326+
background: var(--highlight-selected-line);
13001327
}
13011328

13021329
{# Messenger panel
13031330
========================================================================= #}
13041331

13051332
#collector-content .message-bus .trace {
1306-
border: 1px solid #DDD;
1307-
background: #FFF;
1333+
border: var(--border);
1334+
background: var(--base-0);
13081335
padding: 10px;
13091336
margin: 0.5em 0;
13101337
overflow: auto;
@@ -1317,7 +1344,7 @@ tr.log-status-silenced {
13171344
padding: 0;
13181345
}
13191346
#collector-content .message-bus .trace li.selected {
1320-
background: rgba(255, 255, 153, 0.5);
1347+
background: var(--highlight-selected-line);
13211348
}
13221349

13231350
{# Dump panel

src/Symfony/Component/Serializer/DataCollector/SerializerDataCollector.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
1717
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
1818
use Symfony\Component\Serializer\Debug\TraceableSerializer;
19+
use Symfony\Component\Serializer\SerializerInterface;
1920
use Symfony\Component\VarDumper\Cloner\Data;
2021

2122
/**
@@ -70,68 +71,68 @@ public function getTotalTime(): float
7071
return $totalTime;
7172
}
7273

73-
public function collectSerialize(string $traceId, mixed $data, string $format, array $context, float $time): void
74+
public function collectSerialize(string $traceId, mixed $data, string $format, array $context, float $time, array $caller): void
7475
{
7576
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);
7677

7778
$this->collected[$traceId] = array_merge(
7879
$this->collected[$traceId] ?? [],
79-
compact('data', 'format', 'context', 'time'),
80+
compact('data', 'format', 'context', 'time', 'caller'),
8081
['method' => 'serialize'],
8182
);
8283
}
8384

84-
public function collectDeserialize(string $traceId, mixed $data, string $type, string $format, array $context, float $time): void
85+
public function collectDeserialize(string $traceId, mixed $data, string $type, string $format, array $context, float $time, array $caller): void
8586
{
8687
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);
8788

8889
$this->collected[$traceId] = array_merge(
8990
$this->collected[$traceId] ?? [],
90-
compact('data', 'format', 'type', 'context', 'time'),
91+
compact('data', 'format', 'type', 'context', 'time', 'caller'),
9192
['method' => 'deserialize'],
9293
);
9394
}
9495

95-
public function collectNormalize(string $traceId, mixed $data, ?string $format, array $context, float $time): void
96+
public function collectNormalize(string $traceId, mixed $data, ?string $format, array $context, float $time, array $caller): void
9697
{
9798
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);
9899

99100
$this->collected[$traceId] = array_merge(
100101
$this->collected[$traceId] ?? [],
101-
compact('data', 'format', 'context', 'time'),
102+
compact('data', 'format', 'context', 'time', 'caller'),
102103
['method' => 'normalize'],
103104
);
104105
}
105106

106-
public function collectDenormalize(string $traceId, mixed $data, string $type, ?string $format, array $context, float $time): void
107+
public function collectDenormalize(string $traceId, mixed $data, string $type, ?string $format, array $context, float $time, array $caller): void
107108
{
108109
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);
109110

110111
$this->collected[$traceId] = array_merge(
111112
$this->collected[$traceId] ?? [],
112-
compact('data', 'format', 'type', 'context', 'time'),
113+
compact('data', 'format', 'type', 'context', 'time', 'caller'),
113114
['method' => 'denormalize'],
114115
);
115116
}
116117

117-
public function collectEncode(string $traceId, mixed $data, ?string $format, array $context, float $time): void
118+
public function collectEncode(string $traceId, mixed $data, ?string $format, array $context, float $time, array $caller): void
118119
{
119120
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);
120121

121122
$this->collected[$traceId] = array_merge(
122123
$this->collected[$traceId] ?? [],
123-
compact('data', 'format', 'context', 'time'),
124+
compact('data', 'format', 'context', 'time', 'caller'),
124125
['method' => 'encode'],
125126
);
126127
}
127128

128-
public function collectDecode(string $traceId, mixed $data, ?string $format, array $context, float $time): void
129+
public function collectDecode(string $traceId, mixed $data, ?string $format, array $context, float $time, array $caller): void
129130
{
130131
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);
131132

132133
$this->collected[$traceId] = array_merge(
133134
$this->collected[$traceId] ?? [],
134-
compact('data', 'format', 'context', 'time'),
135+
compact('data', 'format', 'context', 'time', 'caller'),
135136
['method' => 'decode'],
136137
);
137138
}
@@ -192,6 +193,7 @@ public function lateCollect(): void
192193
'context' => $this->cloneVar($collected['context']),
193194
'normalization' => [],
194195
'encoding' => [],
196+
'caller' => $collected['caller'] ?? null,
195197
];
196198

197199
if (isset($collected['normalization'])) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy