Skip to content

Commit

Permalink
Update profile commands examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Mar 27, 2024
1 parent 26107b5 commit 5dde791
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 61 deletions.
80 changes: 50 additions & 30 deletions README.md
Expand Up @@ -38,36 +38,6 @@ 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% |
+--------------------------+---------+-------------+
```

**OPTIONS**

[<stage>]
Expand Down Expand Up @@ -108,6 +78,36 @@ $ wp profile stage bootstrap --fields=hook,time,cache_ratio --spotlight
[--orderby=<orderby>]
Order by fields.

**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 |
+--------------------------+---------+-------------+
| 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
Expand Down Expand Up @@ -209,6 +209,16 @@ current theme.
[--orderby=<orderby>]
Order by fields.

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



### wp profile eval-file
Expand Down Expand Up @@ -257,6 +267,16 @@ current theme.
[--orderby=<orderby>]
Order by fields.

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

## Installing

Installing this package requires WP-CLI v2.5 or greater. Update to the latest stable release with `wp cli update`.
Expand Down
84 changes: 53 additions & 31 deletions src/Command.php
Expand Up @@ -37,6 +37,8 @@
* +--------------------------+---------+-------------+
* | total (7) | 1.0335s | 77.42% |
* +--------------------------+---------+-------------+
*
* @package wp-cli
*/
class Command {

Expand All @@ -54,36 +56,6 @@ class Command {
* * **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% |
* +--------------------------+---------+-------------+
* ```
*
* ## OPTIONS
*
* [<stage>]
Expand Down Expand Up @@ -124,6 +96,36 @@ class Command {
* [--orderby=<orderby>]
* : Order by fields.
*
* ## 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 |
* +--------------------------+---------+-------------+
* | 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% |
* +--------------------------+---------+-------------+
*
* @when before_wp_load
*/
public function stage( $args, $assoc_args ) {
Expand Down Expand Up @@ -314,6 +316,16 @@ public function hook( $args, $assoc_args ) {
* [--orderby=<orderby>]
* : Order by fields.
*
* ## 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 |
* +---------+-------------+---------------+
*
* @subcommand eval
*/
public function eval_( $args, $assoc_args ) {
Expand All @@ -325,7 +337,7 @@ public function eval_( $args, $assoc_args ) {
self::profile_eval_ish(
$assoc_args,
function () use ( $statement ) {
eval( $statement ); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- no other way oround here
eval( $statement ); // phpcs:ignore Squiz.PHP.Eval.Discouraged -- no other way around here
},
$order,
$orderby
Expand Down Expand Up @@ -373,6 +385,16 @@ function () use ( $statement ) {
* [--orderby=<orderby>]
* : Order by fields.
*
* ## 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 |
* +---------+-------------+---------------+
*
* @subcommand eval-file
*/
public function eval_file( $args, $assoc_args ) {
Expand Down

0 comments on commit 5dde791

Please sign in to comment.