4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * @author Fabien Potencier <fabien@symfony.com>
17 class Twig_Profiler_Dumper_Text
21 public function dump(Twig_Profiler_Profile $profile)
23 return $this->dumpProfile($profile);
26 protected function formatTemplate(Twig_Profiler_Profile $profile, $prefix)
28 return sprintf('%sā %s', $prefix, $profile->getTemplate());
31 protected function formatNonTemplate(Twig_Profiler_Profile $profile, $prefix)
33 return sprintf('%sā %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName());
36 protected function formatTime(Twig_Profiler_Profile $profile, $percent)
38 return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent);
41 private function dumpProfile(Twig_Profiler_Profile $profile, $prefix = '', $sibling = false)
43 if ($profile->isRoot()) {
44 $this->root = $profile->getDuration();
45 $start = $profile->getName();
47 if ($profile->isTemplate()) {
48 $start = $this->formatTemplate($profile, $prefix);
50 $start = $this->formatNonTemplate($profile, $prefix);
52 $prefix .= $sibling ? 'ā ' : ' ';
55 $percent = $this->root ? $profile->getDuration() / $this->root * 100 : 0;
57 if ($profile->getDuration() * 1000 < 1) {
60 $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent));
63 $nCount = count($profile->getProfiles());
64 foreach ($profile as $i => $p) {
65 $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount);