BobbyeM71hxwMySQL Profiler Plugin for WordPress

WordPress is so flexible that it has not only made it a major hit but also made non-developers to customize it with ease. Most of the WordPress functions are optimized for acceptable performance, incorrect usage can cause undesirable speed loss.

Code Profiling

A (code) profiler is a performance analysis tool that measures only the frequency and duration of function calls, but there are other specific types of profilers in addition to more comprehensive profilers, capable of gathering extensive performance data.

You may not notice any performance issues unless you use code profiling to assist you. For general PHP profiling, programmers often use xdebug with all sort of PHP applications including wordpress. But, if you’re a wordpress theme developer, usually all you need is a MySQL profiler.

WP MySQL Profiler

This simple plugin will assist both theme and plugin developers in MySQL Profiling. Once installed, MySQL statistics will be available at page footer.

Installation

  • Download WP MySQL Profiler and extract the archive.
  • Rename your wp-db.php file in wp-includes directory to wp-db-backup.php.
  • Upload wp-db.php included in the archive to your wp-includes directory.
  • Upload wpSqlProfiler.php to wp-content/plugins/ directory.
  • Edit your wp-config.php. Find define (‘WPLANG’, ”); and add below:               define(‘SAVEQUERIES’, true);
  • Enable “WP MySQL Profiler” plugin from the admin CP.

Usage

You will see MySQL query details at page footer, when you will log in as an admin. Keep an eye on both total queries and time. Each time you add code to your templates, use the profiling information to check if an optimized function or code snippet has been used.

If you notice high total queries or time, examine the queries and check the backtrace (below) to find where the query originated from. And then remove or replace the unoptimized function/code.

The Backtrace

In the profiler, third column will give you the most important information. It started at themes/default/single.php on line 7 with the function get_header() which called function wp_head(), kubrick_header_display() and finally get_option() in the file functions.php on line 83.

Note that there’s a link “Show Full Trace”. For simplicity, the profiler doesn’t show all the function calls by default. Instead, it tries to determine function calls from plugins and themes. Since you are going to use it when coding plugins and themes, it makes sense to assume that you’re concerned with function calls originating therein.

Final Steps

And if you want to use the same wordpress copy on a live site, make sure to:

  • delete the wp-db.php and rename wp-db-backup.php to wp-db.php. (optional)
  • remove define(‘SAVEQUERIES’, true); from wp-config.php.

Similarly, disable the WP MySQL Profiler plugin.

http://get-a-designer.com

http://www.all1sourcetech.com

Tags: , , , ,