Skip to content

Introduce wp profile queries command#207

Draft
Copilot wants to merge 21 commits intomainfrom
copilot/add-wp-profile-queries
Draft

Introduce wp profile queries command#207
Copilot wants to merge 21 commits intomainfrom
copilot/add-wp-profile-queries

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

  • Understand the codebase structure and how profiling works
  • Design the wp profile queries command structure
  • Implement the core queries() method in Command.php
  • Add support for viewing all queries with execution time
  • Add --hook=<hook> parameter to filter queries for a specific hook
  • Add --callback=<callback> parameter to filter queries for a specific callback
  • Add formatting support (table, json, yaml, csv)
  • Add ordering support (--order, --orderby)
  • Add tests for the new command including hook/callback filtering
  • Enhance Logger to track query indices
  • Update documentation in README.md
  • Run code review and security checks
  • Improve first test to add custom plugin with database queries
  • Fix PHP warnings for non-numeric values in Formatter
  • Address code review feedback (callback filtering, query_indices reset, handle both params)
  • Fix test failures (add hook property to callback loggers, improve Formatter validation)
  • Change query map to use last-logger-wins approach for better specificity in nested hooks
  • Document performance characteristics and complexity of query mapping
  • Fix root cause of hook/callback filtering returning 0 results
  • Implementation complete

Summary

Fixed the root cause of hook and callback filtering always returning 0 results. The Logger::stop() method was populating query_indices during the for-loop, but then immediately clearing it ($this->query_indices = array()). This meant the array was always empty when read by the queries() command after profiling. Removed the reset from stop() to match the behavior of other accumulated properties like query_time and query_count which also accumulate across runs without being reset in stop().

Original prompt

This section details on the original issue you should resolve

<issue_title>Introduce wp profile queries</issue_title>
<issue_description>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</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 8, 2025
Copilot AI and others added 3 commits November 8, 2025 10:36
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
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] Introduce wp profile queries to monitor query performance Introduce wp profile queries command Nov 8, 2025
Copilot AI requested a review from swissspidy November 8, 2025 10:42
@swissspidy swissspidy requested a review from Copilot November 8, 2025 14:23

This comment was marked as resolved.

swissspidy and others added 3 commits November 8, 2025 15:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

… validation

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy
Copy link
Member

@copilot still 2 failing tests:

001 Scenario: Filter queries by hook # features/profile-queries.feature:80
      Then STDOUT should contain:    # features/profile-queries.feature:92
        $ wp profile queries --hook=init --fields=query,callback
        query	callback
        total (0)	
        
        cwd: /tmp/wp-cli-test-run--69a6b209a7ff70.30211979/
        run time: 0.51467704772949
        exit status: 0
        
        --- Expected
        +++ Actual
        @@ @@
        -SELECT 1 as test_query
        +query	callback
        +total (0)	
         (Exception)

002 Scenario: Filter queries by callback # features/profile-queries.feature:98
      Then STDOUT should contain:        # features/profile-queries.feature:111
        $ wp profile queries --callback=my_test_callback --fields=query,hook
        query	hook
        total (0)	
        
        cwd: /tmp/wp-cli-test-run--69a6b20b672fa3.37184918/
        run time: 0.52318000793457
        exit status: 0
        
        --- Expected
        +++ Actual
        @@ @@
        -SELECT 2 as callback_test
        +query	hook
        +total (0)	
         (Exception)

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot still 2 failing tests:

...

Found and fixed the root cause. The Logger::stop() method was populating query_indices inside the loop (line 94) but then immediately resetting it to an empty array at line 114. This meant the array was always empty when read after profiling. Removed the erroneous reset — query_indices now accumulates across runs, consistent with how query_time and query_count work. (commit 1764ddd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce wp profile queries

3 participants