title: Very slow wp-admin. Help diagnosing fault by displaying mysql queries and query times
body: <p>I have noticed that my wp-admin is extremely slow. The front-end of the site is lightning fast.</p>
  
  <p>e.g. if I visit <code>https://domain.co.uk/wordpress/wp-admin/edit-comments.php</code>, the page takes between 10-30 seconds to load.</p>
  
  <p>I ran a script to see if I can diagnose the problem:</p>
  
  <pre><code>add_filter( 'admin_footer_text', 'performance', 20 );
  
  if (is_admin())
  {
      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} " ; 
  }}
  </code></pre>
  
  <p>To find the following: <code>119 queries in 21.929 seconds, using 57.43MB memory</code> on the <code>edit-comments.php</code> page. There are only 49 comments awaiting moderation so I cannot imagine that this is a problem with mysql reading the comments.</p>
  
  <p>Is there a way of displaying individual mysql scripts and query times in that same footer of wp-admin so I can find out what's wrong?</p>
  
  <p>I have tried modifying the above code to the following, but that just overlays all queries over the entire page and is entirely unreadable:</p>
  
  <pre><code>function performance( $visible = false ) {
  
      global $wpdb;
  
      $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 : "&lt;!-- {$stat} --&gt;" ;
  
      if (SAVEQUERIES) {
          foreach ($wpdb-&gt;queries as $query)
          {
              echo '&lt;ul&gt;';
                  foreach ($query as $q)
                  {
                      echo '&lt;li&gt;'. $q .'&lt;/li&gt;';
                  }
              echo '&lt;ul&gt;';
          }
      }
  }
  </code></pre>
  
  <p>If the numerical values in $wpdb->queries are mysql query times, then the excessive php load time is caused by something in one of the PHP scripts.</p>
  
  <p>Is there a way that I can do something similar but with each plugin to determine what the cause is? </p>