Skip to content

Instantly share code, notes, and snippets.

@kinday
Last active February 12, 2016 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinday/009f03f9a5a83ddd0e9a to your computer and use it in GitHub Desktop.
Save kinday/009f03f9a5a83ddd0e9a to your computer and use it in GitHub Desktop.
WordPress performance stats
<?php
// Register function if WordPress is in debug mode
if ( true == 'WP_DEBUG' ) {
add_action( 'wp_footer', 'the_performance_stats' );
}
<?php
function get_performance_stats()
{
$stats = '<script>';
$stats .= 'console.info("Queries:", "' . get_num_queries() . '");';
$stats .= 'console.info("Execution time:", "' . timer_stop() . 's");';
$stats .= 'console.info("Memory usage:", "' . round( memory_get_usage() / 1024 / 1024, 2 ) . '", "MB");';
if ( current_user_can( 'administrator' ) ) {
global $wpdb;
$stats .= 'console.group("DB queries");';
foreach ( $wpdb->queries as $query ) {
$stats .= 'console.group();';
foreach ( $query as $query ) {
$stats .= 'console.log("' . $query . '");';
}
$stats .= 'console.groupEnd();';
}
$stats .= 'console.groupEnd();';
}
$stats .= '</script>';
return $stats;
}
function the_performance_stats()
{
echo $this->get_performance_stats();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment