AloFramework Logger
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • AloFramework
    • Log
  • None
  • PHP
  • Psr
    • Log

Classes

  • BaseUser
  • Kint
  • Kint_Decorators_Plain
  • Kint_Decorators_Rich
  • Kint_Objects_Closure
  • Kint_Objects_Smarty
  • Kint_Objects_SplFileInfo
  • Kint_Parsers_ClassMethods
  • Kint_Parsers_ClassStatics
  • Kint_Parsers_Color
  • Kint_Parsers_FsPath
  • Kint_Parsers_Json
  • Kint_Parsers_Microtime
  • Kint_Parsers_objectIterateable
  • Kint_Parsers_SplObjectStorage
  • Kint_Parsers_Timestamp
  • Kint_Parsers_Xml
  • KintObject
  • kintParser
  • kintVariableData
  • User
  • UserManager

Functions

  • d
  • dd
  • ddd
  • s
  • sd
 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         # '@' is used to prevent the dreaded timezone not set error
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 ) { # meh, faster than count($times) > 1
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     function test() {
49         d( 'start', microtime() );
50         for ( $i = 0; $i < 10; $i++ ) {
51             d(
52                 $duration = mt_rand( 0, 200000 ), // the reported duration will be larger because of Kint overhead
53                 usleep( $duration ),
54                 microtime()
55             );
56         }
57         dd(  );
58     }
59      */
60 }
AloFramework Logger API documentation generated byApiGen 2.8.0