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;
|
|
|
|
|
|
|
|
/**
|
2017-06-19 10:42:01 +01:00
|
|
|
* @param int|float $start The relative time of the start of the period (in milliseconds)
|
|
|
|
* @param int|float $end The relative time of the end of the period (in milliseconds)
|
|
|
|
* @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
2017-06-19 10:42:01 +01:00
|
|
|
public function __construct($start, $end, $morePrecision = false)
|
2012-11-08 10:56:53 +00:00
|
|
|
{
|
2017-06-19 10:42:01 +01:00
|
|
|
$this->start = $morePrecision ? (float) $start : (int) $start;
|
|
|
|
$this->end = $morePrecision ? (float) $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.
|
|
|
|
*
|
2017-06-19 10:42:01 +01:00
|
|
|
* @return int|float 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.
|
|
|
|
*
|
2017-06-19 10:42:01 +01:00
|
|
|
* @return int|float 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.
|
|
|
|
*
|
2017-06-19 10:42:01 +01:00
|
|
|
* @return int|float 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-11-30 13:33:44 +00:00
|
|
|
* @return int The memory usage (in bytes)
|
2012-11-08 10:56:53 +00:00
|
|
|
*/
|
|
|
|
public function getMemory()
|
|
|
|
{
|
|
|
|
return $this->memory;
|
|
|
|
}
|
|
|
|
}
|