From ed110c114046fecdc7e8656939f96c9d141dbc0a Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Thu, 28 Jan 2016 13:54:03 +0100 Subject: [PATCH] Aggregate repeated calls to reduce size of collected data --- .../Phrasea/Core/Profiler/TraceableCache.php | 29 +++++++++++++++++-- templates-profiler/cache.html.twig | 10 +++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php b/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php index cbdaf1b9c9..598fb42321 100644 --- a/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php +++ b/lib/Alchemy/Phrasea/Core/Profiler/TraceableCache.php @@ -77,13 +77,36 @@ class TraceableCache implements Cache, PhraseaCache $this->summary['calls_by_key'][$id]['total']++; - $this->calls[] = [ + $lastCall = end($this->calls); + $callData = [ 'type' => $type, - 'key' => $id, + 'key' => $id, 'result' => $result, - 'hit' => (bool) $hit + 'hit' => (bool) $hit, + 'count' => 1 ]; + if ($this->compareCalls($lastCall, $callData)) { + $lastCall['count']++; + $callData = $lastCall; + + array_pop($this->calls); + } + + $this->calls[] = $callData; + } + + private function compareCalls(array $previousCall, array $currentCall) + { + $keys = [ 'type', 'key', 'result', 'hit']; + + foreach ($keys as $key) { + if ($previousCall[$key] != $currentCall[$key]) { + return false; + } + } + + return true; } /** diff --git a/templates-profiler/cache.html.twig b/templates-profiler/cache.html.twig index 2feffa7fb9..434505015e 100644 --- a/templates-profiler/cache.html.twig +++ b/templates-profiler/cache.html.twig @@ -166,22 +166,26 @@ Call type Key Hit / Miss + Count + {% set callCount = 1 %} {% for call in collector.calls %} - {{ loop.index }} + {{ callCount }} {% if call['type'] != 'fetch' %} - {{ call['type'] }} + {{ call['type'] }} {% else %} - {{ call['type'] }} + {{ call['type'] }} {% endif %} {{ call['key'] }} {% if call['hit'] %}HIT{% else %}MISS{% endif %} + {{ call['count'] }} + {% set callCount = callCount + call['count'] %} {% endfor %}