[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> timer_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: timer_api.php,v 1.8.22.1 2007-10-13 22:35:44 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      ### Timer API ###
  25  
  26      # --- BC Timer -------
  27      # Charles Killian, modified by Kenzaburo Ito
  28  
  29      # USAGE: set $g_debug_timer to ON and just call mark_time( 'token name' );
  30      # where 'token name' is descriptive of what is happening at that point
  31  
  32      # Normally you would mark_time() before and after a critical section of
  33      # code that you are timing.  Remember to test more than once since various
  34      # factors can affect actual runtime.
  35  
  36      # --------------------
  37      # You should use this function instead of the class function
  38  	function mark_time( $p_marker_name ) {
  39          global $g_timer;
  40  
  41          $g_timer->mark_time( $p_marker_name );
  42      }
  43      # --------------------
  44      class BC_Timer {
  45          var $atime; # this is an array of ( string token => time ) array elements.
  46          # ---
  47  		function BC_Timer() {
  48              $this->atime   = array();
  49              $this->atime[] = array( "START", $this->get_microtime() );
  50          }
  51          # ---
  52          # get_microtime function taken from Everett Michaud on Zend.com
  53  		function get_microtime(){
  54              $tmp = split( ' ', microtime() );
  55              $rt = $tmp[0] + $tmp[1];
  56              return $rt;
  57          }
  58          # ---
  59          # create the time entry
  60  		function mark_time( $p_marker_name ) {
  61              $this->atime[] = array( $p_marker_name, $this->get_microtime() );
  62          }
  63          # ---
  64          # print out the timings.  If not in debug then just print out the total time.
  65  		function print_times() {
  66              global $g_debug_timer;
  67  
  68              # store end time
  69              $this->atime[] = array( "END", $this->get_microtime() );
  70  
  71              # calculate end time
  72              $timer_count = count( $this->atime );
  73              $total_time = $this->atime[$timer_count-1][1] - $this->atime[0][1];
  74  
  75              # if debug then display debug timings
  76              if ( ON == $g_debug_timer ) {
  77                  for ($i=0; $i+1 < $timer_count; $i++) {
  78                      $time = $this->atime[$i+1][1] - $this->atime[$i][1];
  79                      $time_precent = $time / $total_time * 100;
  80                      PRINT '<span class="italic">Time: '.number_format( $time, 6 ).' seconds ( '.number_format( $time_precent, 2 ).'% ) for '.$this->atime[$i][0].' -to- '.$this->atime[$i+1][0].'</span><br />';
  81                  }
  82              }
  83  
  84              # display total time
  85              PRINT '<span class="italic">Time: '.number_format( $total_time, 6 ).' seconds.</span><br />';
  86          }
  87      }
  88      # --------------------
  89  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics