Skip to content

Add --plugin grouping to wp profile hook resource output#220

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/profile-plugin-resource-usage
Draft

Add --plugin grouping to wp profile hook resource output#220
Copilot wants to merge 4 commits into
mainfrom
copilot/profile-plugin-resource-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 28, 2026

wp profile could not report resource usage at plugin granularity when profiling hooks. This change adds a plugin-level view so callback metrics can be aggregated per plugin via a first-class CLI flag.

  • Hook command surface

    • Added --plugin to wp profile hook options.
    • Updated command synopsis/docs (README.md, feature usage output) to include the new flag.
  • Plugin-level aggregation

    • Added grouping path in Command::hook() to aggregate callback metrics by plugin when --plugin is set.
    • Aggregates time, query/cache/request counters and durations, and computes aggregate cache_ratio.
    • Supports both standard plugins and mu-plugins by deriving plugin slug from callback location.
  • Behavior constraints

    • --plugin is only valid when profiling callbacks (wp profile hook <hook> or --all).
    • Returns a clear error if used on hook summary mode.
  • Acceptance coverage

    • Added Behat scenario validating plugin-grouped output for a test plugin on init.
wp profile hook init --plugin --fields=plugin,cache_hits,cache_misses

Example output shape:

+---------------+------------+--------------+
| plugin        | cache_hits | cache_misses |
+---------------+------------+--------------+
| resource-test | 0          | 1            |
+---------------+------------+--------------+
| total (1)     | 0          | 1            |
+---------------+------------+--------------+

Copilot AI linked an issue May 28, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits May 28, 2026 11:08
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add table of plugin resource usage with --plugin Add --plugin grouping to wp profile hook resource output May 28, 2026
Copilot AI requested a review from swissspidy May 28, 2026 11:12
}
add_action( 'init', 'resource_test_init_callback' );
"""
And I run `wp plugin activate resource-test`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot to make this work, you need to install wp-cli/extension-command as a composer development dependency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 9aa3a6d: added wp-cli/extension-command to require-dev in composer.json so Behat scenarios can use wp plugin ... commands.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy May 28, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profile plugin resource usage with --plugin

2 participants