1: <?php
2:
3: /*
4: * The MIT License (MIT)
5: *
6: * Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com)
7: *
8: * Permission is hereby granted, free of charge, to any person obtaining a copy of
9: * this software and associated documentation files (the "Software"), to deal in
10: * the Software without restriction, including without limitation the rights to
11: * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12: * the Software, and to permit persons to whom the Software is furnished to do so,
13: * subject to the following conditions:
14: *
15: * The above copyright notice and this permission notice shall be included in all
16: * copies or substantial portions of the Software.
17: *
18: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20: * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21: * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22: * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23: * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24: */
25:
26: namespace Kint\Renderer\Rich;
27:
28: use Kint\Object\Representation\MicrotimeRepresentation;
29: use Kint\Object\Representation\Representation;
30: use Kint\Utils;
31:
32: class MicrotimePlugin extends Plugin implements TabPluginInterface
33: {
34: public function renderTab(Representation $r)
35: {
36: if (!($r instanceof MicrotimeRepresentation)) {
37: return false;
38: }
39:
40: $out = $r->getDateTime()->format('Y-m-d H:i:s.u');
41: if (null !== $r->lap) {
42: $out .= '<br><b>SINCE LAST CALL:</b> <span class="kint-microtime-lap">'.\round($r->lap, 4).'</span>s.';
43: }
44: if (null !== $r->total) {
45: $out .= '<br><b>SINCE START:</b> '.\round($r->total, 4).'s.';
46: }
47: if (null !== $r->avg) {
48: $out .= '<br><b>AVERAGE DURATION:</b> <span class="kint-microtime-avg">'.\round($r->avg, 4).'</span>s.';
49: }
50:
51: $bytes = Utils::getHumanReadableBytes($r->mem);
52: $out .= '<br><b>MEMORY USAGE:</b> '.$r->mem.' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
53: $bytes = Utils::getHumanReadableBytes($r->mem_real);
54: $out .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
55:
56: $bytes = Utils::getHumanReadableBytes($r->mem_peak);
57: $out .= '<br><b>PEAK MEMORY USAGE:</b> '.$r->mem_peak.' bytes ('.\round($bytes['value'], 3).' '.$bytes['unit'].')';
58: $bytes = Utils::getHumanReadableBytes($r->mem_peak_real);
59: $out .= ' (real '.\round($bytes['value'], 3).' '.$bytes['unit'].')';
60:
61: return '<pre data-kint-microtime-group="'.$r->group.'">'.$out.'</pre>';
62: }
63:
64: public static function renderJs()
65: {
66: return \file_get_contents(KINT_DIR.'/resources/compiled/microtime.js');
67: }
68: }
69: