composer package updates
[openemr.git] / vendor / twig / twig / lib / Twig / Profiler / Dumper / Blackfire.php
blob7a33baf2d670b3ba7367a3aa170e81a6a1ee71cc
1 <?php
3 /*
4 * This file is part of Twig.
6 * (c) Fabien Potencier
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 /**
13 * @author Fabien Potencier <fabien@symfony.com>
15 * @final
17 class Twig_Profiler_Dumper_Blackfire
19 public function dump(Twig_Profiler_Profile $profile)
21 $data = array();
22 $this->dumpProfile('main()', $profile, $data);
23 $this->dumpChildren('main()', $profile, $data);
25 $start = sprintf('%f', microtime(true));
26 $str = <<<EOF
27 file-format: BlackfireProbe
28 cost-dimensions: wt mu pmu
29 request-start: {$start}
32 EOF;
34 foreach ($data as $name => $values) {
35 $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n";
38 return $str;
41 private function dumpChildren($parent, Twig_Profiler_Profile $profile, &$data)
43 foreach ($profile as $p) {
44 if ($p->isTemplate()) {
45 $name = $p->getTemplate();
46 } else {
47 $name = sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName());
49 $this->dumpProfile(sprintf('%s==>%s', $parent, $name), $p, $data);
50 $this->dumpChildren($name, $p, $data);
54 private function dumpProfile($edge, Twig_Profiler_Profile $profile, &$data)
56 if (isset($data[$edge])) {
57 $data[$edge]['ct'] += 1;
58 $data[$edge]['wt'] += floor($profile->getDuration() * 1000000);
59 $data[$edge]['mu'] += $profile->getMemoryUsage();
60 $data[$edge]['pmu'] += $profile->getPeakMemoryUsage();
61 } else {
62 $data[$edge] = array(
63 'ct' => 1,
64 'wt' => floor($profile->getDuration() * 1000000),
65 'mu' => $profile->getMemoryUsage(),
66 'pmu' => $profile->getPeakMemoryUsage(),
72 class_alias('Twig_Profiler_Dumper_Blackfire', 'Twig\Profiler\Dumper\BlackfireDumper', false);