Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Closed
wants to merge 9 commits into from
Closed
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
@@ -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)));
Copy link
Member

@nicolas-grekas nicolas-grekas Jan 2, 2017

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?

Copy link
Member

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.

Copy link
Member Author

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?

Sure. But can that be left out of this PR as a future improvement?

or register this pass just before CachePoolClearerPass.

What do you prefer? Should I change the order of the passes

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $

$loader->load('profiling.xml');
$loader->load('collectors.xml');
$loader->load('cache_debug.xml');

if ($this->formConfigEnabled) {
$loader->load('form_debug.xml');
Expand Down
2 changes: 2 additions & 0 deletions 2 src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CacheCollectorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ControllerArgumentValueResolverPass;
Expand Down Expand Up @@ -105,6 +106,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new ConfigCachePass());
$container->addCompilerPass(new CacheCollectorPass());
}
}
}
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">
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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 %}
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it is not done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misunderstood you. I put the aggregated stats for each adapter as big numbers.
screen shot 2017-01-02 at 18 46 11

<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 %}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.