2012-11-08 10:56:53 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2012-11-09 06:47:23 +00:00
|
|
|
namespace Symfony\Component\Stopwatch;
|
2012-11-08 10:56:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an Period for an Event.
|
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
|
*/
|
|
|
|
class StopwatchPeriod
|
|
|
|
{
|
|
|
|
private $start;
|
|
|
|
private $end;
|
|
|
|
private $memory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2014-04-12 18:54:57 +01:00
|
|
|
* @param int $start The relative time of the start of the period
|
|
|
|
* @param int $end The relative time of the end of the period
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
|
|
|
public function __construct($start, $end)
|
|
|
|
{
|
2014-04-12 18:44:00 +01:00
|
|
|
$this->start = (int) $start;
|
|
|
|
$this->end = (int) $end;
|
2012-11-10 15:55:34 +00:00
|
|
|
$this->memory = memory_get_usage(true);
|
2012-11-08 10:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the relative time of the start of the period.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return int The time (in milliseconds)
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
|
|
|
public function getStartTime()
|
|
|
|
{
|
|
|
|
return $this->start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the relative time of the end of the period.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return int The time (in milliseconds)
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
|
|
|
public function getEndTime()
|
|
|
|
{
|
|
|
|
return $this->end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the time spent in this period.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return int The period duration (in milliseconds)
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
2012-11-10 15:55:34 +00:00
|
|
|
public function getDuration()
|
2012-11-08 10:56:53 +00:00
|
|
|
{
|
|
|
|
return $this->end - $this->start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the memory usage.
|
|
|
|
*
|
2014-04-16 11:30:19 +01:00
|
|
|
* @return int The memory usage (in bytes)
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
|
|
|
public function getMemory()
|
|
|
|
{
|
|
|
|
return $this->memory;
|
|
|
|
}
|
|
|
|
}
|