2017-02-08 11:48:13 -08:00
wp-cli/profile-command
======================
2016-07-25 07:36:55 -07:00
2016-08-29 06:51:40 -07:00
Quickly identify what's slow with WordPress.
2016-07-25 07:36:55 -07:00
2021-05-10 10:22:57 +00:00
[](https://github.com/wp-cli/profile-command/actions/workflows/testing.yml)
2016-08-30 07:05:50 -07:00
2017-02-06 15:20:19 -08:00
Quick links: [Overview ](#overview ) | [Using ](#using ) | [Installing ](#installing ) | [Contributing ](#contributing )
2016-08-30 07:05:50 -07:00
## Overview
2016-08-29 07:20:58 -07:00
`wp profile` monitors key performance indicators of the WordPress execution process to help you quickly identify points of slowness.
2016-07-25 07:36:55 -07:00
2024-06-11 01:16:02 +05:30
Save hours diagnosing slow WordPress sites. Because you can easily run it on any server that supports WP-CLI, `wp profile` compliments Xdebug and New Relic by pointing you in the right direction for further debugging. Because it runs on the command line, using `wp profile` means you don't have to install a plugin and deal with the painful dashboard of a slow WordPress site. And, because it's a WP-CLI command, `wp profile` makes it easy to perform hard tasks (e.g. [profiling a WP REST API response ](https://danielbachhuber.com/tip/profile-wp-rest-api/ )).
2016-11-03 05:58:27 -07:00
2022-08-18 16:33:42 +00:00
[Identify why WordPress is slow in just a few steps ](https://danielbachhuber.com/tip/identify-wordpress-slowness/ ) with `wp profile` .
2016-08-29 07:20:58 -07:00
## Using
2016-10-04 06:49:18 -07:00
This package implements the following commands:
### wp profile stage
Profile each stage of the WordPress load process (bootstrap, main_query, template).
2016-08-29 07:20:58 -07:00
~~~
2024-04-05 21:22:53 +05:45
wp profile stage [< stage > ] [--all] [--spotlight] [--url=< url > ] [--fields=< fields > ] [--format=< format > ] [--order=< order > ] [--orderby=< fields > ]
2016-08-29 07:20:58 -07:00
~~~
2016-11-03 07:18:24 -07:00
When WordPress handles a request from a browser, it’ s essentially
executing as one long PHP script. `wp profile stage` breaks the script
into three stages:
* **bootstrap** is where WordPress is setting itself up, loading plugins
and the main theme, and firing the `init` hook.
* **main_query** is how WordPress transforms the request (e.g. `/2016/10/21/moms-birthday/` )
into the primary WP_Query.
* **template** is where WordPress determines which theme template to
render based on the main query, and renders it.
2016-07-25 08:14:12 -07:00
**OPTIONS**
2016-10-04 06:49:18 -07:00
[< stage > ]
Drill down into a specific stage.
2016-10-10 15:05:40 -07:00
[--all]
Expand upon all stages.
2016-10-26 05:40:34 -07:00
[--spotlight]
Filter out logs with zero-ish values from the set.
2016-07-25 08:14:12 -07:00
[--url=< url > ]
Execute a request against a specified URL. Defaults to the home URL.
2016-10-04 06:49:18 -07:00
[--fields=< fields > ]
2016-10-19 05:27:31 -07:00
Limit the output to specific fields. Default is all fields.
2016-10-04 06:49:18 -07:00
[--format=< format > ]
Render output in a particular format.
2016-08-29 06:51:40 -07:00
---
2016-10-04 06:49:18 -07:00
default: table
2016-08-29 06:51:40 -07:00
options:
2016-10-04 06:49:18 -07:00
- table
- json
- yaml
- csv
2016-08-29 06:51:40 -07:00
---
2017-12-11 05:59:38 -08:00
[--order=< order > ]
Ascending or Descending order.
---
default: ASC
options:
- ASC
- DESC
---
2024-04-05 21:22:53 +05:45
[--orderby=< fields > ]
Set orderby which field.
**EXAMPLES**
# See an overview for each stage of the load process.
$ wp profile stage --fields=stage,time,cache_ratio
+------------+---------+-------------+
| stage | time | cache_ratio |
+------------+---------+-------------+
| bootstrap | 0.7994s | 93.21% |
| main_query | 0.0123s | 94.29% |
| template | 0.792s | 91.23% |
+------------+---------+-------------+
| total (3) | 1.6037s | 92.91% |
+------------+---------+-------------+
# Dive into hook performance for a given stage.
$ wp profile stage bootstrap --fields=hook,time,cache_ratio --spotlight
+--------------------------+---------+-------------+
| hook | time | cache_ratio |
+--------------------------+---------+-------------+
2024-08-08 05:43:11 +00:00
| muplugins_loaded:before | 0.2335s | 40% |
| muplugins_loaded | 0.0007s | 50% |
| plugins_loaded:before | 0.2792s | 77.63% |
| plugins_loaded | 0.1502s | 100% |
| after_setup_theme:before | 0.068s | 100% |
| init | 0.2643s | 96.88% |
| wp_loaded:after | 0.0377s | |
2024-04-05 21:22:53 +05:45
+--------------------------+---------+-------------+
2024-08-08 05:43:11 +00:00
| total (7) | 1.0335s | 77.42% |
2024-04-05 21:22:53 +05:45
+--------------------------+---------+-------------+
2017-12-11 05:59:38 -08:00
2016-10-04 06:49:18 -07:00
### wp profile hook
2016-10-10 15:05:40 -07:00
Profile key metrics for WordPress hooks (actions and filters).
2016-10-04 06:49:18 -07:00
~~~
2024-04-05 21:22:53 +05:45
wp profile hook [< hook > ] [--all] [--spotlight] [--url=< url > ] [--fields=< fields > ] [--format=< format > ] [--order=< order > ] [--orderby=< fields > ]
2016-10-04 06:49:18 -07:00
~~~
2016-10-12 05:01:32 -07:00
In order to profile callbacks on a specific hook, the action or filter
will need to execute during the course of the request.
2016-10-04 06:49:18 -07:00
**OPTIONS**
2016-10-10 15:05:40 -07:00
[< hook > ]
Drill into key metrics of callbacks on a specific WordPress hook.
[--all]
Profile callbacks for all WordPress hooks.
2016-10-04 06:49:18 -07:00
2016-10-26 05:40:34 -07:00
[--spotlight]
Filter out logs with zero-ish values from the set.
2016-10-04 06:49:18 -07:00
[--url=< url > ]
Execute a request against a specified URL. Defaults to the home URL.
2016-08-29 06:51:40 -07:00
2016-07-25 10:17:10 -07:00
[--fields=< fields > ]
Display one or more fields.
2016-07-25 08:14:12 -07:00
[--format=< format > ]
Render output in a particular format.
---
default: table
options:
- table
- json
- yaml
- csv
---
2017-12-11 05:59:38 -08:00
[--order=< order > ]
Ascending or Descending order.
---
default: ASC
options:
- ASC
- DESC
---
2024-04-05 21:22:53 +05:45
[--orderby=< fields > ]
Set orderby which field.
**EXAMPLES**
# Profile a hook.
$ wp profile hook template_redirect --fields=callback,cache_hits,cache_misses
+--------------------------------+------------+--------------+
| callback | cache_hits | cache_misses |
+--------------------------------+------------+--------------+
| _wp_admin_bar_init() | 0 | 0 |
| wp_old_slug_redirect() | 0 | 0 |
| redirect_canonical() | 5 | 0 |
| WP_Sitemaps->render_sitemaps() | 0 | 0 |
| rest_output_link_header() | 3 | 0 |
| wp_shortlink_header() | 0 | 0 |
| wp_redirect_admin_locations() | 0 | 0 |
+--------------------------------+------------+--------------+
| total (7) | 8 | 0 |
+--------------------------------+------------+--------------+
2017-12-11 05:59:38 -08:00
2016-10-04 12:57:10 -07:00
### wp profile eval
Profile arbitrary code execution.
~~~
2024-04-05 21:22:53 +05:45
wp profile eval < php-code > [--hook[=< hook > ]] [--fields=< fields > ] [--format=< format > ] [--order=< order > ] [--orderby=< fields > ]
2016-10-04 12:57:10 -07:00
~~~
2016-10-04 14:38:12 -07:00
Code execution happens after WordPress has loaded entirely, which means
you can use any utilities defined in WordPress, active plugins, or the
current theme.
2016-10-04 12:57:10 -07:00
**OPTIONS**
< php-code >
The code to execute, as a string.
2016-11-14 06:31:51 -08:00
[--hook[=< hook > ]]
Focus on key metrics for all hooks, or callbacks on a specific hook.
2016-10-04 12:57:10 -07:00
[--fields=< fields > ]
Display one or more fields.
[--format=< format > ]
Render output in a particular format.
---
default: table
options:
- table
- json
- yaml
- csv
---
2017-12-11 05:59:38 -08:00
[--order=< order > ]
Ascending or Descending order.
---
default: ASC
options:
- ASC
- DESC
---
2024-04-05 21:22:53 +05:45
[--orderby=< fields > ]
Set orderby which field.
**EXAMPLES**
# Profile a function that makes one HTTP request.
$ wp profile eval 'wp_remote_get( "https://www.apple.com/" );' --fields=time,cache_ratio,request_count
+---------+-------------+---------------+
| time | cache_ratio | request_count |
+---------+-------------+---------------+
| 0.1009s | 100% | 1 |
+---------+-------------+---------------+
2017-12-11 05:59:38 -08:00
2016-10-04 14:38:12 -07:00
### wp profile eval-file
Profile execution of an arbitrary file.
~~~
2024-04-05 21:22:53 +05:45
wp profile eval-file < file > [--hook[=< hook > ]] [--fields=< fields > ] [--format=< format > ] [--order=< order > ] [--orderby=< fields > ]
2016-10-04 14:38:12 -07:00
~~~
File execution happens after WordPress has loaded entirely, which means
you can use any utilities defined in WordPress, active plugins, or the
current theme.
**OPTIONS**
< file >
The path to the PHP file to execute and profile.
2016-11-14 06:31:51 -08:00
[--hook[=< hook > ]]
Focus on key metrics for all hooks, or callbacks on a specific hook.
2016-10-04 14:38:12 -07:00
[--fields=< fields > ]
Display one or more fields.
[--format=< format > ]
Render output in a particular format.
---
default: table
options:
- table
- json
- yaml
- csv
---
2017-12-11 05:59:38 -08:00
[--order=< order > ]
Ascending or Descending order.
---
default: ASC
options:
- ASC
- DESC
---
2024-04-05 21:22:53 +05:45
[--orderby=< fields > ]
Set orderby which field.
**EXAMPLES**
# Profile from a file `request.php` containing `<?php wp_remote_get( "https://www.apple.com/" );` .
$ wp profile eval-file request.php --fields=time,cache_ratio,request_count
+---------+-------------+---------------+
| time | cache_ratio | request_count |
+---------+-------------+---------------+
| 0.1009s | 100% | 1 |
+---------+-------------+---------------+
2017-12-11 05:59:38 -08:00
2016-07-25 07:36:55 -07:00
## Installing
2024-11-25 07:45:57 +00:00
Installing this package requires WP-CLI v2.12 or greater. Update to the latest stable release with `wp cli update` .
2016-08-29 08:01:34 -07:00
2021-05-10 10:22:57 +00:00
Once you've done so, you can install the latest stable version of this package with:
2017-08-06 16:13:28 +09:00
2021-05-10 10:22:57 +00:00
```bash
wp package install wp-cli/profile-command:@stable
```
To install the latest development version of this package, use the following command instead:
```bash
2024-08-08 05:43:11 +00:00
wp package install wp-cli/profile-command:dev-main
2021-05-10 10:22:57 +00:00
```
2016-07-25 07:36:55 -07:00
2017-02-06 15:20:19 -08:00
## Contributing
2016-08-29 15:38:54 -07:00
2017-02-06 15:20:19 -08:00
We appreciate you taking the initiative to contribute to this project.
2016-08-29 15:38:54 -07:00
2017-02-06 15:20:19 -08:00
Contributing isn’ t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.
2017-08-06 16:13:28 +09:00
For a more thorough introduction, [check out WP-CLI's guide to contributing ](https://make.wordpress.org/cli/handbook/contributing/ ). This package follows those policy and guidelines.
2017-02-06 15:20:19 -08:00
### Reporting a bug
Think you’ ve found a bug? We’ d love for you to help us get it fixed.
2017-02-08 11:48:13 -08:00
Before you create a new issue, you should [search existing issues ](https://github.com/wp-cli/profile-command/issues?q=label%3Abug%20 ) to see if there’ s an existing resolution to it, or if it’ s already been fixed in a newer version.
2016-07-25 07:36:55 -07:00
2017-08-06 16:13:28 +09:00
Once you’ ve done a bit of searching and discovered there isn’ t an open or fixed issue for your bug, please [create a new issue ](https://github.com/wp-cli/profile-command/issues/new ). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation ](https://make.wordpress.org/cli/handbook/bug-reports/ ).
2016-07-25 07:36:55 -07:00
2017-02-06 15:20:19 -08:00
### Creating a pull request
2016-09-30 06:49:10 -07:00
2017-02-08 11:48:13 -08:00
Want to contribute a new feature? Please first [open a new issue ](https://github.com/wp-cli/profile-command/issues/new ) to discuss whether the feature is a good fit for the project.
2016-09-30 06:49:10 -07:00
2021-05-10 10:22:57 +00:00
Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request ](https://make.wordpress.org/cli/handbook/pull-requests/ ) to make sure it's a pleasant experience. See "[Setting up ](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up )" for details specific to working on this package locally.
2016-07-25 07:36:55 -07:00
2016-08-30 07:05:50 -07:00
2017-02-06 15:20:19 -08:00
*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc ](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme )). To suggest changes, please submit a pull request against the corresponding part of the codebase.*