1 | <?php |
||
10 | class TimelineFormatter extends BenchmarkFormatterAbstract |
||
11 | { |
||
12 | const TIMEBUFFER_FACTOR = 1.05; |
||
13 | |||
14 | /** |
||
15 | * @var ProfilerInterface |
||
16 | */ |
||
17 | protected $profiler; |
||
18 | |||
19 | /** |
||
20 | * @param ProfilerInterface $profiler |
||
21 | */ |
||
22 | 1 | public function __construct(ProfilerInterface $profiler) |
|
23 | { |
||
24 | 1 | $this->setProfiler($profiler); |
|
25 | 1 | } |
|
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | 1 | public function getWidth() |
|
31 | { |
||
32 | 1 | $widthPercentage = $this->getBenchmark()->getDuration() / $this->getProfilerDuration() * 100; |
|
33 | 1 | return number_format($widthPercentage, 2, '.', ''); |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | 1 | public function getOffset() |
|
40 | { |
||
41 | 1 | $offset = ($this->getBenchmark()->getStartTime() - $this->getProfiler()->getStartTime()) * 1000; |
|
42 | 1 | $offsetPercentage = $offset / $this->getProfilerDuration() * 100; |
|
43 | 1 | return number_format($offsetPercentage, 2, '.', ''); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return ProfilerInterface |
||
48 | */ |
||
49 | 1 | public function getProfiler() |
|
50 | { |
||
51 | 1 | return $this->profiler; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param ProfilerInterface $profiler |
||
56 | */ |
||
57 | 1 | public function setProfiler(ProfilerInterface $profiler) |
|
58 | { |
||
59 | 1 | $this->profiler = $profiler; |
|
60 | 1 | } |
|
61 | |||
62 | /** |
||
63 | * @return float |
||
64 | */ |
||
65 | 2 | protected function getProfilerDuration() |
|
69 | } |
||
70 |