8000 merged branch vicb/stopwatch (PR #5970) · symfony/symfony@b337655 · GitHub
[go: up one dir, main page]

Skip to content

Commit b337655

Browse files
committed
merged branch vicb/stopwatch (PR #5970)
This PR was squashed before being merged into the master branch (closes #5970). Commits ------- d0433b6 [Stopwatch] Get the "real size" used & minor tweaks Discussion ---------- [Stopwatch] Get the "real size" used & minor tweaks --------------------------------------------------------------------------- by vicb at 2012-11-11T09:45:50Z @fabpot @maoueh thanks for your feedback, integrated.
2 parents c9f2ae6 + d0433b6 commit b337655

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
{% endif %}
1717

1818
{% block toolbar %}
19-
{% set total_time = collector.events|length ? '%.0f ms'|format(collector.totaltime) : 'n/a' %}
19+
{% set duration = collector.events|length ? '%.0f ms'|format(collector.duration) : 'n/a' %}
2020
{% set icon %}
2121
<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="/>
22-
<span>{{ total_time }}</span>
22+
<span>{{ duration }}</span>
2323
{% endset %}
2424
{% set text %}
2525
<div class="sf-toolbar-info-piece">
2626
<b>Total time</b>
27-
<span>{{ total_time }}</span>
27+
<span>{{ duration }}</span>
2828
</div>
2929
{% endset %}
3030
{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': profiler_url } %}
@@ -54,7 +54,7 @@
5454
<table>
5555
<tr>
5656
<th style="width: 20%">Total time</th>
57-
<td>{{ '%.0f'|format(collector.totaltime) }} ms</td>
57+
<td>{{ '%.0f'|format(collector.duration) }} ms</td>
5858
</tr>
5959
<tr>
6060
<th>Initialization time</th>
@@ -70,7 +70,7 @@
7070
<h3>
7171
{{ profile.parent ? "Request" : "Main Request" }}
7272
<small>
73-
- {{ collector.events.__section__.totaltime }} ms
73+
- {{ collector.events.__section__.duration }} ms
7474
{% if profile.parent %}
7575
- <a href="{{ path('_profiler', { 'token': profile.parent.token, 'panel': 'time' }) }}">parent</a>
7676
{% endif %}
@@ -86,7 +86,7 @@
8686
{% set events = child.getcollector('time').events %}
8787
<h3>
8888
Sub-request "<a href="{{ path('_profiler', { 'token': child.token, 'panel': 'time' }) }}">{{ child.getcollector('request').requestattributes.get('_controller') }}</a>"
89-
<small> - {{ events.__section__.totaltime }} ms</small>
89+
<small> - {{ events.__section__.duration }} ms</small>
9090
</h3>
9191

9292
{{ display_timeline('timeline_' ~ child.token, events, colors) }}
@@ -198,7 +198,7 @@
198198
199199
// Filter events whose total time is below the threshold.
200200
drawableEvents = request.events.filter(function(event) {
201-
return event.totaltime >= threshold;
201+
return event.duration >= threshold;
202202
});
203203
204204
canvasHeight += gapPerEvent * drawableEvents.length;
@@ -315,7 +315,7 @@
315315
ctx.fillStyle = "#444";
316316
ctx.font = "12px sans-serif";
317317
text = event.name;
318-
ms = " ~ " + (event.totaltime < 1 ? event.totaltime : parseInt(event.totaltime, 10)) + " ms / ~ " + event.memory + " MB";
318+
ms = " ~ " + (event.duration < 1 ? event.duration : parseInt(event.duration, 10)) + " ms / ~ " + event.memory + " MB";
319319
if (x + event.starttime * ratio + ctx.measureText(text + ms).width > width) {
320320
ctx.textAlign = "end";
321321
ctx.font = "10px sans-serif";
@@ -453,8 +453,8 @@
453453
"origin": {{ "%F"|format(event.origin) }},
454454
"starttime": {{ "%F"|format(event.starttime) }},
455455
"endtime": {{ "%F"|format(event.endtime) }},
456-
"totaltime": {{ "%F"|format(event.totaltime) }},
457-
"memory": {{ "%.1f"|format(event.memory / 1024 / 1024) }},
456+
"duration": {{ "%F"|format(event.duration) }},
457+
"memory": {{ "%.1F"|format(event.memory / 1024 / 1024) }},
458458
"periods": [
459459
{%- for period in event.periods -%}
460460
{"start": {{ "%F"|format(period.starttime) }}, "end": {{ "%F"|format(period.endtime) }}}{{ loop.last ? '' : ', ' }}

src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function getEvents()
7070
*
7171
* @return float The elapsed time
7272
*/
73-
public function getTotalTime()
73+
public function getDuration()
7474
{
7575
$lastEvent = $this->data['events']['__section__'];
7676

77-
return $lastEvent->getOrigin() + $lastEvent->getTotalTime() - $this->getStartTime();
77+
return $lastEvent->getOrigin() + $lastEvent->getDuration() - $this->getStartTime();
7878
}
7979

8080
/**

src/Symfony/Component/Stopwatch/StopwatchEvent.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function start()
7575
* Stops the last started event period.
7676
*
7777
* @return StopwatchEvent The event
78+
*
79+
* @throws \LogicException When stop() is called without a matching call to start()
7880
*/
7981
public function stop()
8082
{
@@ -138,15 +140,15 @@ public function getEndTime()
138140
}
139141

140142
/**
141-
* Gets the total time of all periods.
143+
* Gets the duration of the events (including all periods).
142144
*
143-
* @return integer The time (in milliseconds)
145+
* @return integer The duration (in milliseconds)
144146
*/
145-
public function getTotalTime()
147+
public function getDuration()
146148
{
147149
$total = 0;
148150
foreach ($this->periods as $period) {
149-
$total += $period->getTime();
151+
$total += $period->getDuration();
150152
}
151153

152154
return $this->formatTime($total);

src/Symfony/Component/Stopwatch/StopwatchPeriod.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class StopwatchPeriod
3030
*/
3131
public function __construct($start, $end)
3232
{
33-
$this->start = $start;
34-
$this->end = $end;
35-
$this->memory = memory_get_usage();
33+
$this->start = (integer) $start;
34+
$this->end = (integer) $end;
35+
$this->memory = memory_get_usage(true);
3636
}
3737

3838
/**
@@ -58,9 +58,9 @@ public function getEndTime()
5858
/**
5959
* Gets the time spent in this period.
6060
*
61-
* @return integer The time (in milliseconds)
61+
* @return integer The period duration (in milliseconds)
6262
*/
63-
public function getTime()
63+
public function getDuration()
6464
{
6565
return $this->end - $this->start;
6666
}

src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public function testLap()
6262
$this->assertCount(2, $event->getPeriods());
6363
}
6464

65-
public function testTotalTime()
65+
public function testDuration()
6666
{
6767
$event = new StopwatchEvent(microtime(true) * 1000);
6868
$event->start();
6969
usleep(20000);
7070
$event->stop();
71-
$total = $event->getTotalTime();
71+
$total = $event->getDuration();
7272
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
7373

7474
$event = new StopwatchEvent(microtime(true) * 1000);
@@ -78,7 +78,7 @@ public function testTotalTime()
7878
$event->start();
7979
usleep(10000);
8080
$event->stop();
81-
$total = $event->getTotalTime();
81+
$total = $event->getDuration();
8282
$this->assertTrue($total >= 11 && $total <= 29, $total.' should be 20 (between 11 and 29)');
8383
}
8484

@@ -100,7 +100,7 @@ public function testEnsureStopped()
100100
$event->start();
101101
usleep(10000);
102102
$event->ensureStopped();
103-
$total = $event->getTotalTime();
103+
$total = $event->getDuration();
104104
$this->assertTrue($total >= 21 && $total <= 39, $total.' should be 30 (between 21 and 39)');
105105
}
106106

src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testStop()
3737
$event = $stopwatch->stop('foo');
3838

3939
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
40-
$total = $event->getTotalTime();
40+
$total = $event->getDuration();
4141
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
4242
}
4343

@@ -51,7 +51,7 @@ public function testLap()
5151
$stopwatch->stop('foo');
5252

5353
$this->assertInstanceof('Symfony\Component\Stopwatch\StopwatchEvent', $event);
54-
$total = $event->getTotalTime();
54+
$total = $event->getDuration();
5555
$this->assertTrue($total > 10 && $total <= 29, $total.' should be 20 (between 10 and 29)');
5656
}
5757

0 commit comments

Comments
 (0)
0