-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add serializer profiler #45656
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Serializer] Add serializer profiler
- Loading branch information
commit 0e20ad6085b62d9bea91136d58db2ad785c75f99
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer_debug.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use Symfony\Component\Serializer\DataCollector\SerializerDataCollector; | ||
use Symfony\Component\Serializer\Debug\TraceableSerializer; | ||
|
||
return static function (ContainerConfigurator $container) { | ||
$container->services() | ||
->set('debug.serializer', TraceableSerializer::class) | ||
->decorate('serializer', null, 255) | ||
->args([ | ||
service('debug.serializer.inner'), | ||
service('serializer.data_collector'), | ||
]) | ||
|
||
->set('serializer.data_collector', SerializerDataCollector::class) | ||
->tag('data_collector', [ | ||
'template' => '@WebProfiler/Collector/serializer.html.twig', | ||
'id' => 'serializer', | ||
]) | ||
; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/serializer.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
{% extends '@WebProfiler/Profiler/layout.html.twig' %} | ||
|
||
{% import _self as helper %} | ||
|
||
{% block menu %} | ||
<span class="label {{ not collector.handledCount ? 'disabled' }}"> | ||
<span class="icon">{{ include('@WebProfiler/Icon/validator.svg') }}</span> | ||
<strong>Serializer</strong> | ||
</span> | ||
{% endblock %} | ||
|
||
{% 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> | ||
|
||
<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 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_encode_tab(collector.data, true) }} | ||
{{ helper.render_encode_tab(collector.data, false) }} | ||
</div> | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% macro render_serialize_tab(collectorData, serialize) %} | ||
{% set data = serialize ? collectorData.serialize : collectorData.deserialize %} | ||
{% set cellPrefix = serialize ? 'serialize' : 'deserialize' %} | ||
|
||
<div class="tab {{ not data ? 'disabled' }}"> | ||
<h3 class="tab-title">{{ serialize ? 'serialize' : 'deserialize' }} <span class="badge">{{ data|length }}</h3> | ||
<div class="tab-content"> | ||
{% if not data|length %} | ||
<div class="empty"> | ||
<p>Nothing was {{ serialize ? 'serialized' : 'deserialized' }}.</p> | ||
</div> | ||
{% else %} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Data</th> | ||
<th>Context</th> | ||
<th>Normalizer</th> | ||
<th>Encoder</th> | ||
<th>Time</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for item in data %} | ||
<tr> | ||
<td>{{ helper.render_data_cell(item, loop.index, cellPrefix) }}</td> | ||
<td>{{ helper.render_context_cell(item, loop.index, cellPrefix) }}</td> | ||
<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> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endmacro %} | ||
|
||
{% macro render_normalize_tab(collectorData, normalize) %} | ||
{% set data = normalize ? collectorData.normalize : collectorData.denormalize %} | ||
{% set cellPrefix = normalize ? 'normalize' : 'denormalize' %} | ||
|
||
<div class="tab {{ not data ? 'disabled' }}"> | ||
<h3 class="tab-title">{{ normalize ? 'normalize' : 'denormalize' }} <span class="badge">{{ data|length }}</h3> | ||
<div class="tab-content"> | ||
{% if not data|length %} | ||
<div class="empty"> | ||
<p>Nothing was {{ normalize ? 'normalized' : 'denormalized' }}.</p> | ||
</div> | ||
{% else %} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Data</th> | ||
<th>Context</th> | ||
<th>Normalizer</th> | ||
<th>Time</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for item in data %} | ||
<tr> | ||
<td>{{ helper.render_data_cell(item, loop.index, cellPrefix) }}</td> | ||
<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> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endmacro %} | ||
|
||
{% macro render_encode_tab(collectorData, encode) %} | ||
{% set data = encode ? collectorData.encode : collectorData.decode %} | ||
{% set cellPrefix = encode ? 'encode' : 'decode' %} | ||
|
||
<div class="tab {{ not data ? 'disabled' }}"> | ||
<h3 class="tab-title">{{ encode ? 'encode' : 'decode' }} <span class="badge">{{ data|length }}</h3> | ||
<div class="tab-content"> | ||
{% if not data|length %} | ||
<div class="empty"> | ||
<p>Nothing was {{ encode ? 'encoded' : 'decoded' }}.</p> | ||
</div> | ||
{% else %} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Data</th> | ||
<th>Context</th> | ||
<th>Encoder</th> | ||
<th>Time</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for item in data %} | ||
<tr> | ||
<td>{{ helper.render_data_cell(item, loop.index, cellPrefix) }}</td> | ||
<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> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endmacro %} | ||
|
||
{% macro render_data_cell(item, index, method) %} | ||
{% set data_id = 'data-' ~ method ~ '-' ~ index %} | ||
|
||
<span class="nowrap">{{ item.dataType }}</span> | ||
|
||
<div> | ||
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ data_id }}" data-toggle-alt-content="Hide contents">Show contents</a> | ||
<div id="{{ data_id }}" class="context sf-toggle-content sf-toggle-hidden"> | ||
{{ profiler_dump(item.data) }} | ||
</div> | ||
</div> | ||
{% endmacro %} | ||
|
||
{% macro render_context_cell(item, index, method) %} | ||
{% set context_id = 'context-' ~ method ~ '-' ~ index %} | ||
|
||
{% if item.type %} | ||
<span class="nowrap">Type: {{ item.type }}</span> | ||
<div class="nowrap">Format: {{ item.format ? item.format : 'none' }}</div> | ||
{% else %} | ||
<span class="nowrap">Format: {{ item.format ? item.format : 'none' }}</span> | ||
{% endif %} | ||
|
||
<div> | ||
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide context">Show context</a> | ||
<div id="{{ context_id }}" class="context sf-toggle-content sf-toggle-hidden"> | ||
{{ profiler_dump(item.context) }} | ||
</div> | ||
</div> | ||
{% endmacro %} | ||
|
||
{% 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.normalization|length > 1 %} | ||
<div> | ||
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ nested_normalizers_id }}" data-toggle-alt-content="Hide nested normalizers">Show nested normalizers</a> | ||
<div id="{{ nested_normalizers_id }}" class="context sf-toggle-content sf-toggle-hidden"> | ||
<ul class="text-small" style="line-height:80%;margin-top:10px"> | ||
{% for normalizer in item.normalization %} | ||
<li><span class="nowrap">x{{ normalizer.calls }} <a href="{{ normalizer.file|file_link(normalizer.line) }}" title="{{ normalizer.file }}">{{ normalizer.class }}</a> ({{ '%.2f'|format(normalizer.time * 1000) }} ms)</span></li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
{% 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.encoding|length > 1 %} | ||
<div> | ||
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ nested_encoders_id }}" data-toggle-alt-content="Hide nested encoders">Show nested encoders</a> | ||
<div id="{{ nested_encoders_id }}" class="context sf-toggle-content sf-toggle-hidden"> | ||
<ul class="text-small" style="line-height:80%;margin-top:10px"> | ||
{% for encoder in item.encoding %} | ||
<li><span class="nowrap">x{{ encoder.calls }} <a href="{{ encoder.file|file_link(encoder.line) }}" title="{{ encoder.file }}">{{ encoder.class }}</a> ({{ '%.2f'|format(encoder.time * 1000) }} ms)</span></li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
{% macro render_time_cell(item) %} | ||
<span class="nowrap">{{ '%.2f'|format(item.time * 1000) }} ms</span> | ||
{% endmacro %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Icon needs to be updated. We are working on updating all icons soon, so let's not block this PR for now.