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->summary['calls_by_key'][$id]['total']++;
$this->calls[] = [ $lastCall = end($this->calls);
$callData = [
'type' => $type, 'type' => $type,
'key' => $id, 'key' => $id,
'result' => $result, '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,22 +166,26 @@
<th>Call type</th> <th>Call type</th>
<th>Key</th> <th>Key</th>
<th>Hit / Miss</th> <th>Hit / Miss</th>
<th>Count</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% set callCount = 1 %}
{% for call in collector.calls %} {% for call in collector.calls %}
<tr> <tr>
<td>{{ loop.index }}</td> <td>{{ callCount }}</td>
<td> <td>
{% if call['type'] != 'fetch' %} {% if call['type'] != 'fetch' %}
<strong>{{ call['type'] }}</strong> <strong>{{ call['type'] }}</strong>
{% else %} {% else %}
{{ call['type'] }} {{ call['type'] }}
{% endif %} {% endif %}
</td> </td>
<td>{{ call['key'] }}</td> <td>{{ call['key'] }}</td>
<td>{% if call['hit'] %}HIT{% else %}<strong>MISS</strong>{% endif %}</td> <td>{% if call['hit'] %}HIT{% else %}<strong>MISS</strong>{% endif %}</td>
<td>{{ call['count'] }}</td>
</tr> </tr>
{% set callCount = callCount + call['count'] %}
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>