Profile and find out where WordPress spends most of its time.
There's an option to hook to every single hook/filter that we can "use" to profile perfromance of almost every single part of the server request.
The request mignt take a little bit longer than without logging (hello Mr. Obvious) but the profiling tries to cut out it's own time spent.
Clone this library (e.g. to your theme folder) or use Composer:
{
"name": "your/project",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/HackingWP/wp-profiler"
}
],
"require": {
"hacking-wp/wp-profiler": "dev-main"
}
}
Don't forget to require
vendor/autoload.php
or thesrc/Log.php
directly.
Add this to your functions.php
:
if (wp_get_environment_type() !== 'production' && !defined('DOING_CRON') && !is_admin()) {
HackingWP\WPProfiler\Log::init(ABSPATH.'measurements.%s.tsv');
}
Add any other conditions when to skip logging:
- Production server requests (unless you want to)
- WP Cron jobs;
- WP Admin.
Use WP_PROFILER_TRESHHOLD_MILISECONDS
constant to override pre-defined treshold of 30 ms.
Use %s
placeholder where to put requst time float.
Example of the processed output in Google Spreadsheet:
Enjoy,