Home / admin / Display DB queries, time spent and memory consumption
  • How to Display DB queries, time spent and memory consumption

    display-db-queries-time-spent-and-memory-consumption

    Adding this snippet to the functions.php of your wordpress theme will add a comment to the footer of your wordpress theme with the following statistics. Database queries, time spent and memory consumption.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    function performance( $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', 'performance', 20 );
    

    ( WordPress codex functions, hooks, in this snippet. )

    wp_footer, add_action, _n, get_num_queries, wp,
  • Ben

    This didn’t work :( didn’t display in footer