mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
Add call summaries by type and key in cache profiler
This commit is contained in:
@@ -42,6 +42,21 @@ class CacheStatisticsSubscriber implements EventSubscriberInterface
|
||||
return '[ root ]';
|
||||
}
|
||||
|
||||
public function getCallSummary()
|
||||
{
|
||||
if ($this->cache instanceof TraceableCache) {
|
||||
return $this->cache->getSummary();
|
||||
}
|
||||
|
||||
return [
|
||||
'calls' => 0,
|
||||
'hits' => 0,
|
||||
'misses' => 0,
|
||||
'calls_by_type' => [],
|
||||
'calls_by_key' => []
|
||||
];
|
||||
}
|
||||
|
||||
public function getCalls()
|
||||
{
|
||||
if ($this->cache instanceof TraceableCache) {
|
||||
|
@@ -35,6 +35,11 @@ class CacheDataCollector implements DataCollectorInterface
|
||||
*/
|
||||
private $calls = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $callSummary;
|
||||
|
||||
/**
|
||||
* @param CacheStatisticsSubscriber $cacheStatisticsSubscriber
|
||||
*/
|
||||
@@ -73,6 +78,7 @@ class CacheDataCollector implements DataCollectorInterface
|
||||
);
|
||||
|
||||
$this->calls = $this->statsListener->getCalls();
|
||||
$this->callSummary = $this->statsListener->getCallSummary();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +102,11 @@ class CacheDataCollector implements DataCollectorInterface
|
||||
return $this->calls;
|
||||
}
|
||||
|
||||
public function getCallSummary()
|
||||
{
|
||||
return $this->callSummary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CacheProfileSummary
|
||||
*/
|
||||
|
@@ -24,7 +24,15 @@ class TraceableCache implements Cache, PhraseaCache
|
||||
*/
|
||||
private $calls = [];
|
||||
|
||||
/**
|
||||
private $summary = [
|
||||
'calls' => 0,
|
||||
'hits' => 0,
|
||||
'misses' => 0,
|
||||
'calls_by_type' => [],
|
||||
'calls_by_key' => [],
|
||||
];
|
||||
|
||||
/*s*
|
||||
* @param PhraseaCache $cache
|
||||
*/
|
||||
public function __construct(PhraseaCache $cache)
|
||||
@@ -34,12 +42,29 @@ class TraceableCache implements Cache, PhraseaCache
|
||||
|
||||
private function collect($type, $id, $hit = true, $result = null)
|
||||
{
|
||||
$this->summary['calls']++;
|
||||
$this->summary['hits'] += $hit ? 1 : 0;
|
||||
$this->summary['misses'] += $hit ? 0 : 1;
|
||||
|
||||
if (! array_key_exists($type, $this->summary['calls_by_type'])) {
|
||||
$this->summary['calls_by_type'][$type] = 0;
|
||||
}
|
||||
|
||||
$this->summary['calls_by_type'][$type]++;
|
||||
|
||||
if (! array_key_exists($id, $this->summary['calls_by_key'])) {
|
||||
$this->summary['calls_by_key'][$id] = 0;
|
||||
}
|
||||
|
||||
$this->summary['calls_by_key'][$id]++;
|
||||
|
||||
$this->calls[] = [
|
||||
'type' => $type,
|
||||
'key' => $id,
|
||||
'result' => $result,
|
||||
'hit' => (bool) $hit
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +83,14 @@ class TraceableCache implements Cache, PhraseaCache
|
||||
return $this->calls;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an entry from the cache.
|
||||
*
|
||||
|
@@ -75,7 +75,7 @@ class WebProfilerServiceProvider implements ServiceProviderInterface
|
||||
return new CacheStatisticsSubscriber($app['cache']);
|
||||
});
|
||||
|
||||
$app->share($app->extend('data_collectors', function ($collectors) use ($app) {
|
||||
$app['data_collectors'] = $app->share($app->extend('data_collectors', function ($collectors) use ($app) {
|
||||
$collectors['db'] = $app->share(function ($app) {
|
||||
/** @var DoctrineDataCollector $collector */
|
||||
$collector = $app['data_collectors.doctrine'];
|
||||
|
@@ -80,6 +80,69 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Hit miss summary</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Call stat</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">Hits</th>
|
||||
<td>{{ collector.callSummary['hits'] }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Misses</th>
|
||||
<td>{{ collector.callSummary['misses'] }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Total</th>
|
||||
<td>{{ collector.callSummary['calls'] }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Calls by type summary</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Operation</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for callType, count in collector.callSummary['calls_by_type'] %}
|
||||
<tr>
|
||||
<td>{{ callType }}</td>
|
||||
<td>{{ count }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Calls by key summary</h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Operation</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for callKey, count in collector.callSummary['calls_by_key'] %}
|
||||
<tr>
|
||||
<td>{{ callKey }}</td>
|
||||
<td>{{ count }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3>Call list</h3>
|
||||
|
||||
<table>
|
||||
|
Reference in New Issue
Block a user