1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kint\Renderer\Text; |
4
|
|
|
|
5
|
|
|
use Kint\Object\BasicObject; |
6
|
|
|
use Kint\Object\Representation\MicrotimeRepresentation; |
7
|
|
|
|
8
|
|
|
class MicrotimePlugin extends Plugin |
9
|
|
|
{ |
10
|
|
|
public function render(BasicObject $o) |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
$r = $o->getRepresentation('microtime'); |
|
|
|
|
13
|
|
|
|
14
|
|
|
if (!$r instanceof MicrotimeRepresentation) { |
15
|
|
|
return false; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$out = ''; |
19
|
|
|
|
20
|
|
|
if ($o->depth == 0) { |
21
|
|
|
$out .= $this->renderer->colorTitle($this->renderer->renderTitle($o)).PHP_EOL; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$out .= $this->renderer->renderHeader($o); |
25
|
|
|
$out .= $this->renderer->renderChildren($o).PHP_EOL; |
26
|
|
|
|
27
|
|
|
list($usec, $sec) = explode(' ', $r->contents); |
28
|
|
|
|
29
|
|
|
$indent = str_repeat(' ', ($o->depth + 1) * $this->renderer->indent_width); |
30
|
|
|
|
31
|
|
|
$out .= $indent.$this->renderer->colorType('TIME:').' '; |
32
|
|
|
$out .= $this->renderer->colorValue(@date('Y-m-d H:i:s', $sec).'.'.substr($usec, 2, 4)).PHP_EOL; |
33
|
|
|
|
34
|
|
View Code Duplication |
if ($r->lap !== null) { |
|
|
|
|
35
|
|
|
$out .= $indent.$this->renderer->colorType('SINCE LAST CALL:').' '; |
36
|
|
|
$out .= $this->renderer->colorValue(round($r->lap, 4).'s').'.'.PHP_EOL; |
37
|
|
|
} |
38
|
|
View Code Duplication |
if ($r->total !== null) { |
|
|
|
|
39
|
|
|
$out .= $indent.$this->renderer->colorType('SINCE START:').' '; |
40
|
|
|
$out .= $this->renderer->colorValue(round($r->total, 4).'s').'.'.PHP_EOL; |
41
|
|
|
} |
42
|
|
View Code Duplication |
if ($r->avg !== null) { |
|
|
|
|
43
|
|
|
$out .= $indent.$this->renderer->colorType('AVERAGE DURATION:').' '; |
44
|
|
|
$out .= $this->renderer->colorValue(round($r->avg, 4).'s').'.'.PHP_EOL; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$unit = array('B', 'KB', 'MB', 'GB', 'TB'); |
48
|
|
|
|
49
|
|
|
$mem = $r->mem.' bytes ('; |
50
|
|
|
$i = floor(log($r->mem, 1024)); |
51
|
|
|
$mem .= round($r->mem / pow(1024, $i), 3).' '.$unit[$i].')'; |
52
|
|
|
$i = floor(log($r->mem_real, 1024)); |
53
|
|
|
$mem .= ' (real '.round($r->mem_real / pow(1024, $i), 3).' '.$unit[$i].')'; |
54
|
|
|
|
55
|
|
|
$out .= $indent.$this->renderer->colorType('MEMORY USAGE:').' '; |
56
|
|
|
$out .= $this->renderer->colorValue($mem).'.'.PHP_EOL; |
57
|
|
|
|
58
|
|
|
if ($r->mem_peak !== null && $r->mem_peak_real !== null) { |
59
|
|
|
$mem = $r->mem_peak.' bytes ('; |
60
|
|
|
$i = floor(log($r->mem_peak, 1024)); |
61
|
|
|
$mem .= round($r->mem_peak / pow(1024, $i), 3).' '.$unit[$i].')'; |
62
|
|
|
$i = floor(log($r->mem_peak_real, 1024)); |
63
|
|
|
$mem .= ' (real '.round($r->mem_peak_real / pow(1024, $i), 3).' '.$unit[$i].')'; |
64
|
|
|
|
65
|
|
|
$out .= $indent.$this->renderer->colorType('PEAK MEMORY USAGE:').' '; |
66
|
|
|
$out .= $this->renderer->colorValue($mem).'.'.PHP_EOL; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $out; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.