diff --git a/CHANGELOG b/CHANGELOG index ea922d86c..0b070a4b3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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() diff --git a/lib/Twig/Profiler/Profile.php b/lib/Twig/Profiler/Profile.php index ec9e25459..104bc0581 100644 --- a/lib/Twig/Profiler/Profile.php +++ b/lib/Twig/Profiler/Profile.php @@ -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; }