fixed the profiler duration for the root node

This commit is contained in:
Fabien Potencier
2015-09-12 12:43:43 +02:00
parent c6ad6feda4
commit f1e963c2dc
2 changed files with 11 additions and 0 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.22.0 (2015-XX-XX)
* fixed the profiler duration for the root node
* deprecated Twig_Environment::clearCacheFiles(), Twig_Environment::getCacheFilename(),
and Twig_Environment::writeCacheFile()
* added a way to override the filesystem template cache system
+10
View File
@@ -86,6 +86,16 @@ class Twig_Profiler_Profile implements IteratorAggregate, Serializable
*/
public function getDuration()
{
if ($this->isRoot() && $this->profiles) {
// for the root node with children, duration is the sum of all child durations
$duration = 0;
foreach ($this->profiles as $profile) {
$duration += $profile->getDuration();
}
return $duration;
}
return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0;
}