Add start/end time accessors on Profile

This commit is contained in:
Fabien Potencier
2024-09-26 08:15:08 +02:00
parent bb30a7ba26
commit f83c844b7d
3 changed files with 26 additions and 0 deletions
+1
View File
@@ -1,5 +1,6 @@
# 3.15.0 (2024-XX-XX)
* Add `Profile::getStartTime()` and `Profile::getEndTime()`
* Fix "ignore missing" when used on an "embed" tag
* Fix the possibility to override an aliased block (via use)
* Add template cache hot reload
+16
View File
@@ -99,6 +99,22 @@ final class Profile implements \IteratorAggregate, \Serializable
return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0;
}
/**
* Returns the start time in microseconds.
*/
public function getStartTime(): float
{
return $this->starts['wt'] ?? 0.0;
}
/**
* Returns the end time in microseconds.
*/
public function getEndTime(): float
{
return $this->ends['wt'] ?? 0.0;
}
/**
* Returns the memory usage in bytes.
*/
+9
View File
@@ -80,6 +80,15 @@ class ProfileTest extends TestCase
$this->assertTrue($profile->getDuration() > 0, \sprintf('Expected duration > 0, got: %f', $profile->getDuration()));
}
public function testTimeAccessors()
{
$current = microtime(true);
$profile = new Profile();
$this->assertEqualsWithDelta($current, $profile->getStartTime(), 1);
$this->assertSame(0.0, $profile->getEndTime());
}
public function testSerialize()
{
$profile = new Profile('template', 'type', 'name');