bug #1825 Profiler root duration fix (fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

Profiler root duration fix

When using the Twig profiler, the root node is a bit special and the duration should really be the sum of the children duration. That should fix #1792

Commits
-------

f1e963c fixed the profiler duration for the root node
This commit is contained in:
Fabien Potencier
2015-09-12 19:43:05 +02:00
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
* changed template cache names to take into account enabled extensions
* deprecated Twig_Environment::clearCacheFiles(), Twig_Environment::getCacheFilename(),
Twig_Environment::writeCacheFile(), and Twig_Environment::getTemplateClassPrefix()
+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;
}