1 | <?php |
||
16 | class PersistenceLogger |
||
17 | { |
||
18 | const NAME = 'PersistenceLogger'; |
||
19 | |||
20 | /** |
||
21 | * @var int[] |
||
22 | */ |
||
23 | protected $stats = [ |
||
24 | 'uncached' => 0, |
||
25 | 'miss' => 0, |
||
26 | 'hit' => 0, |
||
27 | 'memory' => 0, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $logCalls = true; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $calls = []; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $unCachedHandlers = []; |
||
44 | |||
45 | /** |
||
46 | * @param bool $logCalls Flag to enable logging of calls or not, provides extra debug info about calls made to SPI |
||
47 | * level, including where they come form. However this uses quite a bit of memory. |
||
48 | */ |
||
49 | public function __construct(bool $logCalls = true) |
||
53 | |||
54 | /** |
||
55 | * Log uncached SPI calls with method name and arguments. |
||
56 | * |
||
57 | * NOTE: As of 7.5 this method is meant for logging calls to uncached spi method calls, |
||
58 | * for cache miss calls to cached SPI methods migrate to use {@see logCacheMiss()}. |
||
59 | * |
||
60 | * @param string $method |
||
61 | * @param array $arguments |
||
62 | */ |
||
63 | public function logCall(string $method, array $arguments = []): void |
||
80 | |||
81 | /** |
||
82 | * Log Cache miss, gets info it needs by backtrace if needed. |
||
83 | * |
||
84 | * @since 7.5 |
||
85 | * |
||
86 | * @param array $arguments |
||
87 | * @param int $traceOffset |
||
88 | */ |
||
89 | public function logCacheMiss(array $arguments = [], int $traceOffset = 2): void |
||
104 | |||
105 | /** |
||
106 | * Log a Cache hit, gets info it needs by backtrace if needed. |
||
107 | * |
||
108 | * @since 7.5 |
||
109 | * |
||
110 | * @param array $arguments |
||
111 | * @param int $traceOffset |
||
112 | * @param bool $inMemory Denotes is cache hit was from memory (php variable), as opposed to from cache pool which |
||
113 | * is usually disk or remote cache service. |
||
114 | */ |
||
115 | public function logCacheHit(array $arguments = [], int $traceOffset = 2, bool $inMemory = false): void |
||
135 | |||
136 | /** |
||
137 | * Collection method for {@see logCacheHit()}, {@see logCacheMiss()} & {@see logCall()}. |
||
138 | * |
||
139 | * @param $method |
||
140 | * @param array $arguments |
||
141 | * @param array $trimmedBacktrace |
||
142 | * @param string $type |
||
143 | */ |
||
144 | private function collectCacheCallData($method, array $arguments, array $trimmedBacktrace, string $type): void |
||
175 | |||
176 | /** |
||
177 | * Simplify trace to an array of strings. |
||
178 | * |
||
179 | * Skipps any traces from Syfony proxies or closures to make trace as readable as possible in as few lines as |
||
180 | * possible. And point is to identify which code outside kernel is triggering the SPI call, so trace stops one |
||
181 | * call after namespace is no longer in eZ\Publish\Core\. |
||
182 | * |
||
183 | * @param array $backtrace Partial backtrace from |debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) or similar. |
||
184 | * |
||
185 | * @return string[] |
||
186 | */ |
||
187 | private function getSimpleCallTrace(array $backtrace): array |
||
206 | |||
207 | /** |
||
208 | * Log un-cached handler being loaded. |
||
209 | * |
||
210 | * @param string $handler |
||
211 | */ |
||
212 | public function logUnCachedHandler(string $handler): void |
||
219 | |||
220 | public function getName(): string |
||
224 | |||
225 | /** |
||
226 | * Counts the total of spi uncached call (cache miss and uncached calls). |
||
227 | * |
||
228 | * @deprecated Since 7.5, use getStats(). |
||
229 | */ |
||
230 | public function getCount(): int |
||
234 | |||
235 | /** |
||
236 | * Get stats (call/miss/hit/memory). |
||
237 | * |
||
238 | * @since 7.5 |
||
239 | */ |
||
240 | public function getStats(): array |
||
244 | |||
245 | public function isCallsLoggingEnabled(): bool |
||
249 | |||
250 | public function getCalls(): array |
||
254 | |||
255 | public function getLoadedUnCachedHandlers(): array |
||
259 | } |
||
260 |