WordPress Function to Display DB Queries, Time Spent and Memory Consumption

Display DB Queries, Time Spent and Memory Consumption

Tested on: WordPress 3.0.1

function performance( $visible = false ) {

    $stat = sprintf(  '%d queries in %.3f seconds, using %.2fMB memory',
        get_num_queries(),
        timer_stop( 0, 3 ),
        memory_get_peak_usage() / 1024 / 1024
        );

    echo $visible ? $stat : "<!-- {$stat} -->" ;
}

Then this code below the code above which will automatically insert the code above into the footer of your public website (make sure your theme is calling wp_footer):

add_action( 'wp_footer', 'performance', 20 );

Can be called multiple times.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *