wp profile

Профилирование помогает найти слабые места в WordPress.

wp profile monitors key performance indicators of the WordPress execution process to help you quickly identify points of slowness.

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 perfom hard tasks (e.g. profiling a WP REST API response).

Список команд Описание
wp profile stage Профилирование каждого этапа процесса загрузки WordPress (bootstrap, main_query, template).
wp profile hook Профилирование хуков WordPress (события и фильтры).
wp profile eval Профилирование выполнения произвольного кода.
wp profile eval-file Профилирование выполнения произвольного файла.

Установка пакета

wp package install wp-cli/profile-command

Исходный код команд


wp profile stage

Профилирование каждого этапа процесса загрузки WordPress (bootstrap, main_query, template).

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.
# `wp profile stage` gives an overview of each stage.
$ 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%      |
+------------+---------+-------------+
# Then, dive into hooks for each stage with `wp profile stage <stage>`
$ wp profile stage bootstrap --fields=hook,time,cache_ratio --spotlight
+--------------------------+---------+-------------+
| hook                     | time    | cache_ratio |
+--------------------------+---------+-------------+
| 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 |             |
+--------------------------+---------+-------------+
| total (7)                | 1.0335s | 77.42%      |
+--------------------------+---------+-------------+

Использование

wp profile stage [{stage}] [--all] [--spotlight] [--url={url}] [--fields={fields}] [--format={format}] [--order={order}] [--orderby={orderby}]

Можно указать Глобальные параметры и следующие:

[{stage}]
Drill down into a specific stage.
[--all]
Expand upon all stages.
[--spotlight]
Filter out logs with zero-ish values from the set.
[--url={url}]
Execute a request against a specified URL. Defaults to the home URL.
[--fields={fields}]
Limit the output to specific fields. Default is all fields.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • json
  • yaml
  • csv
[--order={order}]

Ascending or Descending order.
По умолчанию: ASC
Может быть:

  • ASC
  • DESC
[--orderby={orderby}]
Order by fields.

wp profile hook

Профилирование хуков WordPress (события и фильтры).

In order to profile callbacks on a specific hook, the action or filter will need to execute during the course of the request.

Использование

wp profile hook [{hook}] [--all] [--spotlight] [--url={url}] [--fields={fields}] [--format={format}] [--order={order}] [--orderby={orderby}]

Можно указать Глобальные параметры и следующие:

[{hook}]
Drill into key metrics of callbacks on a specific WordPress hook.
[--all]
Profile callbacks for all WordPress hooks.
[--spotlight]
Filter out logs with zero-ish values from the set.
[--url={url}]
Execute a request against a specified URL. Defaults to the home URL.
[--fields={fields}]
Display one or more fields.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • json
  • yaml
  • csv
[--order={order}]

Ascending or Descending order.
По умолчанию: ASC
Может быть:

  • ASC
  • DESC
[--orderby={orderby}]
Order by fields.

wp profile eval

Профилирование выполнения произвольного кода.

Code execution happens after WordPress has loaded entirely, which means you can use any utilities defined in WordPress, active plugins, or the current theme.

Использование

wp profile eval {php-code} [--hook[={hook}]] [--fields={fields}] [--format={format}] [--order={order}] [--orderby={orderby}]

Можно указать Глобальные параметры и следующие:

{php-code}
The code to execute, as a string.
[--hook[={hook}]]
Focus on key metrics for all hooks, or callbacks on a specific hook.
[--fields={fields}]
Display one or more fields.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • json
  • yaml
  • csv
[--order={order}]

Ascending or Descending order.
По умолчанию: ASC
Может быть:

  • ASC
  • DESC
[--orderby={orderby}]
Order by fields.

wp profile eval-file

Профилирование выполнения произвольного файла.

File execution happens after WordPress has loaded entirely, which means you can use any utilities defined in WordPress, active plugins, or the current theme.

Использование

wp profile eval-file {file} [--hook[={hook}]] [--fields={fields}] [--format={format}] [--order={order}] [--orderby={orderby}]

Можно указать Глобальные параметры и следующие:

{file}
The path to the PHP file to execute and profile.
[--hook[={hook}]]
Focus on key metrics for all hooks, or callbacks on a specific hook.
[--fields={fields}]
Display one or more fields.
[--format={format}]

Render output in a particular format.
По умолчанию: table
Может быть:

  • table
  • json
  • yaml
  • csv
[--order={order}]

Ascending or Descending order.
По умолчанию: ASC
Может быть:

  • ASC
  • DESC
[--orderby={orderby}]
Order by fields.