Snippet: Display DB Queries, Time Spent and Memory Consumption

If you want to enable profiling inside your wordpress website to check db queries, and memory consumption then below code is just right for you

Add following code to “functions.php”

Snippet

add_action( 'wp_footer', 'sql_stats', 20 );
function sql_stats( $hide = false ) {
    $stat = sprintf(  '<p>%d queries in %.3f seconds, using %.2fMB memory</p>',
        get_num_queries(),
        timer_stop( 0, 3 ),
        memory_get_peak_usage() / 1024 / 1024
        );

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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>