|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kint\Renderer\Text; |
|
4
|
|
|
|
|
5
|
|
|
use Kint\Object\BasicObject; |
|
6
|
|
|
use Kint\Object\Representation\MicrotimeRepresentation; |
|
7
|
|
|
use Kint\Utils; |
|
8
|
|
|
|
|
9
|
|
|
class MicrotimePlugin extends Plugin |
|
10
|
|
|
{ |
|
11
|
|
|
public function render(BasicObject $o) |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
$r = $o->getRepresentation('microtime'); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
if (!$r instanceof MicrotimeRepresentation) { |
|
16
|
|
|
return false; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
$out = ''; |
|
20
|
|
|
|
|
21
|
|
|
if ($o->depth == 0) { |
|
22
|
|
|
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$out .= $this->renderer->renderHeader($o); |
|
26
|
|
|
$out .= $this->renderer->renderChildren($o).PHP_EOL; |
|
27
|
|
|
|
|
28
|
|
|
$indent = str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width); |
|
29
|
|
|
|
|
30
|
|
|
$out .= $indent.$this->renderer->colorType('TIME:').' '; |
|
31
|
|
|
$out .= $this->renderer->colorValue($r->getDateTime()->format('Y-m-d H:i:s.u')).PHP_EOL; |
|
32
|
|
|
|
|
33
|
|
View Code Duplication |
if ($r->lap !== null) { |
|
|
|
|
|
|
34
|
|
|
$out .= $indent.$this->renderer->colorType('SINCE LAST CALL:').' '; |
|
35
|
|
|
$out .= $this->renderer->colorValue(round($r->lap, 4).'s').'.'.PHP_EOL; |
|
36
|
|
|
} |
|
37
|
|
View Code Duplication |
if ($r->total !== null) { |
|
|
|
|
|
|
38
|
|
|
$out .= $indent.$this->renderer->colorType('SINCE START:').' '; |
|
39
|
|
|
$out .= $this->renderer->colorValue(round($r->total, 4).'s').'.'.PHP_EOL; |
|
40
|
|
|
} |
|
41
|
|
View Code Duplication |
if ($r->avg !== null) { |
|
|
|
|
|
|
42
|
|
|
$out .= $indent.$this->renderer->colorType('AVERAGE DURATION:').' '; |
|
43
|
|
|
$out .= $this->renderer->colorValue(round($r->avg, 4).'s').'.'.PHP_EOL; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$bytes = Utils::getHumanReadableBytes($r->mem); |
|
47
|
|
|
$mem = $r->mem.' bytes ('.round($bytes['value'], 3).' '.$bytes['unit'].')'; |
|
48
|
|
|
$bytes = Utils::getHumanReadableBytes($r->mem_real); |
|
49
|
|
|
$mem .= ' (real '.round($bytes['value'], 3).' '.$bytes['unit'].')'; |
|
50
|
|
|
|
|
51
|
|
|
$out .= $indent.$this->renderer->colorType('MEMORY USAGE:').' '; |
|
52
|
|
|
$out .= $this->renderer->colorValue($mem).'.'.PHP_EOL; |
|
53
|
|
|
|
|
54
|
|
|
$bytes = Utils::getHumanReadableBytes($r->mem_peak); |
|
55
|
|
|
$mem = $r->mem_peak.' bytes ('.round($bytes['value'], 3).' '.$bytes['unit'].')'; |
|
56
|
|
|
$bytes = Utils::getHumanReadableBytes($r->mem_peak_real); |
|
57
|
|
|
$mem .= ' (real '.round($bytes['value'], 3).' '.$bytes['unit'].')'; |
|
58
|
|
|
|
|
59
|
|
|
$out .= $indent.$this->renderer->colorType('PEAK MEMORY USAGE:').' '; |
|
60
|
|
|
$out .= $this->renderer->colorValue($mem).'.'.PHP_EOL; |
|
61
|
|
|
|
|
62
|
|
|
return $out; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.