[Stopwatch] Get the "real size" used & minor tweaks
This commit is contained in:
parent
f3c644061a
commit
d0433b69aa
@ -16,15 +16,15 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% block toolbar %}
|
{% block toolbar %}
|
||||||
{% set total_time = collector.events|length ? '%.0f ms'|format(collector.totaltime) : 'n/a' %}
|
{% set duration = collector.events|length ? '%.0f ms'|format(collector.duration) : 'n/a' %}
|
||||||
{% set icon %}
|
{% set icon %}
|
||||||
<img width="16" height="28" alt="Time" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAcCAYAAABoMT8aAAABqUlEQVR42t2Vv0sCYRyHX9OmEhsMx/YKGlwLQ69DTEUSBJEQEy5J3FRc/BsuiFqEIIcQIRo6ysUhoaBBWhoaGoJwiMJLglRKrs8bXgienmkQdPDAwX2f57j3fhFJkkbiPwTK5bIiFoul3kmPud8MqKMewDXpwuGww+12n9hsNhFnlijYf/Z4PDmO45Yxo+10ZFGTyWRMEItU6AdCx7lczkgd6n7J2Wx2xm63P6jJMk6n80YQBBN1aUDv9XqvlAbbm2LE7/cLODRB0un0VveAeoDC8/waCQQC18MGQqHQOcEKvw8bcLlcL6TfYnVtCrGRAlartUUYhmn1jKg/E3USjUYfhw3E4/F7ks/nz4YNFIvFQ/ogbUYikdefyqlU6gnuOg2YK5XKvs/n+xhUDgaDTVEUt+HO04ABOBA5isViDTU5kUi81Wq1AzhWMEkDGmAEq2C3UCjcYXGauDvfEsuyUjKZbJRKpVvM8IABU9SVX+cxYABmwIE9cFqtVi9xtgvsC2AHbIAFoKey0gdlHEyDObAEWLACFsEsMALdIJ80+dK0bTS95v7+v/AJnis0eO906QwAAAAASUVORK5CYII="/>
|
<img width="16" height="28" alt="Time" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAcCAYAAABoMT8aAAABqUlEQVR42t2Vv0sCYRyHX9OmEhsMx/YKGlwLQ69DTEUSBJEQEy5J3FRc/BsuiFqEIIcQIRo6ysUhoaBBWhoaGoJwiMJLglRKrs8bXgienmkQdPDAwX2f57j3fhFJkkbiPwTK5bIiFoul3kmPud8MqKMewDXpwuGww+12n9hsNhFnlijYf/Z4PDmO45Yxo+10ZFGTyWRMEItU6AdCx7lczkgd6n7J2Wx2xm63P6jJMk6n80YQBBN1aUDv9XqvlAbbm2LE7/cLODRB0un0VveAeoDC8/waCQQC18MGQqHQOcEKvw8bcLlcL6TfYnVtCrGRAlartUUYhmn1jKg/E3USjUYfhw3E4/F7ks/nz4YNFIvFQ/ogbUYikdefyqlU6gnuOg2YK5XKvs/n+xhUDgaDTVEUt+HO04ABOBA5isViDTU5kUi81Wq1AzhWMEkDGmAEq2C3UCjcYXGauDvfEsuyUjKZbJRKpVvM8IABU9SVX+cxYABmwIE9cFqtVi9xtgvsC2AHbIAFoKey0gdlHEyDObAEWLACFsEsMALdIJ80+dK0bTS95v7+v/AJnis0eO906QwAAAAASUVORK5CYII="/>
|
||||||
<span>{{ total_time }}</span>
|
<span>{{ duration }}</span>
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{% set text %}
|
{% set text %}
|
||||||
<div class="sf-toolbar-info-piece">
|
<div class="sf-toolbar-info-piece">
|
||||||
<b>Total time</b>
|
<b>Total time</b>
|
||||||
<span>{{ total_time }}</span>
|
<span>{{ duration }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': profiler_url } %}
|
{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': profiler_url } %}
|
||||||
@ -54,7 +54,7 @@
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 20%">Total time</th>
|
<th style="width: 20%">Total time</th>
|
||||||
<td>{{ '%.0f'|format(collector.totaltime) }} ms</td>
|
<td>{{ '%.0f'|format(collector.duration) }} ms</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Initialization time</th>
|
<th>Initialization time</th>
|
||||||
@ -70,7 +70,7 @@
|
|||||||
<h3>
|
<h3>
|
||||||
{{ profile.parent ? "Request" : "Main Request" }}
|
{{ profile.parent ? "Request" : "Main Request" }}
|
||||||
<small>
|
<small>
|
||||||
- {{ collector.events.__section__.totaltime }} ms
|
- {{ collector.events.__section__.duration }} ms
|
||||||
{% if profile.parent %}
|
{% if profile.parent %}
|
||||||
- <a href="{{ path('_profiler', { 'token': profile.parent.token, 'panel': 'time' }) }}">parent</a>
|
- <a href="{{ path('_profiler', { 'token': profile.parent.token, 'panel': 'time' }) }}">parent</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -86,7 +86,7 @@
|
|||||||
{% set events = child.getcollector('time').events %}
|
{% set events = child.getcollector('time').events %}
|
||||||
<h3>
|
<h3>
|
||||||
Sub-request "<a href="{{ path('_profiler', { 'token': child.token, 'panel': 'time' }) }}">{{ child.getcollector('request').requestattributes.get('_controller') }}</a>"
|
Sub-request "<a href="{{ path('_profiler', { 'token': child.token, 'panel': 'time' }) }}">{{ child.getcollector('request').requestattributes.get('_controller') }}</a>"
|
||||||
<small> - {{ events.__section__.totaltime }} ms</small>
|
<small> - {{ events.__section__.duration }} ms</small>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
{{ display_timeline('timeline_' ~ child.token, events, colors) }}
|
{{ display_timeline('timeline_' ~ child.token, events, colors) }}
|
||||||
@ -198,7 +198,7 @@
|
|||||||
|
|
||||||
// Filter events whose total time is below the threshold.
|
// Filter events whose total time is below the threshold.
|
||||||
drawableEvents = request.events.filter(function(event) {
|
drawableEvents = request.events.filter(function(event) {
|
||||||
return event.totaltime >= threshold;
|
return event.duration >= threshold;
|
||||||
});
|
});
|
||||||
|
|
||||||
canvasHeight += gapPerEvent * drawableEvents.length;
|
canvasHeight += gapPerEvent * drawableEvents.length;
|
||||||
@ -315,7 +315,7 @@
|
|||||||
ctx.fillStyle = "#444";
|
ctx.fillStyle = "#444";
|
||||||
ctx.font = "12px sans-serif";
|
ctx.font = "12px sans-serif";
|
||||||
text = event.name;
|
text = event.name;
|
||||||
ms = " ~ " + (event.totaltime < 1 ? event.totaltime : parseInt(event.totaltime, 10)) + " ms / ~ " + event.memory + " MB";
|
ms = " ~ " + (event.duration < 1 ? event.duration : parseInt(event.duration, 10)) + " ms / ~ " + event.memory + " MB";
|
||||||
if (x + event.starttime * ratio + ctx.measureText(text + ms).width > width) {
|
if (x + event.starttime * ratio + ctx.measureText(text + ms).width > width) {
|
||||||
ctx.textAlign = "end";
|
ctx.textAlign = "end";
|
||||||
ctx.font = "10px sans-serif";
|
ctx.font = "10px sans-serif";
|
||||||
@ -453,8 +453,8 @@
|
|||||||
"origin": {{ "%F"|format(event.origin) }},
|
"origin": {{ "%F"|format(event.origin) }},
|
||||||
"starttime": {{ "%F"|format(event.starttime) }},
|
"starttime": {{ "%F"|format(event.starttime) }},
|
||||||
"endtime": {{ "%F"|format(event.endtime) }},
|
"endtime": {{ "%F"|format(event.endtime) }},
|
||||||
"totaltime": {{ "%F"|format(event.totaltime) }},
|
"duration": {{ "%F"|format(event.duration) }},
|
||||||
"memory": {{ "%.1f"|format(event.memory / 1024 / 1024) }},
|
"memory": {{ "%.1F"|format(event.memory / 1024 / 1024) }},
|
||||||
"periods": [
|
"periods": [
|
||||||
{%- for period in event.periods -%}
|
{%- for period in event.periods -%}
|
||||||
{"start": {{ "%F"|format(period.starttime) }}, "end": {{ "%F"|format(period.endtime) }}}{{ loop.last ? '' : ', ' }}
|
{"start": {{ "%F"|format(period.starttime) }}, "end": {{ "%F"|format(period.endtime) }}}{{ loop.last ? '' : ', ' }}
|
||||||
|
@ -70,11 +70,11 @@ class TimeDataCollector extends DataCollector
|
|||||||
*
|
*
|
||||||
* @return float The elapsed time
|
* @return float The elapsed time
|
||||||
*/
|
*/
|
||||||
public function getTotalTime()
|
public function getDuration()
|
||||||
{
|
{
|
||||||
$lastEvent = $this->data['events']['__section__'];
|
$lastEvent = $this->data['events']['__section__'];
|
||||||
|
|
||||||
return $lastEvent->getOrigin() + $lastEvent->getTotalTime() - $this->getStartTime();
|
return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +75,8 @@ class StopwatchEvent
|
|||||||
* Stops the last started event period.
|
* Stops the last started event period.
|
||||||
*
|
*
|
||||||
* @return StopwatchEvent The event
|
* @return StopwatchEvent The event
|
||||||
|
*
|
||||||
|
* @throws \LogicException When stop() is called without a matching call to start()
|
||||||
*/
|
*/
|
||||||
public function stop()
|
public function stop()
|
||||||
{
|
{
|
||||||
@ -138,15 +140,15 @@ class StopwatchEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the total time of all periods.
|
* Gets the duration of the events (including all periods).
|
||||||
*
|
*
|
||||||
* @return integer The time (in milliseconds)
|
* @return integer The duration (in milliseconds)
|
||||||
*/
|
*/
|
||||||
public function getTotalTime()
|
public function getDuration()
|
||||||
{
|
{
|
||||||
$total = 0;
|
$total = 0;
|
||||||
foreach ($this->periods as $period) {
|
foreach ($this->periods as $period) {
|
||||||
$total += $period->getTime();
|
$total += $period->getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->formatTime($total);
|
return $this->formatTime($total);
|
||||||
|
@ -30,9 +30,9 @@ class StopwatchPeriod
|
|||||||
*/
|
*/
|
||||||
public function __construct($start, $end)
|
public function __construct($start, $end)
|
||||||
{
|
{
|
||||||
$this->start = $start;
|
$this->start = (integer) $start;
|
||||||
$this->end = $end;
|
$this->end = (integer) $end;
|
||||||
$this->memory = memory_get_usage();
|
$this->memory = memory_get_usage(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,9 +58,9 @@ class StopwatchPeriod
|
|||||||
/**
|
/**
|
||||||
* Gets the time spent in this period.
|
* Gets the time spent in this period.
|
||||||
*
|
*
|
||||||
* @return integer The time (in milliseconds)
|
* @return integer The period duration (in milliseconds)
|
||||||
*/
|
*/
|
||||||
public function getTime()
|
public function getDuration()
|
||||||
{
|
{
|
||||||
return $this->end - $this->start;
|
return $this->end - $this->start;
|
||||||
}
|
}
|
||||||
|
@ -62,13 +62,13 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertCount(2, $event->getPeriods());
|
$this->assertCount(2, $event->getPeriods());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTotalTime()
|
public function testDuration()
|
||||||
{
|
{
|
||||||
$event = new StopwatchEvent(microtime(true) * 1000);
|
$event = new StopwatchEvent(microtime(true) * 1000);
|
||||||
$event->start();
|
$event->start();
|
||||||
usleep(20000);
|
usleep(20000);
|
||||||
$event->stop();
|
$event->stop();
|
||||||
$total = $event->getTotalTime();
|
$total = $event->getDuration();
|
||||||
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
|
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
|
||||||
|
|
||||||
$event = new StopwatchEvent(microtime(true) * 1000);
|
$event = new StopwatchEvent(microtime(true) * 1000);
|
||||||
@ -78,7 +78,7 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
|
|||||||
$event->start();
|
$event->start();
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
$event->stop();
|
$event->stop();
|
||||||
$total = $event->getTotalTime();
|
$total = $event->getDuration();
|
||||||
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
|
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase
|
|||||||
$event->start();
|
$event->start();
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
$event->ensureStopped();
|
$event->ensureStopped();
|
||||||
$total = $event->getTotalTime();
|
$total = $event->getDuration();
|
||||||
$this->assertTrue($total >= 21 && $total <= 39, $total.' should be 30 (between 21 and 39)');
|
$this->assertTrue($total >= 21 && $total <= 39, $total.' should be 30 (between 21 and 39)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
|
|||||||
$event = $stopwatch->stop('foo');
|
$event = $stopwatch->stop('foo');
|
||||||
|
|
||||||
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
|
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
|
||||||
$total = $event->getTotalTime();
|
$total = $event->getDuration();
|
||||||
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
|
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class StopwatchTest extends \PHPUnit_Framework_TestCase
|
|||||||
$stopwatch->stop('foo');
|
$stopwatch->stop('foo');
|
||||||
|
|
||||||
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
|
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
|
||||||
$total = $event->getTotalTime();
|
$total = $event->getDuration();
|
||||||
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
|
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user