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
This commit is contained in:
commit
c290776b45
@ -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 ? '' : ',' }}
|
||||
|
@ -82,7 +82,7 @@ class StopwatchEvent
|
||||
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 @@ class StopwatchEvent
|
||||
/**
|
||||
* Gets all event periods.
|
||||
*
|
||||
* @return array An array of periods
|
||||
* @return StopwatchPeriod[] An array of StopwatchPeriod instances
|
||||
*/
|
||||
public function getPeriods()
|
||||
{
|
||||
@ -124,7 +124,7 @@ class StopwatchEvent
|
||||
*/
|
||||
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 @@ class StopwatchEvent
|
||||
*/
|
||||
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,12 +146,29 @@ class StopwatchEvent
|
||||
{
|
||||
$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.
|
||||
*
|
||||
|
77
src/Symfony/Component/HttpKernel/Debug/StopwatchPeriod.php
Normal file
77
src/Symfony/Component/HttpKernel/Debug/StopwatchPeriod.php
Normal file
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user