[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_handlers/ -> traffic_class.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_handlers/traffic_class.php,v $
  14  |     $Revision: 1.10 $
  15  |     $Date: 2006/10/21 11:18:00 $
  16  |     $Author: mrpete $
  17  +----------------------------------------------------------------------------+
  18  */
  19  
  20  if (!defined('e107_INIT')) { exit; }
  21  
  22  class e107_traffic {
  23      var $aTraffic=array();      // Overall system traffic counters
  24      var $aTrafficTimed=array(); // Timed traffic counters
  25      var $aTrafficWho=array();   // Overall system traffic source tracking
  26      var $calPassBoth=0.0;       // Calibration offset when both parameters are passed
  27      var $calPassOne=0.0;        // Calibration offset when only one parameter is passed
  28      var $calTime=0.0;           // Total time spent in overhead, based on calibration
  29      var $qTimeOn=0;                    // Quick Timer: when it started
  30      var $qTimeTotal=0.0;            // Quick Timer: Accumulated time
  31  
  32      //   function e107_traffic() {
  33      // No dynamic initializers needed, so no constructor
  34      //   }
  35  
  36      /**
  37      * @return float         Time difference
  38      * @param time $tStart   Start time - unexploded microtime result
  39      * @param time $tStop    Finish time - unexploded microtime result
  40      * @desc Calculate time difference between to microtimes
  41      * @access public
  42      */
  43  	function TimeDelta($tStart, $tFinish ) {
  44          $tFrom = explode(' ', $tStart);
  45          $tTo = explode(' ', $tFinish);
  46          $tTot = ((float)$tTo[0] + (float)$tTo[1]) - ((float)$tFrom[0] + (float)$tFrom[1]);
  47          return $tTot;
  48      }
  49  
  50      /**
  51      * @return float         Absolute time from microtime
  52      * @param time $tStart   time - unexploded microtime result
  53      * @desc Return absolute time
  54      * @access public
  55      */
  56  	function TimeAbs($tStart ) {
  57          $tFrom = explode(' ', $tStart);
  58          return (float)$tFrom[0] + (float)$tFrom[1];
  59      }
  60  
  61      /**
  62      * @return void
  63      * @param string $sWhat  what to count
  64      * @param time $tStart Start time - unexploded microtime result
  65      * @param time $tStop  Finish time - unexploded microtime result
  66      * @desc Count one of anything, optionally with time used
  67      * @access public
  68      */
  69  	function Bump($sWhat, $tStart = 0, $tFinish = 0) {
  70          $x = microtime(); // on my system:
  71          // 0        err: $e=microtime(); $eTraffic->Bump('foo',$b,$e);
  72          // ~15 usec err: $eTraffic->Bump('foo',$b,microtime());
  73          // ~25 usec err: $eTraffic->Bump('foo',$b);
  74  
  75          if (!defined("E107_DBG_TRAFFIC") || !E107_DBG_TRAFFIC) {
  76              return;
  77          }
  78  
  79          if ($tStart) {
  80              $vName = 'aTrafficTimed';
  81              $bTimed = TRUE;
  82          } else {
  83              $vName = 'aTraffic';
  84              $bTimed = FALSE;
  85          }
  86          if (!isset($this->{$vName}[$sWhat])) {
  87              $this->{$vName}[$sWhat] = array();
  88              $t = & $this->{$vName}[$sWhat];
  89              $t['Count'] = 0;
  90              if ($bTimed) {
  91                  $t['Time'] = 0.0;
  92                  $t['Min'] = 999999999.0;
  93                  $t['Max'] = 0.0;
  94              }
  95          }
  96  
  97          $this->{$vName}[$sWhat]['Count']++;
  98  
  99          if ($bTimed) {
 100              $t = & $this->aTrafficTimed[$sWhat];
 101              if (!$tFinish) {
 102                  $tFinish = $x;
 103                  $offset = $this->calPassOne;
 104              } else {
 105                  $offset = $this->calPassBoth;
 106              }
 107              $time = $this->TimeDelta($tStart, $tFinish ) - $offset;
 108              $this->calTime += $offset;
 109              $t['Time'] += $time;
 110              if ($time < $t['Min']) $t['Min'] = $time;
 111              if ($time > $t['Max']) $t['Max'] = $time;
 112          }
 113      }
 114  
 115      /**
 116      * @return void
 117      * @param string $sWhat  what to count
 118      * @param int  $level  who to record: default caller. 1-999=N levels up the call tree
 119      * @param time $tStart Start time - unexploded microtime result
 120      * @param time $tStop  Finish time - unexploded microtime result
 121      * @desc Count one of anything, optionally with time used.
 122      * @access public
 123      */
 124  	function BumpWho($sWhat, $level = 0, $tStart = 0, $tFinish = 0) {
 125          $x = microtime();
 126          if (!defined("E107_DBG_TRAFFIC") || !E107_DBG_TRAFFIC) {
 127              return;
 128          }
 129  
 130          $this->Bump($sWhat, $tStart, ($tFinish? $tFinish : $x));
 131  
 132          if (!isset($this->aTrafficWho[$sWhat])) {
 133              $this->aTrafficWho[$sWhat] = array();
 134          }
 135          $aTrace = debug_backtrace();
 136          if ($level >= count($aTrace)) {
 137              $level = count($aTrace)-1;
 138          }
 139          $sFile = $aTrace[$level]['file'];
 140          $sLine = $aTrace[$level]['line'];
 141  
 142          $this->aTrafficWho[$sWhat][] = "$sFile($sLine)";
 143      }
 144  
 145  	function Calibrate($tObject, $count = 10 ) {
 146          if (!defined("E107_DBG_TRAFFIC") || !E107_DBG_TRAFFIC) {
 147              return;
 148          }
 149          if ($tObject != $this) {
 150              message_handler("CRITICAL_ERROR", "Bad traffic object", __LINE__-2, __FILE__);
 151          }
 152          if ($count <= 0) return;    // no calibration
 153  
 154          $this->calPassBoth = $this->calPassOne = 0.0;
 155  
 156          for ($i = 0; $i < $count; $i++) {
 157              $b = microtime();
 158              $e = microtime();
 159              $tObject->Bump('TRAF_CAL1', $b, $e); // emulate the normal non-insider call
 160              $b = microtime();
 161              $tObject->Bump('TRAF_CAL2', $b);
 162          }
 163          $t = $tObject->aTrafficTimed['TRAF_CAL1'];
 164          $this->calPassBoth = $t['Time']/$t['Count'];
 165          $t = $tObject->aTrafficTimed['TRAF_CAL2'];
 166          $this->calPassOne = $t['Time']/$t['Count'];
 167      }
 168  
 169  	function Display() {
 170          if (!defined("E107_DBG_TRAFFIC") || !E107_DBG_TRAFFIC) {
 171              return '';
 172          }
 173  
 174          $text = '';
 175          @include_once(e_HANDLER.'traffic_class_display.php');
 176          return $text;
 177      }
 178  }
 179  
 180  
 181  //
 182  // This is a set of quick-n-simple tools to measure ONE bit of render time,
 183  // without any need for debug to be working. You can copy to somewhere else if needed
 184  // such as before this class has been loaded
 185  
 186  if (!isset($qTimeOn)) {
 187      $qTimeOn=0;
 188      $qTimeTotal=0;
 189  	function eQTimeOn() {
 190          $GLOBALS['qTimeOn']=explode(' ',microtime());
 191      }
 192  	function eQTimeOff() {
 193          $e=explode(' ',microtime());
 194          $diff=((float)$e[0] + (float)$e[1]) - ((float)$qTimeOn[0] + (float)$qTimeOn[1]);
 195          $GLOBALS['qTimeTotal'] += $diff;
 196      }
 197  	function eQTimeElapsed() {
 198          // return elapsed time so far, as text in microseconds, or blank if zero
 199          if ($GLOBALS['qTimeTotal']) {
 200              return number_format($GLOBALS['qTimeTotal']*1000000.0,1);
 201          } else {
 202              return '';
 203          }
 204      }
 205  
 206  }
 207  
 208  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7