1 <?php
2
3 class Kint_Parsers_Microtime extends kintParser
4 {
5 private static $_times = array();
6 private static $_laps = array();
7
8 protected function _parse( & $variable )
9 {
10 if ( !is_string( $variable ) || !preg_match( '[0\.[0-9]{8} [0-9]{10}]', $variable ) ) {
11 return false;
12 }
13
14 list( $usec, $sec ) = explode( " ", $variable );
15
16 $time = (float) $usec + (float) $sec;
17 if ( KINT_PHP53 ) {
18 $size = memory_get_usage( true );
19 }
20
21
22 $this->value = @date( 'Y-m-d H:i:s', $sec ) . '.' . substr( $usec, 2, 4 );
23
24 $numberOfCalls = count( self::$_times );
25 if ( $numberOfCalls > 0 ) {
26 $lap = $time - end( self::$_times );
27 self::$_laps[] = $lap;
28
29 $this->value .= "\n<b>SINCE LAST CALL:</b> <b class=\"kint-microtime\">" . round( $lap, 4 ) . '</b>s.';
30 if ( $numberOfCalls > 1 ) {
31 $this->value .= "\n<b>SINCE START:</b> " . round( $time - self::$_times[0], 4 ) . 's.';
32 $this->value .= "\n<b>AVERAGE DURATION:</b> "
33 . round( array_sum( self::$_laps ) / $numberOfCalls, 4 ) . 's.';
34 }
35 }
36
37 $unit = array( 'B', 'KB', 'MB', 'GB', 'TB' );
38 if ( KINT_PHP53 ) {
39 $this->value .= "\n<b>MEMORY USAGE:</b> " . $size . " bytes ("
40 . round( $size / pow( 1024, ( $i = floor( log( $size, 1024 ) ) ) ), 3 ) . ' ' . $unit[ $i ] . ")";
41 }
42
43 self::$_times[] = $time;
44 $this->type = 'Stats';
45 }
46
47 48 49 50 51 52 53 54 55 56 57 58 59
60 }