| [ Indice ] |
Riferimento incrociato di Joomla! 1.5.14 - VM 1.1.4Servizio fornito da VMItalia |
[Vedi sommario] [Stampa] [Vedi testo]
1 <?php 2 3 /** 4 * @version $Id: profiler.php 10707 2008-08-21 09:52:47Z eddieajau $ 5 * @package Joomla.Framework 6 * @subpackage Error 7 * @copyright Copyright (C) 2005 - 2008 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 Error 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 $_buffer= null; 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[$prefix] = new 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 = $this->_prefix." $label: "; 100 $mark .= sprintf('%.3f', $this->getmicrotime() - $this->_start) . ' seconds'; 101 if ( function_exists('memory_get_usage') ) { 102 $mark .= ', '.sprintf('%0.2f', memory_get_usage() / 1048576 ).' MB'; 103 } 104 105 $this->_buffer[] = $mark; 106 return $mark; 107 } 108 109 /** 110 * Get the current time. 111 * 112 * @access public 113 * @return float The current time 114 */ 115 function getmicrotime() 116 { 117 list( $usec, $sec ) = explode( ' ', microtime() ); 118 return ((float)$usec + (float)$sec); 119 } 120 121 /** 122 * Get information about current memory usage. 123 * 124 * @access public 125 * @return int The memory usage 126 * @link PHP_MANUAL#memory_get_usage 127 */ 128 function getMemory() 129 { 130 static $isWin; 131 132 if (function_exists( 'memory_get_usage' )) { 133 return memory_get_usage(); 134 } else { 135 // Determine if a windows server 136 if (is_null( $isWin )) { 137 $isWin = (substr(PHP_OS, 0, 3) == 'WIN'); 138 } 139 140 // Initialize variables 141 $output = array(); 142 $pid = getmypid(); 143 144 if ($isWin) { 145 // Windows workaround 146 @exec( 'tasklist /FI "PID eq ' . $pid . '" /FO LIST', $output ); 147 if (!isset($output[5])) { 148 $output[5] = null; 149 } 150 return substr( $output[5], strpos( $output[5], ':' ) + 1 ); 151 } else { 152 @exec("ps -o rss -p $pid", $output); 153 return $output[1] *1024; 154 } 155 } 156 } 157 158 /** 159 * Get all profiler marks. 160 * 161 * Returns an array of all marks created since the Profiler object 162 * was instantiated. Marks are strings as per {@link JProfiler::mark()}. 163 * 164 * @access public 165 * @return array Array of profiler marks 166 */ 167 function getBuffer() { 168 return $this->_buffer; 169 } 170 }
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Descrizione
Corpo
titolo
Corpo
| Generato il: Mon Oct 19 20:29:27 2009 | Generato con PHPXref 0.7 |