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\Object\Representation;
27:
28: use DateTime;
29:
30: class MicrotimeRepresentation extends Representation
31: {
32: public $seconds;
33: public $microseconds;
34: public $group;
35: public $lap;
36: public $total;
37: public $avg;
38: public $i = 0;
39: public $mem = 0;
40: public $mem_real = 0;
41: public $mem_peak = 0;
42: public $mem_peak_real = 0;
43: public $hints = array('microtime');
44:
45: public function __construct($seconds, $microseconds, $group, $lap = null, $total = null, $i = 0)
46: {
47: parent::__construct('Microtime');
48:
49: $this->seconds = (int) $seconds;
50: $this->microseconds = (int) $microseconds;
51:
52: $this->group = $group;
53: $this->lap = $lap;
54: $this->total = $total;
55: $this->i = $i;
56:
57: if ($i) {
58: $this->avg = $total / $i;
59: }
60:
61: $this->mem = \memory_get_usage();
62: $this->mem_real = \memory_get_usage(true);
63: $this->mem_peak = \memory_get_peak_usage();
64: $this->mem_peak_real = \memory_get_peak_usage(true);
65: }
66:
67: public function getDateTime()
68: {
69: return DateTime::createFromFormat('U u', $this->seconds.' '.\str_pad($this->microseconds, 6, '0', STR_PAD_LEFT));
70: }
71: }
72: