Last active
February 12, 2016 00:17
-
-
Save kinday/009f03f9a5a83ddd0e9a to your computer and use it in GitHub Desktop.
WordPress performance stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register function if WordPress is in debug mode | |
if ( true == 'WP_DEBUG' ) { | |
add_action( 'wp_footer', 'the_performance_stats' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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