protected function Kint_Parsers_Microtime::_parse in Devel 8
Same name and namespace in other branches
- 8.2 kint/kint/parsers/custom/microtime.php \Kint_Parsers_Microtime::_parse()
* main and usually single method a custom parser must implement * *
Parameters
mixed $variable: * * @return mixed [!!!] false is returned if the variable is not of current type
Overrides kintParser::_parse
File
- kint/
kint/ parsers/ custom/ microtime.php, line 8
Class
Code
protected function _parse(&$variable) {
if (!is_string($variable) || !preg_match('[0\\.[0-9]{8} [0-9]{10}]', $variable)) {
return false;
}
list($usec, $sec) = explode(" ", $variable);
$time = (double) $usec + (double) $sec;
if (KINT_PHP53) {
$size = memory_get_usage(true);
}
# '@' is used to prevent the dreaded timezone not set error
$this->value = @date('Y-m-d H:i:s', $sec) . '.' . substr($usec, 2, 4);
$numberOfCalls = count(self::$_times);
if ($numberOfCalls > 0) {
# meh, faster than count($times) > 1
$lap = $time - end(self::$_times);
self::$_laps[] = $lap;
$this->value .= "\n<b>SINCE LAST CALL:</b> <b class=\"kint-microtime\">" . round($lap, 4) . '</b>s.';
if ($numberOfCalls > 1) {
$this->value .= "\n<b>SINCE START:</b> " . round($time - self::$_times[0], 4) . 's.';
$this->value .= "\n<b>AVERAGE DURATION:</b> " . round(array_sum(self::$_laps) / $numberOfCalls, 4) . 's.';
}
}
$unit = array(
'B',
'KB',
'MB',
'GB',
'TB',
);
if (KINT_PHP53) {
$this->value .= "\n<b>MEMORY USAGE:</b> " . $size . " bytes (" . round($size / pow(1024, $i = floor(log($size, 1024))), 3) . ' ' . $unit[$i] . ")";
}
self::$_times[] = $time;
$this->type = 'Stats';
}