Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[HttpKernel] added memory information in the Stopwatch #5944

Merged
merged 1 commit into from

5 participants

@fabpot
Owner

No description provided.

...ilerBundle/Resources/views/Collector/memory.html.twig
@@ -4,13 +4,13 @@
{% set icon %}
<span>
<img width="13" height="28" alt="Memory Usage" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAcBAMAAABITyhxAAAAJ1BMVEXNzc3///////////////////////8/Pz////////////+NjY0/Pz9lMO+OAAAADHRSTlMAABAgMDhAWXCvv9e8JUuyAAAAQ0lEQVQI12MQBAMBBmLpMwoMDAw6BxjOOABpHyCdAKRzsNDp5eXl1KBh5oHBAYY9YHoDQ+cqIFjZwGCaBgSpBrjcCwCZgkUHKKvX+wAAAABJRU5ErkJggg=="/>
- <span>{{ '%.1f'|format(collector.memory / 1024 / 1024) }} MB</span>
+ <span>{{ '%.1f'|format(collector.memory / 1024 / 1024) }} Mo</span>

Why change this to the french style byte units?

@stof Collaborator
stof added a note

this is indeed wrong. The page is in English

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot merged branch fabpot/stopwatch (PR #5944)
This PR was merged into the master branch.

Commits
-------

380cf4f [HttpKernel] added memory information in the Stopwatch

Discussion
----------

[HttpKernel] added memory information in the Stopwatch
c290776
@fabpot fabpot merged commit 380cf4f into symfony:master

1 check was pending

Details default The Travis build is in progress
@bdmu

Hello,

Could you please merge this pull request on the 2.1 branch ?

It has been merged on master Nov 08, 2012, meaning 1 day before the creation of the StopWatch component, but no merge on the 2.1 branch.

It would be nice to have those memory information in the next 2.1 version.

Thanks in advance.
Christophe L.

@stloyd

@bdmu It cannot be merged into 2.1 as it was released at: September 06, 2012, and new features cannot be merged to already released versions.

@mmucklo mmucklo referenced this pull request from a commit
@fabpot fabpot merged branch fabpot/stopwatch (PR #5944)
This PR was merged into the master branch.

Commits
-------

380cf4f [HttpKernel] added memory information in the Stopwatch

Discussion
----------

[HttpKernel] added memory information in the Stopwatch
f49133a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
13 src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig
@@ -214,11 +214,11 @@
drawableEvents.forEach(function(event) {
event.periods.forEach(function(period) {
- var timelineHeadPosition = x + period.begin * ratio;
+ var timelineHeadPosition = x + period.start * ratio;
if (isChildEvent(event)) {
ctx.fillStyle = colors.child_sections;
- ctx.fillRect(timelineHeadPosition, 0, (period.end - period.begin) * ratio, canvasHeight);
+ ctx.fillRect(timelineHeadPosition, 0, (period.end - period.start) * ratio, canvasHeight);
} else if (isSectionEvent(event)) {
var timelineTailPosition = x + period.end * ratio;
@@ -259,11 +259,11 @@
}
// Draw the timeline
- var timelineHeadPosition = x + period.begin * ratio;
+ var timelineHeadPosition = x + period.start * ratio;
if ( ! isSectionEvent(event)) {
ctx.fillRect(timelineHeadPosition, h + 3, 2, 6);
- ctx.fillRect(timelineHeadPosition, h, (period.end - period.begin) * ratio || 2, 6);
+ ctx.fillRect(timelineHeadPosition, h, (period.end - period.start) * ratio || 2, 6);
} else {
var timelineTailPosition = x + period.end * ratio;
@@ -315,7 +315,7 @@
ctx.fillStyle = "#444";
ctx.font = "12px sans-serif";
text = event.name;
- ms = " ~ " + (event.totaltime < 1 ? event.totaltime : parseInt(event.totaltime, 10)) + " ms";
+ ms = " ~ " + (event.totaltime < 1 ? event.totaltime : parseInt(event.totaltime, 10)) + " ms / ~ " + event.memory + " MB";
if (x + event.starttime * ratio + ctx.measureText(text + ms).width > width) {
ctx.textAlign = "end";
ctx.font = "10px sans-serif";
@@ -454,9 +454,10 @@
"starttime": {{ "%F"|format(event.starttime) }},
"endtime": {{ "%F"|format(event.endtime) }},
"totaltime": {{ "%F"|format(event.totaltime) }},
+ "memory": {{ "%.1f"|format(event.memory / 1024 / 1024) }},
"periods": [
{%- for period in event.periods -%}
- {"begin": {{ "%F"|format(period.0) }}, "end": {{ "%F"|format(period.1) }}}{{ loop.last ? '' : ', ' }}
+ {"start": {{ "%F"|format(period.starttime) }}, "end": {{ "%F"|format(period.endtime) }}}{{ loop.last ? '' : ', ' }}
{%- endfor -%}
]
}{{ loop.last ? '' : ',' }}
View
27 src/Symfony/Component/HttpKernel/Debug/StopwatchEvent.php
@@ -82,7 +82,7 @@ public function stop()
throw new \LogicException('stop() called but start() has not been called before.');
}
- $this->periods[] = array(array_pop($this->started), $this->getNow());
+ $this->periods[] = new StopwatchPeriod(array_pop($this->started), $this->getNow());
return $this;
}
@@ -110,7 +110,7 @@ public function ensureStopped()
/**
* Gets all event periods.
*
- * @return array An array of periods
+ * @return StopwatchPeriod[] An array of StopwatchPeriod instances
*/
public function getPeriods()
{
@@ -124,7 +124,7 @@ public function getPeriods()
*/
public function getStartTime()
{
- return isset($this->periods[0]) ? $this->periods[0][0] : 0;
+ return isset($this->periods[0]) ? $this->periods[0]->getStartTime() : 0;
}
/**
@@ -134,7 +134,7 @@ public function getStartTime()
*/
public function getEndTime()
{
- return ($count = count($this->periods)) ? $this->periods[$count - 1][1] : 0;
+ return ($count = count($this->periods)) ? $this->periods[$count - 1]->getEndTime() : 0;
}
/**
@@ -146,13 +146,30 @@ public function getTotalTime()
{
$total = 0;
foreach ($this->periods as $period) {
- $total += $period[1] - $period[0];
+ $total += $period->getTime();
}
return $this->formatTime($total);
}
/**
+ * Gets the max memory usage of all periods.
+ *
+ * @return integer The memory usage (in bytes)
+ */
+ public function getMemory()
+ {
+ $memory = 0;
+ foreach ($this->periods as $period) {
+ if ($period->getMemory() > $memory) {
+ $memory = $period->getMemory();
+ }
+ }
+
+ return $memory;
+ }
+
+ /**
* Return the current time relative to origin.
*
* @return float Time in ms
View
77 src/Symfony/Component/HttpKernel/Debug/StopwatchPeriod.php
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\Debug;
+
+/**
+ * Represents an Period for an Event.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class StopwatchPeriod
+{
+ private $start;
+ private $end;
+ private $memory;
+
+ /**
+ * Constructor
+ *
+ * @param integer $start The relative time of the start of the period
+ * @param integer $end The relative time of the end of the period
+ */
+ public function __construct($start, $end)
+ {
+ $this->start = $start;
+ $this->end = $end;
+ $this->memory = memory_get_usage();
+ }
+
+ /**
+ * Gets the relative time of the start of the period.
+ *
+ * @return integer The time (in milliseconds)
+ */
+ public function getStartTime()
+ {
+ return $this->start;
+ }
+
+ /**
+ * Gets the relative time of the end of the period.
+ *
+ * @return integer The time (in milliseconds)
+ */
+ public function getEndTime()
+ {
+ return $this->end;
+ }
+
+ /**
+ * Gets the time spent in this period.
+ *
+ * @return integer The time (in milliseconds)
+ */
+ public function getTime()
+ {
+ return $this->end - $this->start;
+ }
+
+ /**
+ * Gets the memory usage.
+ *
+ * @return integer The memory usage (in bytes)
+ */
+ public function getMemory()
+ {
+ return $this->memory;
+ }
+}
Something went wrong with that request. Please try again.