Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

PersistenceCacheCollector.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishDebugBundle\Collector;
8
9 use eZ\Publish\Core\Persistence\Cache\PersistenceLogger;
10 use Symfony\Component\HttpFoundation\Request;
11 use Symfony\Component\HttpFoundation\Response;
12 use Symfony\Component\HttpKernel\DataCollector\DataCollector;
13
17 class PersistenceCacheCollector extends DataCollector
18 {
20 private $logger;
21
22 public function __construct(PersistenceLogger $logger)
23 {
24 $this->logger = $logger;
25 }
26
27 public function collect(Request $request, Response $response, \Exception $exception = null)
28 {
29 $this->data = [
30 'stats' => $this->logger->getStats(),
31 'calls_logging_enabled' => $this->logger->isCallsLoggingEnabled(),
32 'calls' => $this->logger->getCalls(),
33 'handlers' => $this->logger->getLoadedUnCachedHandlers(),
34 ];
35 }
36
37 public function getName()
38 {
39 return 'ezpublish.debug.persistence';
40 }
41
49 public function getCount()
50 {
51 return $this->data['stats']['call'] + $this->data['stats']['miss'];
52 }
53
61 public function getStats()
62 {
63 return $this->data['stats'];
64 }
65
73 public function getCallsLoggingEnabled()
74 {
75 return $this->data['calls_logging_enabled'];
76 }
77
83 public function getCalls()
84 {
85 if (empty($this->data['calls'])) {
86 return [];
87 }
88
89 $calls = $count = [];
90 foreach ($this->data['calls'] as $hash => $call) {
91 list($class, $method) = \explode('::', $call['method']);
92 $namespace = \explode('\\', $class);
93 $class = \array_pop($namespace);
94 $calls[$hash] = [
95 'namespace' => $namespace,
96 'class' => $class,
97 'method' => $method,
98 'arguments' => $call['arguments'],
99 'stats' => $call['stats'],
100 ];
101 // Get traces, and order them to have the most called first
102 $calls[$hash]['traces'] = $call['traces'];
103 $traceCount = [];
104 foreach ($call['traces'] as $traceHash => $traceData) {
105 $traceCount[$traceHash] = $traceData['count'];
106 }
107 \array_multisort($traceCount, SORT_DESC, SORT_NUMERIC, $calls[$hash]['traces']);
108
109 // For call sorting count all calls, but weight in-memory lookups lower
110 $count[$hash] = $call['stats']['uncached'] + $call['stats']['miss'] + $call['stats']['hit'] + ($call['stats']['memory'] * 0.001);
111 }
112
113 // Order calls
114 \array_multisort($count, SORT_DESC, SORT_NUMERIC, $calls);
115
116 return $calls;
117 }
118
124 public function getHandlers()
125 {
126 $handlers = [];
127 foreach ($this->data['handlers'] as $handler => $count) {
128 list($class, $method) = explode('::', $handler);
129 unset($class);
130 $handlers[$method] = $method . '(' . $count . ')';
131 }
132
133 return $handlers;
134 }
135
141 public function getHandlersCount()
142 {
143 return array_sum($this->data['handlers']);
144 }
145 }
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector
Data collector listing SPI cache calls.
Definition: PersistenceCacheCollector.php:18
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getCalls
getCalls()
Returns all calls.
Definition: PersistenceCacheCollector.php:83
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\__construct
__construct(PersistenceLogger $logger)
Definition: PersistenceCacheCollector.php:22
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getName
getName()
Definition: PersistenceCacheCollector.php:37
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getHandlersCount
getHandlersCount()
Returns un cached handlers being loaded.
Definition: PersistenceCacheCollector.php:141
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getHandlers
getHandlers()
Returns un cached handlers being loaded.
Definition: PersistenceCacheCollector.php:124
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\$logger
$logger
Definition: PersistenceCacheCollector.php:20
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\collect
collect(Request $request, Response $response, \Exception $exception=null)
Definition: PersistenceCacheCollector.php:27
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getStats
getStats()
Returns stats on Persistance cache usage.
Definition: PersistenceCacheCollector.php:61
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getCallsLoggingEnabled
getCallsLoggingEnabled()
Returns flag to indicate if logging of calls is enabled or not.
Definition: PersistenceCacheCollector.php:73
eZ\Bundle\EzPublishDebugBundle\Collector\PersistenceCacheCollector\getCount
getCount()
Returns call count.
Definition: PersistenceCacheCollector.php:49
eZ\Publish\Core\Persistence\Cache\PersistenceLogger
Log un-cached & cached use of SPI Persistence.
Definition: PersistenceLogger.php:15
eZ\Bundle\EzPublishDebugBundle\Collector
Definition: EzPublishCoreCollector.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.