Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3592d0d

Browse files
ro0NLfabpot
authored andcommitted
[WebProfilerBundle] Improve cache panel
1 parent db8d87d commit 3592d0d

File tree

2 files changed

+94
-75
lines changed

2 files changed

+94
-75
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/cache.html.twig

Lines changed: 86 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
<div class="sf-toolbar-info-piece">
2424
<b>Cache hits</b>
25-
<span>{{ collector.totals.hits }}/{{ collector.totals.reads }} ({{ collector.totals['hits/reads'] }})</span>
25+
<span>{{ collector.totals.hits }}/{{ collector.totals.reads }}{% if collector.totals.hit_read_ratio is not null %} ({{ collector.totals.hit_read_ratio }}%){% endif %}</span>
2626
</div>
2727
<div class="sf-toolbar-info-piece">
2828
<b>Cache writes</b>
@@ -54,21 +54,14 @@
5454
<span class="label">Total calls</span>
5555
</div>
5656
<div class="metric">
57-
<span class="value">{{ '%0.2f'|format(collector.totals.time * 1000) }} ms</span>
57+
<span class="value">{{ '%0.2f'|format(collector.totals.time * 1000) }} <span class="unit">ms</span></span>
5858
<span class="label">Total time</span>
5959
</div>
60+
<div class="metric-divider"></div>
6061
<div class="metric">
6162
<span class="value">{{ collector.totals.reads }}</span>
6263
<span class="label">Total reads</span>
6364
</div>
64-
<div class="metric">
65-
<span class="value">{{ collector.totals.hits }}</span>
66-
<span class="label">Total hits</span>
67-
</div>
68-
<div class="metric">
69-
<span class="value">{{ collector.totals.misses }}</span>
70-
<span class="label">Total misses</span>
71-
</div>
7265
<div class="metric">
7366
<span class="value">{{ collector.totals.writes }}</span>
7467
<span class="label">Total writes</span>
@@ -77,70 +70,96 @@
7770
<span class="value">{{ collector.totals.deletes }}</span>
7871
<span class="label">Total deletes</span>
7972
</div>
73+
<div class="metric-divider"></div>
74+
<div class="metric">
75+
<span class="value">{{ collector.totals.hits }}</span>
76+
<span class="label">Total hits</span>
77+
</div>
78+
<div class="metric">
79+
<span class="value">{{ collector.totals.misses }}</span>
80+
<span class="label">Total misses</span>
81+
</div>
8082
<div class="metric">
81-
<span class="value">{{ collector.totals['hits/reads'] }}</span>
83+
<span class="value">
84+
{% if collector.totals.hit_read_ratio is null %}
85+
n/a
86+
{% else %}
87+
{{ collector.totals.hit_read_ratio }} <span class="unit">%</span>
88+
{% endif %}
89+
</span>
8290
<span class="label">Hits/reads</span>
8391
</div>
8492
</div>
8593

86-
{% for name, calls in collector.calls %}
87-
<h3>Statistics for '{{ name }}'</h3>
88-
<div class="metrics">
89-
{% for key, value in collector.statistics[name] %}
90-
<div class="metric">
91-
<span class="value">
92-
{% if key == 'time' %}
93-
{{ '%0.2f'|format(1000*value.value) }} ms
94-
{% else %}
95-
{{ value }}
96-
{% endif %}
97-
</span>
98-
<span class="label">{{ key|capitalize }}</span>
99-
</div>
100-
{% endfor %}
101-
</div>
102-
<h4>Calls for '{{ name }}'</h4>
94+
<h2>Pools</h2>
95+
<div class="sf-tabs">
96+
{% for name, calls in collector.calls %}
97+
<div class="tab {{ calls|length == 0 ? 'disabled' }}">
98+
<h3 class="tab-title">{{ name }} <span class="badge">{{ collector.statistics[name].calls }}</span></h3>
10399

