wp-cli/profile-command

快速识别WordPress中的慢速问题。

安装次数: 254,594

依赖项: 2

建议者: 0

安全: 0

星标: 266

关注者: 21

分支: 29

开放问题: 16

类型:wp-cli-package

v2.1.4 2024-07-22 10:28 UTC

This package is auto-updated.

Last update: 2024-09-08 07:21:25 UTC


README

快速识别WordPress中的慢速问题。

Testing

快速链接: 概述 | 使用 | 安装 | 贡献

概述

wp profile 监控WordPress执行过程中的关键性能指标,帮助您快速识别慢速点。

节省诊断慢速WordPress站点的时间。因为您可以在支持WP-CLI的任何服务器上轻松运行它,wp profile 通过指明进一步的调试方向来补充Xdebug和New Relic。因为它是命令行运行的,使用 wp profile 意味着您不需要安装插件并处理慢速WordPress站点的痛苦仪表板。而且,因为它是WP-CLI命令,wp profile 使得执行困难任务(例如,分析WP REST API响应)变得容易。

使用 wp profile 仅需几个步骤即可 识别WordPress为什么慢

使用

此包实现了以下命令

wp profile stage

分析WordPress加载过程的每个阶段(引导、主查询、模板)。

wp profile stage [<stage>] [--all] [--spotlight] [--url=<url>] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<fields>]

当WordPress处理来自浏览器的请求时,它实际上是一个长PHP脚本的执行。 wp profile stage 将脚本分为三个阶段

  • 引导 是WordPress设置自己的地方,加载插件和主主题,并触发 init 钩子。
  • 主查询 是WordPress如何将请求(例如 /2016/10/21/moms-birthday/)转换为主要的WP_Query。
  • 模板 是WordPress根据主查询确定要渲染哪个主题模板,并渲染它。

选项

[<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.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<fields>]
	Set orderby which field.

示例

# 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 |
+--------------------------+---------+-------------+
| 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 hook

分析WordPress钩子(动作和过滤器)的关键指标。

wp profile hook [<hook>] [--all] [--spotlight] [--url=<url>] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<fields>]

为了分析特定钩子上的回调,动作或过滤器需要在请求过程中执行。

选项

[<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.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<fields>]
	Set orderby which field.

示例

# 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            |
+--------------------------------+------------+--------------+

wp profile eval

分析任意代码执行。

wp profile eval <php-code> [--hook[=<hook>]] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<fields>]

代码执行发生在WordPress完全加载之后,这意味着您可以使用WordPress中定义的任何实用工具、活动的插件或当前的主题。

选项

<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.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<fields>]
	Set orderby which field.

示例

# 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             |
+---------+-------------+---------------+

wp profile eval-file

分析任意文件的执行。

wp profile eval-file <file> [--hook[=<hook>]] [--fields=<fields>] [--format=<format>] [--order=<order>] [--orderby=<fields>]

文件执行发生在WordPress完全加载之后,这意味着您可以使用WordPress中定义的任何实用工具、活动的插件或当前的主题。

选项

<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.
	---
	default: table
	options:
	  - table
	  - json
	  - yaml
	  - csv
	---

[--order=<order>]
	Ascending or Descending order.
	---
	default: ASC
	options:
	  - ASC
	  - DESC
	---

[--orderby=<fields>]
	Set orderby which field.

示例

# 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             |
+---------+-------------+---------------+

安装

安装此包需要WP-CLI v2.5或更高版本。使用 wp cli update 更新到最新稳定版本。

完成此操作后,您可以使用以下命令安装此包的最新稳定版本

wp package install wp-cli/profile-command:@stable

要安装此包的最新开发版本,请使用以下命令代替

wp package install wp-cli/profile-command:dev-main

贡献

我们感谢您主动为这个项目做出贡献。

贡献不仅限于代码。我们鼓励您以最适合您能力的方式做出贡献,例如撰写教程、在当地聚会中进行演示、帮助其他用户解答支持问题,或者修订我们的文档。

要了解更多信息,请查看WP-CLI贡献指南。此包遵循那些政策和指南。

报告一个错误

你认为你发现了一个错误?我们很乐意你帮助我们将其修复。

在创建新的问题之前,你应该先搜索现有的问题,看看是否有现有的解决方案,或者它是否已经在更新的版本中修复。

一旦你进行了一些搜索并发现你的错误没有开放或已修复的问题,请创建一个新的问题。尽可能提供详细的信息,如果可能的话,包括明确的复现步骤。更多指导,请查看我们的错误报告文档

创建一个pull request

想要贡献一个新功能?请首先打开一个新的问题,讨论该功能是否适合项目。

一旦你决定投入时间将你的pull request完成,请遵循我们创建pull request的指南,以确保这是一个愉快的体验。有关在本地工作于此包的特定细节,请参阅"设置"。

此README.md是从项目的代码库动态生成的,使用wp scaffold package-readme文档)。要提出更改建议,请提交针对代码库相应部分的pull request。