Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/utilities/profiler.php

Documentation is available at profiler.php

  1. <?php
  2.  
  3. /**
  4. @version        $Id: profiler.php 6675 2007-02-19 06:11:26Z louis $
  5. @package        Joomla.Framework
  6. @subpackage    Utilities
  7. @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  8. @license        GNU/GPL, see LICENSE.php
  9. *  Joomla! is free software. This version may have been modified pursuant
  10. *  to the GNU General Public License, and as distributed it includes or
  11. *  is derivative of works licensed under the GNU General Public License or
  12. *  other free or open source software licenses.
  13. *  See COPYRIGHT.php for copyright notices and details.
  14. */
  15.  
  16. // Check to ensure this file is within the rest of the framework
  17. defined('JPATH_BASE'or die();
  18.  
  19.  
  20. /**
  21.  * Utility class to assist in the process of benchmarking the execution
  22.  * of sections of code to understand where time is being spent.
  23.  *
  24.  * @package     Joomla.Framework
  25.  * @subpackage    Utilities
  26.  * @since 1.0
  27.  */
  28. class JProfiler extends JObject
  29. {
  30.     /**
  31.      *
  32.      * @var int 
  33.      */
  34.     var $_start = 0;
  35.  
  36.     /**
  37.      *
  38.      * @var string 
  39.      */
  40.     var $_prefix = '';
  41.  
  42.     /**
  43.      *
  44.      * @var array 
  45.      */
  46.     var $_buffernull;
  47.  
  48.     /**
  49.      * Constructor
  50.      *
  51.      * @access protected
  52.      * @param string Prefix for mark messages
  53.      */
  54.     function __construct$prefix '' )
  55.     {
  56.         $this->_start = $this->getmicrotime();
  57.         $this->_prefix = $prefix;
  58.         $this->_buffer = array();
  59.     }
  60.  
  61.     /**
  62.      * Returns a reference to the global Profiler object, only creating it
  63.      * if it doesn't already exist.
  64.      *
  65.      * This method must be invoked as:
  66.      *         <pre>  $browser = & JProfiler::getInstance( $prefix );</pre>
  67.      *
  68.      * @access public
  69.      * @param string Prefix used to distinguish profiler objects.
  70.      * @return JProfiler  The Profiler object.
  71.      */
  72.     function &getInstance($prefix '')
  73.     {
  74.         static $instances;
  75.  
  76.         if (!isset($instances)) {
  77.             $instances array();
  78.         }
  79.  
  80.         if (empty($instances[$prefix])) {
  81.             $instances[$prefixnew JProfiler($prefix);
  82.         }
  83.  
  84.         return $instances[$prefix];
  85.     }
  86.  
  87.     /**
  88.      * Output a time mark
  89.      *
  90.      * The mark is returned as text enclosed in <div> tags
  91.      * with a CSS class of 'profiler'.
  92.      *
  93.      * @access public
  94.      * @param string A label for the time mark
  95.      * @return string Mark enclosed in <div> tags
  96.      */
  97.     function mark$label )
  98.     {
  99.         $mark sprintf "\n<div class=\"profiler\">$this->_prefix %.3f $label</div>"$this->getmicrotime($this->_start );
  100.         $this->_buffer[$mark;
  101.         return $mark;
  102.     }
  103.  
  104.     /**
  105.      * Get the current time.
  106.      *
  107.      * @access public
  108.      * @return float The current time
  109.      */
  110.     function getmicrotime()
  111.     {
  112.         list$usec$sec explode' 'microtime() );
  113.         return ((float)$usec + (float)$sec);
  114.     }
  115.  
  116.     /**
  117.      * Get information about current memory usage.
  118.      *
  119.      * @access public
  120.      * @return int The memory usage
  121.      * @link PHP_MANUAL#memory_get_usage
  122.      */
  123.     function getMemory()
  124.     {
  125.         static $isWin;
  126.  
  127.         if (function_exists'memory_get_usage' )) {
  128.             return memory_get_usage();
  129.         else {
  130.             // Determine if a windows server
  131.             if (is_null$isWin )) {
  132.                 $isWin (substr(PHP_OS03== 'WIN');
  133.             }
  134.  
  135.             // Initialize variables
  136.             $output array();
  137.             $pid getmypid();
  138.  
  139.             if ($isWin{
  140.                 // Windows workaround
  141.                 @exec'tasklist /FI "PID eq ' $pid '" /FO LIST'$output );
  142.                 if (!isset($output[5])) {
  143.                     $output[5null;
  144.                 }
  145.                 return substr$output[5]strpos$output[5]':' );
  146.             else {
  147.                 @exec("ps -o rss -p $pid"$output);
  148.                 return $output[1*1024;
  149.             }
  150.         }
  151.     }
  152.  
  153.     /**
  154.      * Get all profiler marks.
  155.      *
  156.      * Returns an array of all marks created since the Profiler object
  157.      * was instantiated.  Marks are strings as per {@link JProfiler::mark()}.
  158.      *
  159.      * @access public
  160.      * @return array Array of profiler marks
  161.      */
  162.     function getBuffer({
  163.         return $this->_buffer;
  164.     }
  165. }
  166.  
  167. ?>

Documentation generated on Mon, 05 Mar 2007 21:19:13 +0000 by phpDocumentor 1.3.1