Loading...
Home Picture
Code

Function to Change Display D/B Query Times & Resources

Scroll Down

/**
* code #14 - display WordPress database query times and memory consumption in footer
* source - http://wordpress.stackexchange.com/a/1866/8922
*/
function footer_stats_display($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} -->" ;
}
add_action('wp_footer', 'footer_stats_display', 20);

If you are curious about how your server handles each page load this may be worth adding into your document. This small block will add an HTML comment right at the end of each page in the wp_footer() function. You will see the total number of database queries, how long they took to perform, and how much memory was used on the server.