8000 [WebProfilerBundle] Improve cache panel by ro0NL · Pull Request #22129 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WebProfilerBundle] Improve cache panel #22129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improved metric formatting
  • Loading branch information
ro0NL committed Mar 23, 2017
commit 40a6c7527afe9a81caf1aefb9953873ddd9f9fec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<div class="sf-toolbar-info-piece">
<b>Cache hits</b>
<span>{{ collector.totals.hits }}/{{ collector.totals.reads }} ({{ collector.totals['hits/reads'] }})</span>
<span>{{ collector.totals.hits }}/{{ collector.totals.reads }}{% if collector.totals.hit_read_ratio is not null %} ({{ collector.totals.hit_read_ratio }}%){% endif %}</span>
</div>
<div class="sf-toolbar-info-piece">
<b>Cache writes</b>
Expand Down Expand Up @@ -54,21 +54,14 @@
<span class="label">Total calls</span>
</div>
<div class="metric">
<span class="value">{{ '%0.2f'|format(collector.totals.time * 1000) }} ms</span>
<span class="value">{{ '%0.2f'|format(collector.totals.time * 1000) }} <span class="unit">ms</span></span>
<span class="label">Total time</span>
</div>
<div class="metric-divider"></div>
<div class="metric">
<span class="value">{{ collector.totals.reads }}</span>
<span class="label">Total reads</span>
</div>
<div class="metric">
<span class="value">{{ collector.totals.hits }}</span>
<span class="label">Total hits</span>
</div>
<div class="metric">
<span class="value">{{ collector.totals.misses }}</span>
<span class="label">Total misses</span>
</div>
<div class="metric">
<span class="value">{{ collector.totals.writes }}</span>
<span class="label">Total writes</span>
Expand All @@ -77,8 +70,23 @@
<span class="value">{{ collector.totals.deletes }}</span>
<span class="label">Total deletes</span>
</div>
<div class="metric-divider"></div>
<div class="metric">
<span class="value">{{ collector.totals.hits }}</span>
<span class="label">Total hits</span>
</div>
<div class="metric">
<span class="value">{{ collector.totals['hits/reads'] }}</span>
<span class="value">{{ collector.totals.misses }}</span>
<span class="label">Total misses</span>
</div>
<div class="metric">
<span class="value">
{% if collector.totals.hit_read_ratio is null %}
n/a
{% else %}
{{ collector.totals.hit_read_ratio }} <span class="unit">%</span>
{% endif %}
</span>
<span class="label">Hits/reads</span>
</div>
</div>
Expand All @@ -95,13 +103,22 @@
<div class="metric">
<span class="value">
{% if key == 'time' %}
{{ '%0.2f'|format(1000*value.value) }} ms
{{ '%0.2f'|format(1000*value.value) }} <span class="unit">ms</span>
{% elseif key == 'hit_read_ratio' %}
{% if value.value is null %}
n/a
{% else %}
{{ value }} <span class="unit">%</span>
{% endif %}
{% else %}
{{ value }}
{% endif %}
</span>
<span class="label">{{ key|capitalize }}</span>
<span class="label">{{ key == 'hit_read_ratio' ? 'Hits/reads' : key|capitalize }}</span>
</div>
{% if key == 'time' or key == 'deletes' %}
<div class="metric-divider"></div>
{% endif %}
{% endfor %}
</div>

Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ private function calculateStatistics()
'calls' => 0,
'time' => 0,
'reads' => 0,
'hits' => 0,
'misses' => 0,
'writes' => 0,
'deletes' => 0,
'hits' => 0,
'misses' => 0,
);
/** @var TraceableAdapterEvent $call */
foreach ($calls as $call) {
Expand Down Expand Up @@ -138,9 +138,9 @@ private function calculateStatistics()
}
}
if ($statistics[$name]['reads']) {
$statistics[$name]['hits/reads'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2).'%';
$statistics[$name]['hit_read_ratio'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2);
} else {
$statistics[$name]['hits/reads'] = 'N/A';
$statistics[$name]['hit_read_ratio'] = null;
}
}

Expand All @@ -157,20 +157,20 @@ private function calculateTotalStatistics()
'calls' => 0,
'time' => 0,
'reads' => 0,
'writes' => 0,
'deletes' => 0,
'hits' => 0,
'misses' => 0,
'writes' => 0,
'deletes' => 0,
);
foreach ($statistics as $name => $values) {
foreach ($totals as $key => $value) {
$totals[$key] += $statistics[$name][$key];
}
}
if ($totals['reads']) {
$totals['hits/reads'] = round(100 * $totals['hits'] / $totals['reads'], 2).'%';
$totals['hit_read_ratio'] = round(100 * $totals['hits'] / $totals['reads'], 2);
} else {
$totals['hits/reads'] = 'N/A';
$totals['hit_read_ratio'] = null;
}

return $totals;
Expand Down
0