Aggregate repeated calls to reduce size of collected data

This commit is contained in:
Thibaud Fabre
2016-01-28 13:54:03 +01:00
parent 4c493dc717
commit ed110c1140
2 changed files with 33 additions and 6 deletions

View File

@@ -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,
'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;
}
/**

View File

@@ -166,12 +166,14 @@
<th>Call type</th>
<th>Key</th>
<th>Hit / Miss</th>
<th>Count</th>
</tr>
</thead>
<tbody>
{% set callCount = 1 %}
{% for call in collector.calls %}
<tr>
<td>{{ loop.index }}</td>
<td>{{ callCount }}</td>
<td>
{% if call['type'] != 'fetch' %}
<strong>{{ call['type'] }}</strong>
@@ -181,7 +183,9 @@
</td>
<td>{{ call['key'] }}</td>
<td>{% if call['hit'] %}HIT{% else %}<strong>MISS</strong>{% endif %}</td>
<td>{{ call['count'] }}</td>
</tr>
{% set callCount = callCount + call['count'] %}
{% endfor %}
</tbody>
</table>