Skip to content

Add cache_calls metric for persistent object cache integration#219

Draft
Copilot wants to merge 10 commits into
mainfrom
copilot/integrate-persistent-object-caches
Draft

Add cache_calls metric for persistent object cache integration#219
Copilot wants to merge 10 commits into
mainfrom
copilot/integrate-persistent-object-caches

Conversation

Copilot AI commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Multiple persistent object cache plugins expose backend call counts, but wp profile had no way to surface this data.

Changes

  • src/Logger.php — adds $cache_calls public property; adds get_object_cache_calls() static helper that reads from whichever backend is active; start() captures the offset, stop() computes and stores the delta. Gracefully no-ops (shows 0) when no supported backend is present.
  • src/Profiler.php — adds $tick_cache_calls_offset for tick-based (function-level) profiling; mirrors the same offset/delta pattern in handle_function_tick() via the shared helper.
  • src/Command.php — adds cache_calls to the $metrics fields for stage, hook, eval, and eval-file subcommands.
  • features/profile-eval.feature — two new scenarios: one asserting cache_calls = 0 with the default cache; one using a minimal object-cache.php drop-in that mimics the cache_calls array format to assert the count is correct.

Supported backends

The get_object_cache_calls() helper checks each source in order:

Plugin Property / Method
WP Redis $wp_object_cache->redis_calls (array of command → count)
Redis Object Cache $wp_object_cache->cache_calls (array of command → count)
Object Cache Pro $wp_object_cache->metrics()->storeReads + storeWrites

Example output

$ wp profile eval 'wp_cache_set( "foo", "bar" ); wp_cache_get( "foo" ); wp_cache_get( "foo" );' \
    --fields=cache_hits,cache_misses,cache_calls
+------------+--------------+-------------+
| cache_hits | cache_misses | cache_calls |
+------------+--------------+-------------+
| 2          | 0            | 3           |
+------------+--------------+-------------+

@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.13953% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Profiler.php 0.00% 14 Missing ⚠️
src/Logger.php 84.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI and others added 2 commits April 29, 2026 20:37
Copilot AI changed the title [WIP] Add integration for persistent object caches Add redis_calls metric for persistent object cache integration Apr 29, 2026
Copilot AI requested a review from swissspidy April 29, 2026 20:39
Comment thread src/Profiler.php Outdated
Comment thread src/Profiler.php Outdated
@swissspidy

This comment was marked as resolved.

…ct cache backends

Agent-Logs-Url: https://github.com/wp-cli/profile-command/sessions/96870b9d-2d37-4ac3-b192-b5d30a51d5fe

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

This comment was marked as resolved.

Copilot AI changed the title Add redis_calls metric for persistent object cache integration Add cache_calls metric for persistent object cache integration May 19, 2026
@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy swissspidy requested a review from Copilot June 9, 2026 09:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new cache_calls metric to wp profile output to surface persistent object cache backend call counts across supported implementations (WP Redis, Redis Object Cache, Object Cache Pro), including end-to-end Behat coverage.

Changes:

  • Add Logger::get_object_cache_calls() helper and track cache_calls delta in Logger::start()/stop().
  • Extend tick-based profiling to accumulate cache_calls per function in Profiler::handle_function_tick().
  • Expose cache_calls as a selectable field for stage, hook, eval, and eval-file, and add Behat scenarios covering supported/unsupported backends.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Logger.php Introduces cache_calls metric storage and backend-specific call counting helper.
src/Profiler.php Tracks cache_calls deltas during tick-based (function-level) profiling.
src/Command.php Adds cache_calls to field lists for relevant subcommands.
features/profile-eval.feature Adds Behat scenarios validating cache_calls behavior with/without a persistent cache backend.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Logger.php
Comment thread src/Profiler.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/Profiler.php Outdated
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.

Integrate with persistent object caches

4 participants