Changeset 73 for ez_publish/ezipb/trunk

Show
Ignore:
Timestamp:
09/29/07 22:09:11 (16 months ago)
Author:
llaumgui
Message:

Ticket #41 : ezipb utilise à présent le débug MySQL d'eZ :

  • Compteur de requètes
  • Timer
  • etc...
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ez_publish/ezipb/trunk/classes/sql/ezipb_db_mysql_client.php

    r19 r73  
    2525 * 
    2626 * Surcharge de la classe IPB pour utiliser la connection eZ ddans IPB. 
     27 * A noter que je pourrais me passer des fonctions d'ezdbinterface 
     28 * que je récupÚrent vu qu'on est en écriture oriantée php4... 
     29 * Mais bon autant préparer l'arrivée d'eZ 4 et du php 5. 
    2730 *  
    2831 * @author Guillaume Kulakowski <guillaume_AT_llaumgui_DOT_com> 
     
    3639         
    3740        protected $ezdb;                // Connexion eZ. 
     41        private $ezini;                 // eZini 
     42         
     43        /* Timer */ 
     44        private $StartTime; 
     45        private $EndTime; 
     46        private $TimeTaken; 
    3847         
    3948         
     
    4857                 
    4958                // eZ 
    50                 $this->ezdb =& eZDB::instance(); 
     59                $this->ezdb     = &eZDB::instance(); 
     60                $this->debug    = &eZDebug::instance(); 
    5161         
    5262                // IPB 
     
    7484        } 
    7585        
    76         return TRUE; 
     86        return true; 
    7787    } 
    78          
     88 
     89 
     90 
     91        /** 
     92     * Fonction débug récupérée dans ezdbinterface.php 
     93     * Records the current micro time. End the timer with endTimer() and 
     94     * fetch the result with timeTaken(); 
     95     */ 
     96    private function startTimer() { 
     97        $this->StartTime = microtime(); 
     98    } 
     99 
    79100     
    80101     
    81102    /** 
    82      * Surcharge de la fonction query pour les logs de requêtes 
     103     * Fonction débug récupérée dans ezdbinterface.php 
     104     * Stops the current timer and calculates the time taken. 
     105     * @see startTimer, timeTaken 
     106     */ 
     107    private function endTimer()  
     108        { 
     109        $this->EndTime = microtime(); 
     110        // Calculate time taken in ms 
     111        list($usec, $sec) = explode( " ", $this->StartTime ); 
     112        $start_val = ((float)$usec + (float)$sec); 
     113        list($usec, $sec) = explode( " ", $this->EndTime ); 
     114        $end_val = ((float)$usec + (float)$sec); 
     115        $this->TimeTaken = $end_val - $start_val; 
     116        $this->TimeTaken *= 1000.0; 
     117    } 
     118 
     119     
     120     
     121    /** 
     122     * Fonction débug récupérée dans ezdbinterface.php 
     123     * @return the micro time when the timer was start or false if no timer. 
     124     */ 
     125    private function startTime() { 
     126        return $this->StartTime; 
     127    } 
     128 
     129     
     130     
     131    /** 
     132     * Fonction débug récupérée dans ezdbinterface.php 
     133     * return the micro time when the timer was ended or false if no timer. 
     134    */ 
     135    private function endTime() { 
     136        return $this->EndTime; 
     137    } 
     138 
     139     
     140     
     141    /** 
     142     * Fonction débug récupérée dans ezdbinterface.php 
     143     * @return the number of milliseconds the last operation took or false if no value. 
     144    */ 
     145    private function timeTaken() { 
     146        return $this->TimeTaken; 
     147    } 
     148     
     149     
     150     
     151    /** 
     152     * Surcharge de la fonction query pour utiliser le débug eZ 
    83153     * 
    84154     * @param string $the_query Requêtes 
     
    87157     */ 
    88158    function query($the_query, $bypass=0) { 
    89  
    90         /* 
    91          * La fonction reportQuery() étant private on la recopie ici... 
    92          */ 
    93         $debug = eZDebug::instance(); 
    94                 $debug->writeNotice( "$the_query", "IPB query", "" ); 
    95                  
    96                 return db_driver_mysql::query($the_query, $bypass=0);    
     159         
     160        $this->ezini = eZINI::instance(); 
     161        if ( ( $this->ezini->variable( "DatabaseSettings", "SQLOutput" ) == "enabled" ) and 
     162             ( $this->ezini->variable( "DebugSettings", "DebugOutput" ) == "enabled" ) ) { 
     163                        $this->debug->accumulatorStart( 'mysql_query', 'mysql_total', 'Mysql_queries' ); 
     164                        $this->startTimer(); 
     165                } 
     166         
     167        $return = db_driver_mysql::query($the_query, $bypass=0); 
     168                 
     169        if ( ( $this->ezini->variable( "DatabaseSettings", "SQLOutput" ) == "enabled" ) and 
     170             ( $this->ezini->variable( "DebugSettings", "DebugOutput" ) == "enabled" ) ) {       
     171                $this->debug->accumulatorStop( 'mysql_query' ); 
     172                $this->endTimer(); 
     173                        $this->debug->writeNotice( "$the_query", "IPB query (".intval($this->get_num_rows())." rows, ".number_format( $this->timeTaken(), 3 )." ms) query number per page:".$this->ezdb->NumQueries++, "" ); 
     174        } 
     175         
     176                return $return; 
    97177    } 
    98178