Giter Club home page Giter Club logo

profile-command's Introduction

wp-cli/profile-command

Quickly identify what's slow with WordPress.

Testing

Quick links: Overview | Using | Installing | Contributing

Overview

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).

Identify why WordPress is slow in just a few steps with wp profile.

Using

This package implements the following commands:

wp profile stage

Profile each stage of the WordPress load process (bootstrap, main_query, template).

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

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.

OPTIONS

[<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.

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

Profile key metrics for WordPress hooks (actions and filters).

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

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

OPTIONS

[<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.

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

wp profile eval

Profile arbitrary code execution.

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

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

OPTIONS

<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.

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

Profile execution of an arbitrary file.

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

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.

[--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.

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.

Once you've done so, you can install the latest stable version of this package with:

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

To install the latest development version of this package, use the following command instead:

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

Contributing

We appreciate you taking the initiative to contribute to this project.

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.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

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. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase.

profile-command's People

Contributors

buntybuddyboss avatar csrui avatar danielbachhuber avatar ernilambar avatar johnbillion avatar miya0001 avatar schlessera avatar sidsector9 avatar swissspidy avatar timothybjacobs avatar wojsmol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

profile-command's Issues

Can't install

Can't install via terminal

Same problem as the doctor command.
Could this be a local problem?

Installing package wp-cli/profile-command (dev-master)
Updating /Users/ralfhortt/.wp-cli/packages/composer.json to require the package...
Using Composer to install the package...
---
Loading composer repositories with package information
Updating dependencies
Resolving dependencies through SAT
Dependency resolution completed in 0.345 seconds
Your requirements could not be resolved to an installable set of packages.
Problem 1
    - The requested package runcommand/profile could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see https://getcomposer.org/doc/04-schema.md#minimum-stability for more details.

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.
---
Error: Package installation failed (Composer return code 2). Reverted composer.json```

Search by specific callback names

Ability to search by specific callback names. For example: show all FacetWP-related callbacks by searching for FWP().*

Among other things, it'd give a better picture of a plugin's impact on the site.

Put names to the intermediate stages for `--stage=<stage>`

The empty cells are confusing in this chart:

salty-wordpress ➜  plugins  wp profile --stage=bootstrap --fields=hook,time
+-------------------+---------+
| hook              | time    |
+-------------------+---------+
|                   | 0.3213s |
| muplugins_loaded  | 0.0002s |
|                   | 0.0206s |
| plugins_loaded    | 0.0358s |
|                   | 0.0004s |
| setup_theme       | 0s      |
|                   | 0.0159s |
| after_setup_theme | 0.0085s |
|                   | 0.0002s |
| init              | 0.0099s |
|                   | 0s      |
| wp_loaded         | 0.0001s |
+-------------------+---------+
| total             | 0.4129s |
+-------------------+---------+

Introduce `wp profile queries`

It would be helpful to be able to see all queries and how much time they're taking.

Also make it possible to show actual queries for (a) a specific callback or (b) all queries within a specific hook

Update installation steps with docs on how to require file

Recommended Installation Steps:

  1. Download the package from the URL in the purchase email.
  2. Extract the package files to a wp-cli-packages folder your desired WordPress install.
  3. Create a wp-cli.local.yml file in your WordPress install directory (see: Always require a specific file when running WP-CLI)
  4. Run wp profile to execute the profiler.

Doc: https://runcommand.io/to/require-file-wp-cli-yml/

From https://app.intercom.io/a/apps/w8jbky24/inbox/conversation/5807766877

Installation error: Your requirements could not be resolved to an installable set of packages

Bug Report

Describe the current, buggy behavior

Installation is failing with error: Your requirements could not be resolved to an installable set of packages.

Describe how other contributors can replicate this bug

Describe what you would expect as the correct outcome

Installation of package should be successful, as similar way to install other packages is working fine.

Let us know what environment you are running this on

OS:     Linux 5.4.0-71-generic #79-Ubuntu SMP Wed Mar 24 10:56:57 UTC 2021 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php7.4
PHP version:    7.4.16
php.ini used:   /etc/php/7.4/cli/php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/user
WP-CLI packages dir:    /home/user/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0

Provide additional context/Screenshots

Error screenshot with details as shown below:

Screenshot

Use `--focus=<focus>` to focus profiling on a named focus area

Given this example:

$ wp profile --verbose
+----------------+------------------+
| Field          | Value            |
+----------------+------------------+
| hook_count     | 10737            |
| hook_time      | 0.19295263290405 |
| execution_time | 2.438s           |
| memory_usage   | 49.5mb           |
| query_count    | 192              |
| query_time     | 0.021s           |
+----------------+------------------+

For any of these named overview fields, I should be able to --focus=<field> to focus the profiling on a specific area. For instance, --focus=hook_count would give me a list of the common hooks.

Update the readme for initial release

At the very least, we'll need:

  • Compelling description of how the command works
  • Installation instructions
  • Communication of support / feature requests.

Integrate with persistent object caches

For the persistent object caches that track additional debug information (e.g. redis_calls), it would be helpful to expose it.

To start with:

  • WP Redis
  • WP LCache

Can `wp profile` be run as a logged in user?

It would be useful for my use-cases if I could run wp profile as a logged in user, as a lot of new functionality is triggered for logged in users.

Could I request this feature? (I'm not sure if it exists already.)

Use multi-line headings

We'd save ourselves some horizontal space if we could collapse these into multi-line headings:

image

Profile command returns homepage source code

Any reason why "wp profile stages --all" would return source code of the homepage?

We got v2.1.0 with PHP 7.2.14.

Same thing happens with "doctor" command. Regular commands seem to work fine.

Warning during installation: PHP Notice: Trying to access array offset on value of type null

wp package install [email protected]:wp-cli/profile-command.git --allow-root

php -v
PHP 7.4.4 (cli) (built: Mar 20 2020 13:47:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
with Xdebug v2.9.3, Copyright (c) 2002-2020, by Derick Rethans

Bug Report

PHP Notice: Trying to access array offset on value of type null in phar:///usr/local/bin/wp/vendor/wp-cli/package-command/src/Package_Command.php on line 1244 PHP Stack trace: PHP 1. {main}() /usr/local/bin/wp:0 PHP 2. include() /usr/local/bin/wp:4 PHP 3. include() phar:///usr/local/bin/wp/php/boot-phar.php:11 PHP 4. WP_CLI\bootstrap() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:27 PHP 5. WP_CLI\Bootstrap\LaunchRunner->process() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:74 PHP 6. WP_CLI\Runner->start() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23 PHP 7. WP_CLI\Runner->do_early_invoke() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1102 PHP 8. WP_CLI\Runner->run_command_and_exit() phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:87 PHP 9. Package_Command->{closure:phar:///usr/local/bin/wp/vendor/wp-cli/package-command/src/Package_Command.php:1226-1247}() phar:///usr/local/bin/wp/vendor/wp-cli/package-command/src/Package_Command.php:0

Skipping Fatal errors possible?

I am loving wp profile, I have encountered some issues with some sites where the theme or some plugin triggers a fatal error. When this happens all I get is a fatal error and the stack trace (truncated) and no beautiful table at all.

Fatal error: Call to a member function get_value() on null in /www/game24hs_309/public/wp-content/themes/flatsome/inc/woocommerce/structure-wc-product-box.php on line 23

Is it possible to somehow suppress these warnings or make it so the table still loads? Ideally what I'd like to do is redirect these errors to a separate file for logging but still be able to see the table.

I tried redirecting STDERR to a separate file (2> /tmp/profile-errors) but it doesn't seem to make a difference

Total row missing when --format=csv is used

I noticed today the wp profile hook --all --spotlight command is showing different output

wp profile hook --all --spotlight

Output

+-----------------------------------------------------------+-----------------------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| function(){}                                              | /home/master/.wp-cli/packages/vendor/wp-cli/profile-command/inc | 0.0003s | 0s         | 0           | 50%         | 1          | 1            | 0s           | 0             |
|                                                           | /class-profiler.php:78                                          |         |            |             |             |            |              |              |               |
| wp_maybe_load_widgets()                                   | wp-includes/functions.php:3673                                  | 0.0145s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| underDEV\AdvancedCronManager\Server\Processor->block_cron | advanced-cron-manager/inc/Server/Processor.php:30               | 0.0009s | 0.0006s    | 1           | 66.67%      | 2          | 1            | 0s           | 0             |
| _executions()                                             |                                                                 |         |            |             |             |            |              |              |               |
| wpcf7()                                                   | contact-form-7/settings.php:88                                  | 0.0121s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| wppb_plugin_init()                                        | profile-builder-pro/index.php:28                                | 0.04s   | 0s         | 0           | 100%        | 30         | 0            | 0s           | 0             |
| RevSliderFront::createDBTables()                          | revslider/public/revslider-front.class.php:211                  | 0.0046s | 0.0032s    | 3           | 90.91%      | 10         | 1            | 0s           | 0             |
| SimpleLoginLog->update_db_check()                         | simple-login-log/simple-login-log.php:290                       | 0.0001s | 0s         | 0           | 66.67%      | 2          | 1            | 0s           | 0             |
| UpdraftPlus_Addons_Migrator_RemoteSend->plugins_loaded()  | updraftplus/addons/migrator.php:1482                            | 0.0005s | 0.0002s    | 1           | 66.67%      | 2          | 1            | 0s           | 0             |
| UpdraftPlus->plugins_loaded()                             | updraftplus/class-updraftplus.php:499                           | 0.0029s | 0.0002s    | 1           | 66.67%      | 2          | 1            | 0s           | 0             |
| WC_Min_Max_Quantities::get_instance()                     | woocommerce-min-max-quantities/woocommerce-min-max-quantities.p | 0.0022s | 0.0008s    | 4           | 66.67%      | 8          | 4            | 0s           | 0             |
|                                                           | hp:52                                                           |         |            |             |             |            |              |              |               |
| SV_WC_Framework_Bootstrap->load_framework_plugins()       | woocommerce-product-documents/lib/skyverge/woocommerce/class-sv | 0.0165s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
|                                                           | -wc-framework-bootstrap.php:112                                 |         |            |             |             |            |              |              |               |
| wpseo_load_textdomain()                                   | wordpress-seo-premium/wp-seo-main.php:234                       | 0.0111s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| WpSecurityAuditLog->Load()                                | wp-security-audit-log/wp-security-audit-log.php:252             | 0.0249s | 0.0065s    | 9           |             | 0          | 0            | 0s           | 0             |
| wpseo_init()                                              | wordpress-seo-premium/wp-seo-main.php:252                       | 0.02s   | 0s         | 0           | 100%        | 32         | 0            | 0s           | 0             |
| wpseo_premium_init()                                      | wordpress-seo-premium/wp-seo-premium.php:96                     | 0.0103s | 0s         | 0           | 100%        | 2          | 0            | 0s           | 0             |
| WooCommerce->init()                                       | woocommerce/woocommerce.php:416                                 | 0.034s  | 0.0006s    | 2           | 84.62%      | 11         | 2            | 0s           | 0             |
| wp_widgets_init()                                         | wp-includes/widgets.php:1438                                    | 0.013s  | 0s         | 0           | 100%        | 125        | 0            | 0s           | 0             |
| acf->init()                                               | woocommerce-shipping-tracking/classes/acf/acf.php:203           | 0.032s  | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| WC_Post_types::register_taxonomies()                      | woocommerce/includes/class-wc-post-types.php:38                 | 0.0177s | 0s         | 0           | 100%        | 94         | 0            | 0s           | 0             |
| WC_Post_types::register_post_types()                      | woocommerce/includes/class-wc-post-types.php:244                | 0.0054s | 0.0007s    | 1           | 93.33%      | 14         | 1            | 0s           | 0             |
| Vc_Manager->init()                                        | js_composer/js_composer.php:244                                 | 0.0904s | 0.0057s    | 6           | 18.6%       | 16         | 70           | 0s           | 0             |
| jckWooDeliverySlots->initiate()                           | jck_woo_deliveryslots/jck_woo_deliveryslots.php:139             | 0.0035s | 0.0005s    | 1           | 87.5%       | 7          | 1            | 0s           | 0             |
| TI_WooCommerce_WishList_Extra_Fields::init()              | ti-woocommerce-wishlist-extra-fields/ti-woocommerce-wishlist-ex | 0.0013s | 0.0011s    | 1           |             | 0          | 0            | 0s           | 0             |
|                                                           | tra-fields.php:132                                              |         |            |             |             |            |              |              |               |
| WC_SA->init()                                             | woocommerce-status-actions/includes/class-wc-sa.php:239         | 0.0014s | 0.0009s    | 1           | 100%        | 3          | 0            | 0s           | 0             |
| WC_Emails::init_transactional_emails()                    | woocommerce/includes/class-wc-emails.php:68                     | 0.0009s | 0.0005s    | 1           |             | 0          | 0            | 0s           | 0             |
| WpSecurityAuditLog->Init()                                | wp-security-audit-log/wp-security-audit-log.php:175             | 0.0045s | 0.0023s    | 4           | 100%        | 2          | 0            | 0s           | 0             |
| wppb_manage_fields_submenu()                              | profile-builder-pro/admin/manage-fields.php:9                   | 0.006s  | 0s         | 0           | 88.24%      | 15         | 2            | 0s           | 0             |
| wppb_manage_ul_cpt()                                      | profile-builder-pro/modules/user-listing/userlisting.php:2208   | 0.0015s | 0s         | 0           | 80%         | 4          | 1            | 0s           | 0             |
| wppb_prepopulate_fields()                                 | profile-builder-pro/admin/manage-fields.php:199                 | 0.0005s | 0s         | 0           | 83.33%      | 5          | 1            | 0s           | 0             |
| WC_Tab_Manager->init()                                    | woocommerce-tab-manager/woocommerce-tab-manager.php:190         | 0.0136s | 0s         | 0           | 100%        | 4          | 0            | 0s           | 0             |
| Alg_WC_Checkout_Fees_Settings_Gateways->add_gateway_fees_ | checkout-fees-for-woocommerce/includes/admin/class-wc-checkout- | 0.0243s | 0.0038s    | 7           | 87.72%      | 50         | 7            | 0s           | 0             |
| settings_hook()                                           | fees-settings-gateways.php:42                                   |         |            |             |             |            |              |              |               |
| WP_Rewrite->flush_rules()                                 | wp-includes/class-wp-rewrite.php:1802                           | 0.0165s | 0.0066s    | 2           | 100%        | 200        | 0            | 0s           | 0             |
| pmxi_wp_loaded_99()                                       | wp-all-import-pro/actions/wp_loaded_99.php:3                    | 0.0007s | 0.0005s    | 1           |             | 0          | 0            | 0s           | 0             |
| WC_API->register_rest_routes()                            | woocommerce/includes/class-wc-api.php:210                       | 0.2086s | 0.0179s    | 35          | 93.67%      | 355        | 24           | 0s           | 0             |
| create_initial_rest_routes()                              | wp-includes/rest-api.php:182                                    | 0.0582s | 0s         | 0           | 76.42%      | 162        | 50           | 0s           | 0             |
| WC_SA->add_order_statuses()                               | woocommerce-status-actions/includes/class-wc-sa.php:337         | 0.0045s | 0.0032s    | 4           | 100%        | 2          | 0            | 0s           | 0             |
| _wp_admin_bar_init()                                      | wp-includes/admin-bar.php:23                                    | 0.0009s | 0.0003s    | 1           | 80%         | 4          | 1            | 0s           | 0             |
| Vc_Base->frontCss()                                       | js_composer/include/classes/core/class-vc-base.php:505          | 0.0017s | 0.0004s    | 1           | 66.67%      | 2          | 1            | 0s           | 0             |
| wp_enqueue_scripts()                                      | wp-includes/script-loader.php:1294                              | 0.0224s | 0.0025s    | 5           | 95.04%      | 115        | 6            | 0s           | 0             |
| wp_print_head_scripts()                                   | wp-includes/script-loader.php:1248                              | 0.0069s | 0.001s     | 2           | 90.7%       | 39         | 4            | 0s           | 0             |
| Vc_Base->bodyClass()                                      | js_composer/include/classes/core/class-vc-base.php:684          | 0.0005s | 0.0003s    | 1           | 66.67%      | 2          | 1            | 0s           | 0             |
| wptexturize()                                             | wp-includes/formatting.php:41                                   | 0.0272s | 0s         | 0           |             | 0          | 0            | 0s           | 0             |
| porto_add_custom_nav_fields()                             | porto/inc/menu/menu.php:16                                      | 0.0438s | 0s         | 0           | 100%        | 20         | 0            | 0s           | 0             |
+-----------------------------------------------------------+-----------------------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| total (43)                                                |                                                                 | 0.8025s | 0.0603s    | 95          | 83.84%      | 1342       | 182          | 0s           | 0             |
+-----------------------------------------------------------+-----------------------------------------------------------------+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+

With format=csv the bottom total column is gone

wp profile hook --all --spotlight --format=csv

Output

function(){},/home/master/.wp-cli/packages/vendor/wp-cli/profile-command/inc/class-profiler.php:78,0.00023913383483887,0,0,50%,1,1,0,0
"underDEV\AdvancedCronManager\Server\Processor->block_cron_executions()",advanced-cron-manager/inc/Server/Processor.php:30,0.00092601776123047,0.00055694580078125,1,66.67%,2,1,0,0
wpcf7(),contact-form-7/settings.php:88,0.010501861572266,0,0,,0,0,0,0
wppb_plugin_init(),profile-builder-pro/index.php:28,0.032809972763062,0,0,100%,30,0,0,0
RevSliderFront::createDBTables(),revslider/public/revslider-front.class.php:211,0.0057201385498047,0.0044279098510742,3,90.91%,10,1,0,0
SimpleLoginLog->update_db_check(),simple-login-log/simple-login-log.php:290,6.0081481933594E-5,0,0,66.67%,2,1,0,0
UpdraftPlus_Addons_Migrator_RemoteSend->plugins_loaded(),updraftplus/addons/migrator.php:1482,0.00049400329589844,0.00030612945556641,1,66.67%,2,1,0,0
UpdraftPlus->plugins_loaded(),updraftplus/class-updraftplus.php:499,0.0021529197692871,0.0002129077911377,1,66.67%,2,1,0,0
WC_Min_Max_Quantities::get_instance(),woocommerce-min-max-quantities/woocommerce-min-max-quantities.php:52,0.0018842220306396,0.00083327293395996,4,66.67%,8,4,0,0
WpSecurityAuditLog->Load(),wp-security-audit-log/wp-security-audit-log.php:252,0.019633054733276,0.0046637058258057,9,,0,0,0,0
wpseo_init(),wordpress-seo-premium/wp-seo-main.php:252,0.012759923934937,0,0,100%,32,0,0,0
WooCommerce->init(),woocommerce/woocommerce.php:416,0.044458866119385,0.00072503089904785,2,84.62%,11,2,0,0
wp_widgets_init(),wp-includes/widgets.php:1438,0.011989116668701,0,0,100%,125,0,0,0
acf->init(),woocommerce-shipping-tracking/classes/acf/acf.php:203,0.036365985870361,0,0,,0,0,0,0
WC_Post_types::register_taxonomies(),woocommerce/includes/class-wc-post-types.php:38,0.024302959442139,0,0,100%,94,0,0,0
WC_Post_types::register_post_types(),woocommerce/includes/class-wc-post-types.php:244,0.0076179504394531,0.00063204765319824,1,93.33%,14,1,0,0
Vc_Manager->init(),js_composer/js_composer.php:244,0.087106943130493,0.0060820579528809,6,18.6%,16,70,0,0
jckWooDeliverySlots->initiate(),jck_woo_deliveryslots/jck_woo_deliveryslots.php:139,0.0032269954681396,0.00032401084899902,1,87.5%,7,1,0,0
TI_WooCommerce_WishList_Extra_Fields::init(),ti-woocommerce-wishlist-extra-fields/ti-woocommerce-wishlist-extra-fields.php:132,0.001270055770874,0.0010240077972412,1,,0,0,0,0
WC_SA->init(),woocommerce-status-actions/includes/class-wc-sa.php:239,0.0013620853424072,0.00067400932312012,1,100%,3,0,0,0
WC_Emails::init_transactional_emails(),woocommerce/includes/class-wc-emails.php:68,0.00060105323791504,0.0003199577331543,1,,0,0,0,0
WpSecurityAuditLog->Init(),wp-security-audit-log/wp-security-audit-log.php:175,0.0040090084075928,0.0018119812011719,4,100%,2,0,0,0
wppb_manage_fields_submenu(),profile-builder-pro/admin/manage-fields.php:9,0.013191938400269,0,0,88.24%,15,2,0,0
wppb_manage_ul_cpt(),profile-builder-pro/modules/user-listing/userlisting.php:2208,0.005108118057251,0,0,80%,4,1,0,0
wppb_prepopulate_fields(),profile-builder-pro/admin/manage-fields.php:199,0.0012059211730957,0,0,83.33%,5,1,0,0
WC_Tab_Manager->init(),woocommerce-tab-manager/woocommerce-tab-manager.php:190,0.023850917816162,0,0,100%,4,0,0,0
Alg_WC_Checkout_Fees_Settings_Gateways->add_gateway_fees_settings_hook(),checkout-fees-for-woocommerce/includes/admin/class-wc-checkout-fees-settings-gateways.php:42,0.026709794998169,0.0035951137542725,7,87.72%,50,7,0,0
WP_Rewrite->flush_rules(),wp-includes/class-wp-rewrite.php:1802,0.026412963867188,0.0089561939239502,2,100%,200,0,0,0
pmxi_wp_loaded_99(),wp-all-import-pro/actions/wp_loaded_99.php:3,0.00083494186401367,0.0005490779876709,1,,0,0,0,0
WC_API->register_rest_routes(),woocommerce/includes/class-wc-api.php:210,0.18443202972412,0.016847133636475,35,93.67%,355,24,0,0
create_initial_rest_routes(),wp-includes/rest-api.php:182,0.050954103469849,0,0,76.42%,162,50,0,0
WC_SA->add_order_statuses(),woocommerce-status-actions/includes/class-wc-sa.php:337,0.0054359436035156,0.0040264129638672,4,100%,2,0,0,0
_wp_admin_bar_init(),wp-includes/admin-bar.php:23,0.00093197822570801,0.00032997131347656,1,80%,4,1,0,0
Vc_Base->frontCss(),js_composer/include/classes/core/class-vc-base.php:505,0.0020840167999268,0.00022602081298828,1,66.67%,2,1,0,0
wp_enqueue_scripts(),wp-includes/script-loader.php:1294,0.030303001403809,0.0024213790893555,5,95.04%,115,6,0,0
wp_print_head_scripts(),wp-includes/script-loader.php:1248,0.0088381767272949,0.001317024230957,2,90.7%,39,4,0,0
Vc_Base->bodyClass(),js_composer/include/classes/core/class-vc-base.php:684,0.00064182281494141,0.00025796890258789,1,66.67%,2,1,0,0
wptexturize(),wp-includes/formatting.php:41,0.036612987518311,0,0,,0,0,0,0
porto_add_custom_nav_fields(),porto/inc/menu/menu.php:16,0.043588161468506,0,0,100%,20,0,0,0

Focus on outliers

If you don't want all of the verbosity, but only the outliers, it would be nice to have a flag for it.

coreymaass [8:19 AM] @daniel using profile on a messy site, I definitely want an arg for showing me the top 1 or few culprits http://prntscr.com/cc4xs7
[8:19] It’s a pain to have to scan this.
[8:20] Show me the top two worst ones with wp profile --hook=init —winners=2 or something.

Related #10

Broken docs for --format argument

The list of available formats is at the bottom of the docblock for each of the four commands in the Command class. It should immediately follow the [--format=<format>] section in each docblock.

The section in question is:

  ---
  default: table
  options:
  - table
  - json
  - yaml
  - csv
  ---

Adopt and enforce new `WP_CLI_CS` standard

We have a new PHPCS standard for WP-CLI called WP_CLI_CS (props @jrfnl). It is part of the wp-cli/wp-cli-tests package starting with version v2.1.0.

To adopt & enforce this new standard, the following actions need to be taken for this repository:

  • Create a PR that adds a custom ruleset phpcs.xml.dist to the repository

    • Add phpcs.xml.dist file
    • Adapt .distignore to ignore phpcs.xml.dist & phpunit.xml.dist
    • Adapt .gitignore to ignore phpunit.xml, phpcs.xml & .phpcs.xml
    • Require version ^2.1 of the wp-cli/wp-cli-tests as a dev dependency
  • Make any required changes to the code that fail the checks from the above ruleset in separate PRs

  • Merge the ruleset once all required changes have been processed and merged

A sample PR for a simple repository can be seen here: https://github.com/wp-cli/maintenance-mode-command/pull/3/files

Related wp-cli/wp-cli#5201

Invalid field: callback_count with --format=json and --fields not specified

Running wp_profile on any stage or --all with JSON or CSV output format results in the following error:

Error: Invalid field: callback_count

Other output formats like 'table' or 'yaml' work just fine. Specifying individual fields with --fields= also works, unless the problematic 'callback_count' field is requested.

PHP version: 5.6.38
WP-CLI version: 2.0.1

Create a better summary view for initial use

Our current summary view doesn't immediately point out glaring issues:

$ wp profile
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+
| stage      | time    | query_time | query_count | cache_ratio | cache_hits | cache_misses | hook_time | hook_count | request_time | request_count |
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+
| bootstrap  | 2.0408s | 0.0365s    | 15          | 93.21%      | 412        | 30           | 0.9299s   | 3097       | 0s           | 0             |
| main_query | 0.0123s | 0.0004s    | 3           | 94.29%      | 33         | 2            | 0.0098s   | 79         | 0s           | 0             |
| template   | 0.305s  | 0.0175s    | 179         | 91.02%      | 2636       | 260          | 0.1125s   | 7777       | 0s           | 0             |
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+
| total      | 2.3582s | 0.0544s    | 197         | 92.84%      | 3081       | 292          | 1.0522s   | 10953      | 0s           | 0             |
+------------+---------+------------+-------------+-------------+------------+--------------+-----------+------------+--------------+---------------+

It would be nice if we had a summary view that made it more immediately obvious where the problem areas are.

Related #61

Move command over to new v2 structure

The following changes need to be made to move the command over to the v2 structure:

  • Make sure the correct framework is required:
    composer require wp-cli/wp-cli:^2
    
  • Require the testing framework as a dev dependency:
    composer require --dev wp-cli/wp-cli-tests:^2
    
  • Use the .travis.yml file from wp-cli/wp-cli:
    wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/.travis.yml
    
  • Add the default script configuration to Composer file:
      "scripts": {
          "lint": "run-linter-tests",
          "phpcs": "run-phpcs-tests",
          "phpunit": "run-php-unit-tests",
          "behat": "run-behat-tests",
          "prepare-tests": "install-package-tests",
          "test": [
              "@lint",
              "@phpcs",
              "@phpunit",
              "@behat"
          ]
      },
    
  • Remove scaffolded binary files:
    git rm bin/install-package-tests.sh
    git rm bin/test.sh
    
  • Remove scaffolded Behat setup:
    git rm features/bootstrap/*
    git rm features/extra/*
    git rm features/steps/*
    
  • Remove scaffolded Behat tags util script:
    git rm utils/behat-tags.php
    
  • Add command packages that are needed for Behat tests as --dev dependencies.
    The following commands are already available, anything else needs to be explicitly required:
    • cli *
    • config *
    • core *
    • eval
    • eval-file
    • help
  • Update all dependencies:
    composer update
    
  • Optional - Add PHPCS rule set to enable CS & compatibility sniffing:
    wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/phpcs.xml.dist
    
  • Run and adapt tests to make sure they all pass:
    composer test
    

Introduce `wp profile cache`

We can overload the $wp_object_cache global with our own object in order to monitor which cache keys are being fetched and written.

We could also introduce a --cache flag or similar to wp profile eval-file for the user to see all of the cache keys being hit in a given profile. In this example, it would be helpful to know why the cache usage is so high.

PHP Fatal error: Allowed memory size on install package

Loading composer repositories with package information
Updating dependencies
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 86 bytes) in phar:///var/www/vhosts/*******.com/wp-cli.phar/vendor/composer/composer/src/Composer/Repository/ComposerRepository.php on line 588
Reverted composer.json.
WP-CLI ran out of memory. Please see https://bit.ly/wpclimem for further help.
[root@servidor]# env PATH="/opt/plesk/php/7.2/bin/:$PATH" ./wp-cli.phar package install [email protected]:wp-cli/profile-command.git

Help!

Thanks

--------------^ Click "Preview" for a nicer view!

GitHub issues are meant for enhancement requests and specific, reproducible bugs, not for general support questions. For support options, please review http://wp-cli.org/#support.

The easiest way to get support is to join us in the #cli channel on the Make WordPress Slack Team.

Profiling an intermediate hook is sometimes empty

When profiling an intermediate hook (e.g. wp profile hook plugins_loaded:before), some environments don't log any results:

image

In debugging this initial report, the callback hooked into register_tick_function() is only fired once.

AJAX

Will we be able to generate an AJAX request and profile it?

Warning: count(): Parameter must be an array or an object that implements Countable inc/class-logger.php on line 65

Bug Report

Warning: count(): Parameter must be an array or an object that implements Countable in /home/domain/.wp-cli/packages/vendor/wp-cli/profile-command/inc/class-logger.php on line 65

With this command: wp profile hook --all -spotlight --url=https://www.domain.tld

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.