diff --git a/CHANGELOG b/CHANGELOG index 4d0616cea..2fc4b9347 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/src/Profiler/Profile.php b/src/Profiler/Profile.php index 2928e1646..a3c6ee02e 100644 --- a/src/Profiler/Profile.php +++ b/src/Profiler/Profile.php @@ -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. */ diff --git a/tests/Profiler/ProfileTest.php b/tests/Profiler/ProfileTest.php index 5f41fc9c1..8c00e65bf 100644 --- a/tests/Profiler/ProfileTest.php +++ b/tests/Profiler/ProfileTest.php @@ -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');