views:

37

answers:

2

Using a method similar to the one described here: (http://stackoverflow.com/questions/14873/how-do-i-display-database-query-statistics-on-wordpress-site), I can see the total number of queries being made when I load a page.

Now I'd like to output a list of the queries that are being made when the page loads. This would allow me to see who my biggest resource hogs are without having to go through the process of elimination of all my plugins and theme scripts.

How would I do this? Thanks.

+1  A: 

If you add define('SAVEQUERIES', true) to your configuration file, you can then list all the queries made for the current page by adding the following to your footer.

if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    print_r($wpdb->queries);
    echo "</pre>";
}

See the documentation for more details: http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis

Richard M
Thanks, this did the trick. Now I just need to make sense of the queries.
matt
A: 

or you can hook into posts_request. You can put the coe inside functions.php such as

add_filter('posts_request','debug_post_request'); // debugging sql query of a post

function debug_post_request($sql_text) {

$GLOBALS['debugku'] = $sql_text; //intercept and store the sql
return $sql_text;

}

in your theme footer, you can use print_r like print_r($GLOBALS['debugku']);

justjoe
Thanks for the suggestion. I like that this didn't require editing core files, and I think it worked, but I'm not 100% sure. It was a little hard to decipher what it output. The data seemed to be sparce, but I think that it might have all been on one line and I just couldn't see it all. I went with Richard M's suggestion above and it outputed it all into a nicely formated list.
matt
hei, like the old wisdom saying : There plenty road to Rome ;D
justjoe