[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/misc/ -> info.class.php (source)

   1  <?php
   2  
   3      /**
   4       * global variables to take care of the timing stuff
   5       */
   6      $__metrics_start_time = 0;
   7      $__metrics_end_time = 0;
   8  
   9      /**
  10       * Basic class for obtaining certain information about the script and the server
  11       * itself. This class will in the future have benchmarking methods, etc.
  12       */
  13      class Info
  14      {
  15          /**
  16           * @return Returns the peak memory usage (probably more useful, though only exists on php5)
  17                         or current memory usage (on PHP4),
  18                         or -1 if it cannot be determined.
  19           * @static
  20           */         
  21  		function getMemoryUsage()
  22          {
  23              if( function_exists( "memory_get_peak_usage" )) {
  24                  return( memory_get_peak_usage());
  25              }
  26              else if( function_exists( "memory_get_usage" )) {
  27                  return( memory_get_usage());
  28              }
  29              return "";
  30          }
  31          
  32          /**
  33           * Starts the measurement. This method should be called before logMetrics is called, and preferably,
  34           * at the beginning of the script
  35           *
  36           * @static
  37           * @return Always true
  38           */
  39  		function startMetrics()
  40          {
  41              global $__metrics_start_time;
  42              
  43              $mtime = microtime(); 
  44              $mtime = explode(" ",$mtime); 
  45              $mtime = $mtime[1] + $mtime[0]; 
  46              $__metrics_start_time = $mtime;
  47              
  48              return( true );
  49          }
  50          
  51          
  52          /**
  53           * sends performance statistics in CSV format to the output defined by the 'metricslog' logger.
  54           *
  55           * @static
  56           */
  57  		function logMetrics()
  58          {
  59              lt_include( PLOG_CLASS_PATH."class/logger/loggermanager.class.php" );
  60              lt_include( PLOG_CLASS_PATH."class/cache/cachemanager.class.php" );
  61              lt_include( PLOG_CLASS_PATH."class/database/db.class.php" );
  62              lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
  63          
  64              global $__metrics_start_time;
  65              
  66              $mtime = microtime(); 
  67              $mtime = explode(" ",$mtime); 
  68              $mtime = $mtime[1] + $mtime[0]; 
  69              $__metrics_end_time = $mtime;            
  70              
  71              // calculate the execution time
  72              $totalTime = ( $__metrics_end_time - $__metrics_start_time );
  73              
  74              // load cache statistics
  75              $cache =& CacheManager::getCache();
  76              $cacheData = $cache->getCacheStats();
  77              
  78              // get information from the request
  79              $script = $_SERVER["SCRIPT_NAME"];
  80              $requestUri = $_SERVER["REQUEST_URI"];
  81              
  82              // get the number of sql queries
  83              $db =& Db::getDb();
  84              $numQueries = $db->getNumQueries();
  85              if( $numQueries == "" ) $numQueries = 0;
  86              
  87              // build the message
  88              $t = new Timestamp();
  89              $message = $t->getTimestamp().",".
  90                         Info::getMemoryUsage().",".
  91                         $totalTime.",".
  92                         count(get_included_files()).",".
  93                         $numQueries.",".
  94                         $cacheData["total"].",".
  95                         $cacheData["hits"].",".
  96                         $cacheData["miss"].",\"".
  97                         $script."\",\"".
  98                         $requestUri."\"";
  99              
 100              // get the logger and log the message
 101              $logger =& LoggerManager::getLogger( "metricslog" );            
 102              $logger->debug( $message );
 103          }
 104      }
 105  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics