-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Added cache data collector and profiler page #21065
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
Changes from all commits
23c0039
8f73434
32376dd
d63adcd
321e526
26ea3e9
9e12fac
d09bcf3
9f1aa40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?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\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\Cache\Adapter\TraceableAdapter; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Inject a data collector to all the cache services to be able to get detailed statistics. | ||
* | ||
* @author Tobias Nyholm <tobias.nyholm@gmail.com> | ||
*/ | ||
class CacheCollectorPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('data_collector.cache')) { | ||
return; | ||
} | ||
|
||
$collectorDefinition = $container->getDefinition('data_collector.cache'); | ||
foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) { | ||
if ($container->getDefinition($id)->isAbstract()) { | ||
continue; | ||
} | ||
|
||
$container->register($id.'.recorder', TraceableAdapter::class) | ||
->setDecoratedService($id) | ||
->addArgument(new Reference($id.'.recorder.inner')) | ||
->setPublic(false); | ||
|
||
// Tell the collector to add the new instance | ||
$collectorDefinition->addMethodCall('addInstance', array($id, new Reference($id))); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<!-- DataCollector --> | ||
<service id="data_collector.cache" class="Symfony\Component\Cache\DataCollector\CacheDataCollector"> | ||
<tag name="data_collector" template="@WebProfiler/Collector/cache.html.twig" id="cache" priority="275" /> | ||
</service> | ||
</services> | ||
</container> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} | ||
|
||
{% block toolbar %} | ||
{% if collector.totals.calls > 0 %} | ||
{% set icon %} | ||
{{ include('@WebProfiler/Icon/cache.svg') }} | ||
<span class="sf-toolbar-value">{{ collector.totals.calls }}</span> | ||
<span class="sf-toolbar-info-piece-additional-detail"> | ||
<span class="sf-toolbar-label">in</span> | ||
<span class="sf-toolbar-value">{{ '%0.2f'|format(collector.totals.time * 1000) }}</span> | ||
<span class="sf-toolbar-label">ms</span> | ||
</span> | ||
{% endset %} | ||
{% set text %} | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Cache Calls</b> | ||
<span>{{ collector.totals.calls }}</span> | ||
</div> | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Total time</b> | ||
<span>{{ '%0.2f'|format(collector.totals.time * 1000) }} ms</span> | ||
</div> | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Cache hits</b> | ||
<span>{{ collector.totals.hits }}/{{ collector.totals.reads }} ({{ collector.totals['hits/reads'] }})</span> | ||
</div> | ||
<div class="sf-toolbar-info-piece"> | ||
<b>Cache writes</b> | ||
<span>{{ collector.totals.writes }}</span> | ||
</div> | ||
{% endset %} | ||
{% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block menu %} | ||
<span class="label {{ collector.totals.calls == 0 ? 'disabled' }}"> | ||
<span class="icon"> | ||
{{ include('@WebProfiler/Icon/cache.svg') }} | ||
</span> | ||
<strong>Cache</strong> | ||
<span class="count"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should have the time here anymore, for consistency with other panels There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want me to remove it? |
||
<span>{{ collector.totals.calls }}</span> | ||
<span>{{ '%0.2f'|format(collector.totals.time * 1000) }} ms</span> | ||
</span> | ||
</span> | ||
{% endblock %} | ||
|
||
{% block panel %} | ||
<h2>Cache</h2> | ||
<div class="metrics"> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals.calls }}</span> | ||
<span class="label">Total calls</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ '%0.2f'|format(collector.totals.time * 1000) }} ms</span> | ||
<span class="label">Total time</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals.reads }}</span> | ||
<span class="label">Total reads</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals.hits }}</span> | ||
<span class="label">Total hits</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals.misses }}</span> | ||
<span class="label">Total misses</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals.writes }}</span> | ||
<span class="label">Total writes</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals.deletes }}</span> | ||
<span class="label">Total deletes</span> | ||
</div> | ||
<div class="metric"> | ||
<span class="value">{{ collector.totals['hits/reads'] }}</span> | ||
<span class="label">Hits/reads</span> | ||
</div> | ||
</div> | ||
|
||
{% for name, calls in collector.calls %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to have the aggregated stats first as big numbers (as done in other panels), before having the detail for each pool There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no it is not done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<h3>Statistics for '{{ name }}'</h3> | ||
<div class="metrics"> | ||
{% for key, value in collector.statistics[name] %} | ||
<div class="metric"> | ||
<span class="value"> | ||
{% if key == 'time' %} | ||
{{ '%0.2f'|format(1000*value) }} ms | ||
{% else %} | ||
{{ value }} | ||
{% endif %} | ||
</span> | ||
<span class="label">{{ key|capitalize }}</span> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
<h4>Calls for '{{ name }}'</h4> | ||
|
||
{% if not collector.totals.calls %} | ||
<p> | ||
<em>No calls.</em> | ||
</p> | ||
{% else %} | ||
<table> | ||
<thead> | ||
<tr> | ||
<th style="width: 5rem;">Key</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for i, call in calls %} | ||
<tr> | ||
<th style="padding-top:2rem">#{{ i }}</th> | ||
<th style="padding-top:2rem">Pool::{{ call.name }}</th> | ||
</tr> | ||
<tr> | ||
<th>Argument</th> | ||
<td>{{ profiler_dump(call.argument, maxDepth=2) }}</td> | ||
</tr> | ||
<tr> | ||
<th>Results</th> | ||
<td> | ||
{% if call.result != false %} | ||
{{ profiler_dump(call.result, maxDepth=1) }} | ||
{% endif %} | ||
</td> | ||
</tr> | ||
<tr> | ||
<th>Time</th> | ||
<td>{{ '%0.2f'|format((call.end - call.start) * 1000) }} ms</td> | ||
</tr> | ||
|
||
{% endfor %} | ||
</tbody> | ||
|
||
</table> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% endblock %} |
Uh oh!
There was an error while loading. Please reload this page.
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.
what about reporting the "clearer", "provider", "namespace" and/or "default_lifetime" attributes when available?
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.
Note also that this will prevent private services from being removed at compile time.
We have two options here: keep it this way so that even non-used private service could be seen in the panel,
or register this pass just before CachePoolClearerPass.
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.
Sure. But can that be left out of this PR as a future improvement?
What do you prefer? Should I change the order of the passes