Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer][WebProfilerBundle] Collect & show caller source code #46569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,36 @@

{% block panel %}
<h2>Serializer</h2>
{% if not collector.handledCount %}
<div class="empty">
<p>Nothing was handled by the serializer for this request.</p>
</div>
{% else %}
<div class="metrics">
<div class="metric">
<span class="value">{{ collector.handledCount }}</span>
<span class="label">Handled</span>
<div class="sf-serializer sf-reset">
{% if not collector.handledCount %}
<div class="empty">
<p>Nothing was handled by the serializer for this request.</p>
</div>
{% else %}
<div class="metrics">
<div class="metric">
<span class="value">{{ collector.handledCount }}</span>
<span class="label">Handled</span>
</div>

<div class="metric">
<span class="value">{{ '%.2f'|format(collector.totalTime * 1000) }} <span class="unit">ms</span></span>
<span class="label">Total time</span>
<div class="metric">
<span class="value">{{ '%.2f'|format(collector.totalTime * 1000) }} <span class="unit">ms</span></span>
<span class="label">Total time</span>
</div>
</div>
</div>

<div class="sf-tabs">
{{ helper.render_serialize_tab(collector.data, true) }}
{{ helper.render_serialize_tab(collector.data, false) }}
<div class="sf-tabs">
{{ helper.render_serialize_tab(collector.data, true) }}
{{ helper.render_serialize_tab(collector.data, false) }}

{{ helper.render_normalize_tab(collector.data, true) }}
{{ helper.render_normalize_tab(collector.data, false) }}
{{ helper.render_normalize_tab(collector.data, true) }}
{{ helper.render_normalize_tab(collector.data, false) }}

{{ helper.render_encode_tab(collector.data, true) }}
{{ helper.render_encode_tab(collector.data, false) }}
</div>
{% endif %}
{{ helper.render_encode_tab(collector.data, true) }}
{{ helper.render_encode_tab(collector.data, false) }}
</div>
{% endif %}
</div>
{% endblock %}

{% macro render_serialize_tab(collectorData, serialize) %}
Expand All @@ -61,6 +63,7 @@
<th>Normalizer</th>
<th>Encoder</th>
<th>Time</th>
<th>Caller</th>
</tr>
</thead>
<tbody>
Expand All @@ -71,6 +74,7 @@
<td>{{ helper.render_normalizer_cell(item, loop.index, cellPrefix) }}</td>
<td>{{ helper.render_encoder_cell(item, loop.index, cellPrefix) }}</td>
<td>{{ helper.render_time_cell(item) }}</td>
<td>{{ helper.render_caller_cell(item, loop.index, cellPrefix) }}</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -80,6 +84,36 @@
</div>
{% endmacro %}

{% macro render_caller_cell(item, index, method) %}
{% if item.caller is defined %}
<span class="metadata">
{% set caller = item.caller %}
{% if caller.line %}
{% set link = caller.file|file_link(caller.line) %}
{% if link %}
<a href="{{ link }}" title="{{ caller.file }}">{{ caller.name }}</a>
{% else %}
<abbr title="{{ caller.file }}">{{ caller.name }}</abbr>
{% endif %}
{% else %}
{{ caller.name }}
{% endif %}
line <a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ method }}-{{ index }}">{{ caller.line }}</a>
</span>

<div class="sf-serializer-compact hidden" id="sf-trace-{{ method }}-{{ index }}">
<div class="trace">
{{ caller.file|file_excerpt(caller.line)|replace({
'#DD0000': 'var(--highlight-string)',
'#007700': 'var(--highlight-keyword)',
'#0000BB': 'var(--highlight-default)',
'#FF8000': 'var(--highlight-comment)'
})|raw }}
</div>
</div>
{% endif %}
{% endmacro %}

