PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-beta1
Elementor Website Builder – more than just a page builder v3.28.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 All 457 releases
elementor / vendor_prefixed / twig / src / Profiler / Dumper / BlackfireDumper.php

BlackfireDumper.php in Elementor Website Builder – more than just a page builder 3.28.0-beta1, at vendor_prefixed/twig/src/Profiler/Dumper/BlackfireDumper.php

61 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace ElementorDeps\Twig\Profiler\Dumper;
12
13 use ElementorDeps\Twig\Profiler\Profile;
14 /**
15 * @author Fabien Potencier <[email protected]>
16 */
17 final class BlackfireDumper
18 {
19 public function dump(Profile $profile) : string
20 {
21 $data = [];
22 $this->dumpProfile('main()', $profile, $data);
23 $this->dumpChildren('main()', $profile, $data);
24 $start = \sprintf('%f', \microtime(\true));
25 $str = <<<EOF
26 file-format: BlackfireProbe
27 cost-dimensions: wt mu pmu
28 request-start: {$start}
29
30
31 EOF;
32 foreach ($data as $name => $values) {
33 $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n";
34 }
35 return $str;
36 }
37 private function dumpChildren(string $parent, Profile $profile, &$data)
38 {
39 foreach ($profile as $p) {
40 if ($p->isTemplate()) {
41 $name = $p->getTemplate();
42 } else {
43 $name = \sprintf('%s::%s(%s)', $p->getTemplate(), $p->getType(), $p->getName());
44 }
45 $this->dumpProfile(\sprintf('%s==>%s', $parent, $name), $p, $data);
46 $this->dumpChildren($name, $p, $data);
47 }
48 }
49 private function dumpProfile(string $edge, Profile $profile, &$data)
50 {
51 if (isset($data[$edge])) {
52 ++$data[$edge]['ct'];
53 $data[$edge]['wt'] += \floor($profile->getDuration() * 1000000);
54 $data[$edge]['mu'] += $profile->getMemoryUsage();
55 $data[$edge]['pmu'] += $profile->getPeakMemoryUsage();
56 } else {
57 $data[$edge] = ['ct' => 1, 'wt' => \floor($profile->getDuration() * 1000000), 'mu' => $profile->getMemoryUsage(), 'pmu' => $profile->getPeakMemoryUsage()];
58 }
59 }
60 }
61