104-
{% if not collector.totals.calls %}
105-
<p>
106-
<em>No calls.</em>
107-
</p>
108-
{% else %}
109-
<table>
110-
<thead>
111-
<tr>
112-
<th style="width: 5rem;">Key</th>
113-
<th>Value</th>
114-
</tr>
115-
</thead>
116-
<tbody>
117-
{% for i, call in calls %}
118-
<tr>
119-
<th style="padding-top:2rem">#{{ i }}</th>
120-
<th style="padding-top:2rem">Pool::{{ call.name }}</th>
121-
</tr>
122-
<tr>
123-
<th>Argument</th>
124-
<td>{{ profiler_dump(call.argument, maxDepth=2) }}</td>
125-
</tr>
126-
<tr>
127-
<th>Results</th>
128-
<td>
129-
{% if call.result != false %}
130-
{{ profiler_dump(call.result, maxDepth=1) }}
100+
<div class="tab-content">
101+
<h3>Statistics</h3>
102+
<div class="metrics">
103+
{% for key, value in collector.statistics[name] %}
104+
<div class="metric">
105+
<span class="value">
106+
{% if key == 'time' %}
107+
{{ '%0.2f'|format(1000 * value.value) }} <span class="unit">ms</span>
108+
{% elseif key == 'hit_read_ratio' %}
109+
{% if value.value is null %}
110+
n/a
111+
{% else %}
112+
{{ value }} <span class="unit">%</span>
113+
{% endif %}
114+
{% else %}
115+
{{ value }}
116+
{% endif %}
117+
</span>
118+
<span class="label">{{ key == 'hit_read_ratio' ? 'Hits/reads' : key|capitalize }}</span>
119+
</div>
120+
{% if key == 'time' or key == 'deletes' %}
121+
<div class="metric-divider"></div>
131122
{% endif %}
132-
</td>
133-
</tr>
134-
<tr>
135-
<th>Time</th>
136-
<td>{{ '%0.2f'|format((call.end - call.start) * 1000) }} ms</td>
137-
</tr>
138-
139-
{% endfor %}
140-
</tbody>
123+
{% endfor %}
124+
</div>
141125

142-
</table>
143-
{% endif %}
144-
{% endfor %}
126+
<h4>Calls</h4>
127+
{% if calls|length == 0 %}
128+
<div class="empty">
129+
<p>No calls</p>
130+
</div>
131+
{% else %}
132+
<table>
133+
<thead>
134+
<tr>
135+
<th>#</th>
136+
<th class="key">Key</th>
137+
<th>Value</th>
138+
</tr>
139+
</thead>
140+
<tbody>
141+
{% for call in calls %}
142+
{% set separatorStyle = not loop.first ? ' style="border-top-width: medium;"' : '' %}
143+
<tr>
144+
<td class="font-normal text-small text-muted nowrap" rowspan="3"{{ separatorStyle|raw }}>{{ loop.index }}</td>
145+
<th{{ separatorStyle|raw }}>{{ call.name }}</th>
146+
<td{{ separatorStyle|raw }}>{{ profiler_dump(call.value.argument, maxDepth=2) }}</td>
147+
</tr>
148+
<tr>
149+
<th>Result</th>
150+
<td>{{ profiler_dump(call.value.result, maxDepth=1) }}</td>
151+
</tr>
152+
<tr>
153+
<th>Time</th>
154+
<td>{{ '%0.2f'|format((call.end - call.start) * 1000) }} ms</td>
155+
</tr>
156+
{% endfor %}
157+
</tbody>
158+
</table>
159+
{% endif %}
160+
</div>
161+
</div>
162+
{% endfor %}
163+
</div>
145164

146165
{% endblock %}

src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ private function calculateStatistics()
103103
'calls' => 0,
104104
'time' => 0,
105105
'reads' => 0,
106-
'hits' => 0,
107-
'misses' => 0,
108106
'writes' => 0,
109107
'deletes' => 0,
108+
'hits' => 0,
109+
'misses' => 0,
110110
);
111111
/** @var TraceableAdapterEvent $call */
112112
foreach ($calls as $call) {
@@ -138,9 +138,9 @@ private function calculateStatistics()
138138
}
139139
}
140140
if ($statistics[$name]['reads']) {
141-
$statistics[$name]['hits/reads'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2).'%';
141+
$statistics[$name]['hit_read_ratio'] = round(100 * $statistics[$name]['hits'] / $statistics[$name]['reads'], 2);
142142
} else {
143-
$statistics[$name]['hits/reads'] = 'N/A';
143+
$statistics[$name]['hit_read_ratio'] = null;
144144
}
145145
}
146146

@@ -157,20 +157,20 @@ private function calculateTotalStatistics()
157157
'calls' => 0,
158158
'time' => 0,
159159
'reads' => 0,
160-
'hits' => 0,
161-
'misses' => 0,
162160
'writes' => 0,
163161
'deletes' => 0,
162+
'hits' => 0,
163+
'misses' => 0,
164164
);
165165
foreach ($statistics as $name => $values) {
166166
foreach ($totals as $key => $value) {
167167
$totals[$key] += $statistics[$name][$key];
168168
}
169169
}
170170
if ($totals['reads']) {
171-
$totals['hits/reads'] = round(100 * $totals['hits'] / $totals['reads'], 2).'%';
171+
$totals['hit_read_ratio'] = round(100 * $totals['hits'] / $totals['reads'], 2);
172172
} else {
173-
$totals['hits/reads'] = 'N/A';
173+
$totals['hit_read_ratio'] = null;
174174
}
175175

176176
return $totals;

0 commit comments

Comments
 (0)