num_queries;
$seconds = timer_stop();
/* Add the main siteadmin menu item */
$wp_admin_bar->add_menu( array( 'id' => 'queries', 'title' => "{$queries}q/{$seconds}", 'href' => 'javascript:toggle_query_list()', 'meta' => array( 'class' => 'ab-sadmin' ) ) );
}
add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_debug_menu', 1000 );
function wp_admin_bar_query_debug_list() {
global $wpdb, $wp_object_cache;
if ( !is_super_admin() )
return false;
$debugs = array();
if ( defined('SAVEQUERIES') && SAVEQUERIES )
$debugs['wpdb'] = array( __('Queries'), 'wp_admin_bar_debug_queries' );
if ( is_object($wp_object_cache) && method_exists($wp_object_cache, 'stats') )
$debugs['object-cache'] = array( __('Object Cache'), 'wp_admin_bar_debug_object_cache' );
$debugs = apply_filters( 'wp_admin_bar_debugs_list', $debugs );
if ( empty($debugs) )
return;
?>
queries) ) {
$show_many = isset($_GET['debug_queries']);
if ( $wpdb->num_queries > 500 && !$show_many )
$out .= "There are too many queries to show easily! Show them anyway.
";
$out .= '';
$first_query = 0;
$counter = 0;
foreach ( $wpdb->queries as $q ) {
list($query, $elapsed, $debug) = $q;
$total_time += $elapsed;
if ( !$show_many && ++$counter > 500 )
continue;
$query = nl2br(esc_html($query));
// $dbhname, $host, $port, $name, $tcp, $elapsed
$out .= "- $query
$debug #{$counter} (" . number_format(sprintf('%0.1f', $elapsed * 1000), 1, '.', ',') . "ms)
\n";
}
$out .= '
';
} else {
$out .= "There are no queries on this page, you won the prize!!! :)
";
}
$query_count = 'Total Queries:' . number_format( $wpdb->num_queries ) . "
\n";
$query_time = 'Total query time:' . number_format(sprintf('%0.1f', $total_time * 1000), 1) . "ms
\n";
$memory_usage = 'Peak Memory Used:' . number_format( memory_get_peak_usage( ) ) . " bytes
\n";
$out = $query_count . $query_time . $memory_usage . $out;
return $out;
}
function wp_admin_bar_debug_object_cache() {
global $wp_object_cache;
ob_start();
echo "";
$wp_object_cache->stats();
echo "
";
$out = ob_get_contents();
ob_end_clean();
return $out;
}
?>