{% macro render_normalize_tab(collectorData, normalize) %}
{% set data = normalize ? collectorData.normalize : collectorData.denormalize %}
{% set cellPrefix = normalize ? 'normalize' : 'denormalize' %}
Expand All @@ -99,6 +133,7 @@
<th>Context</th>
<th>Normalizer</th>
<th>Time</th>
<th>Caller</th>
</tr>
</thead>
<tbody>
Expand All @@ -108,6 +143,7 @@
<td>{{ helper.render_context_cell(item, loop.index, cellPrefix) }}</td>
<td>{{ helper.render_normalizer_cell(item, loop.index, cellPrefix) }}</td>
<td>{{ helper.render_time_cell(item) }}</td>
<td>{{ helper.render_caller_cell(item, loop.index, cellPrefix) }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -136,6 +172,7 @@
<th>Context</th>
<th>Encoder</th>
<th>Time</th>
<th>Caller</th>
</tr>
</thead>
<tbody>
Expand All @@ -145,6 +182,7 @@
<td>{{ helper.render_context_cell(item, loop.index, cellPrefix) }}</td>
<td>{{ helper.render_encoder_cell(item, loop.index, cellPrefix) }}</td>
<td>{{ helper.render_time_cell(item) }}</td>
<td>{{ helper.render_caller_cell(item, loop.index, cellPrefix) }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -188,7 +226,9 @@
{% macro render_normalizer_cell(item, index, method) %}
{% set nested_normalizers_id = 'nested-normalizers-' ~ method ~ '-' ~ index %}

<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>
{% if item.normalizer is defined %}
<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>
{% endif %}

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

<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>
{% if item.encoder is defined %}
<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>
{% endif %}

{% if item.encoding|length > 1 %}
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
--highlight-default: #222222;
--highlight-keyword: #a71d5d;
--highlight-string: #183691;
--highlight-selected-line: rgba(255, 255, 153, 0.5);
--base-0: #fff;
--base-1: #f5f5f5;
--base-2: #e0e0e0;
Expand Down Expand Up @@ -104,6 +105,7 @@
--highlight-default: var(--base-6);
--highlight-keyword: #ff413c;
--highlight-string: #70a6fd;
--highlight-selected-line: rgba(14, 14, 14, 0.5);
--base-0: #2e3136;
--base-1: #444;
--base-2: #666;
Expand Down Expand Up @@ -1296,15 +1298,40 @@ tr.log-status-silenced {
padding: 0;
}
#collector-content .sf-validator .trace li.selected {
background: rgba(255, 255, 153, 0.5);
background: var(--highlight-selected-line);
}

{# Serializer panel
========================================================================= #}

#collector-content .sf-serializer {
margin-bottom: 2em;
}

#collector-content .sf-serializer .trace {
border: var(--border);
background: var(--base-0);
padding: 10px;
margin: 0.5em 0;
overflow: auto;
}
#collector-content .sf-serializer .trace {
font-size: 12px;
}
#collector-content .sf-serializer .trace li {
margin-bottom: 0;
padding: 0;
}
#collector-content .sf-serializer .trace li.selected {
background: var(--highlight-selected-line);
}

{# Messenger panel
========================================================================= #}

#collector-content .message-bus .trace {
border: 1px solid #DDD;
background: #FFF;
border: var(--border);
background: var(--base-0);
padding: 10px;
margin: 0.5em 0;
overflow: auto;
Expand All @@ -1317,7 +1344,7 @@ tr.log-status-silenced {
padding: 0;
}
#collector-content .message-bus .trace li.selected {
background: rgba(255, 255, 153, 0.5);
background: var(--highlight-selected-line);
}

{# Dump panel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Symfony\Component\Serializer\Debug\TraceableSerializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\VarDumper\Cloner\Data;

/**
Expand Down Expand Up @@ -70,68 +71,68 @@ public function getTotalTime(): float
return $totalTime;
}

public function collectSerialize(string $traceId, mixed $data, string $format, array $context, float $time): void
public function collectSerialize(string $traceId, mixed $data, string $format, array $context, float $time, array $caller): void
{
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);

$this->collected[$traceId] = array_merge(
$this->collected[$traceId] ?? [],
compact('data', 'format', 'context', 'time'),
compact('data', 'format', 'context', 'time', 'caller'),
['method' => 'serialize'],
);
}

public function collectDeserialize(string $traceId, mixed $data, string $type, string $format, array $context, float $time): void
public function collectDeserialize(string $traceId, mixed $data, string $type, string $format, array $context, float $time, array $caller): void
{
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);

$this->collected[$traceId] = array_merge(
$this->collected[$traceId] ?? [],
compact('data', 'format', 'type', 'context', 'time'),
compact('data', 'format', 'type', 'context', 'time', 'caller'),
['method' => 'deserialize'],
);
}

public function collectNormalize(string $traceId, mixed $data, ?string $format, array $context, float $time): void
public function collectNormalize(string $traceId, mixed $data, ?string $format, array $context, float $time, array $caller): void
{
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);

$this->collected[$traceId] = array_merge(
$this->collected[$traceId] ?? [],
compact('data', 'format', 'context', 'time'),
compact('data', 'format', 'context', 'time', 'caller'),
['method' => 'normalize'],
);
}

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

$this->collected[$traceId] = array_merge(
$this->collected[$traceId] ?? [],
compact('data', 'format', 'type', 'context', 'time'),
compact('data', 'format', 'type', 'context', 'time', 'caller'),
['method' => 'denormalize'],
);
}

public function collectEncode(string $traceId, mixed $data, ?string $format, array $context, float $time): void
public function collectEncode(string $traceId, mixed $data, ?string $format, array $context, float $time, array $caller): void
{
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);

$this->collected[$traceId] = array_merge(
$this->collected[$traceId] ?? [],
compact('data', 'format', 'context', 'time'),
compact('data', 'format', 'context', 'time', 'caller'),
['method' => 'encode'],
);
}

public function collectDecode(string $traceId, mixed $data, ?string $format, array $context, float $time): void
public function collectDecode(string $traceId, mixed $data, ?string $format, array $context, float $time, array $caller): void
{
unset($context[TraceableSerializer::DEBUG_TRACE_ID]);

$this->collected[$traceId] = array_merge(
$this->collected[$traceId] ?? [],
compact('data', 'format', 'context', 'time'),
compact('data', 'format', 'context', 'time', 'caller'),
['method' => 'decode'],
);
}
Expand Down Expand Up @@ -192,6 +193,7 @@ public function lateCollect(): void
'context' => $this->cloneVar($collected['context']),
'normalization' => [],
'encoding' => [],
'caller' => $collected['caller'] ?? null,
];

if (isset($collected['normalization'])) {
Expand Down
Loading