Xuups
Get an account!     Login

Utilities

Main menu

Who's Online

26 user(s) are online (1 user(s) are browsing Hacks and Tips)

Members: 0
Guests: 26

more...

Get Xoops

Support Xuups Project

Modules :  Query timers on debug for xoops 2.3
Tags: hack   timer   logger   query   debug  
 
This hack will enable xoops 2.3 to show the time that each query takes to execute.

The timers will be shown on the queries logger if debug is enable. Trouble queries will become red for better tracking.

This information may be useful to determine if a table is missing indexes for example, and to help developers to optimize their code.

It requires editing class/database/mysqldatabase.php and changing the method queryF() as follows:

/**
     * perform a query on the database
     * 
     * @param string $sql a valid MySQL query
     * @param int $limit number of records to return
     * @param int $start offset of first record to return
     * @return resource query result or FALSE if successful
     * or TRUE if successful and no result
     */
    
function queryF($sql$limit=0$start=0)
    {
        if ( !empty(
$limit) ) {
            if (empty(
$start)) {
                
$start 0;
            }
            
$sql $sql' LIMIT '.(int)$start.', '.(int)$limit;
        }

        
$limit_query_time '0.001'//change this value if necessary
        
$query_time 0;
        
$query_error NULL;
        
$query_message NULL;

        
//debug_mode == 1 for inline debug, change to 2 for popup debug
        
if (isset($GLOBALS['xoopsConfig']) && isset($GLOBALS['xoopsConfig']['debug_mode']) && $GLOBALS['xoopsConfig']['debug_mode'] == 1) {
            
//if mysql debug enabled
            
$this->logger->startTime('query_time'false);
            
$result =& mysql_query($sql$this->conn);
            
$this->logger->stopTime('query_time');
            
$query_time sprintf('%f'$this->logger->dumpTime('query_time'));
        }
        else {
            
//just execute the query
            
$result mysql_query($sql$this->conn);
        }
        
        if (
$query_time $limit_query_time) {
            
$query_error sprintf('QUERY TAKING MORE THAN %f SECONDS',$limit_query_time);
            
$query_message $query_time;
        }
        
         if ( 
$result ) {
            
$this->logger->addQuery($query_time.' - '.$sql$query_error$query_message);
             return 
$result;
         } else {
            
$this->logger->addQuery($sql$this->error(), $this->errno());
             return 
false;
         }

    }


Enjoy


TDM

Hack based on xoops 2.2x series.
I expect it to work on xoops 2.0.x but I have not tested.
Author
trabis
Author trabis
News by the same authorMore stories
Author rssAuthor rss
StatisticsStatistics
 
Story
Date 2008/12/21 15:15:54
Views 8334
Favorites 1
Send this Story to a FriendSend
Printer Friendly PagePrint
Create a PDF from the articleCreate a pdf
 
Bookmarks
         
         
         
         
         
     
Recents
How to sucessfuly add scripts in your Xoops Themes
Query timers on debug for xoops 2.3
Highlighting current module on mainMenu
Main menu hack - on click submenus
Preventing empty blocks to display
Random
How to sucessfuly add scripts in your Xoops Themes
Highlighting current module on mainMenu
Main menu hack - on click submenus
Preventing empty blocks to display
Adding an horizontal multiMenu to Xoops
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
 

Login

Username:

Password:

Remember me



Lost Password?

Register now!

Ajax Search


Advanced Search

Sub menu

Last comments