Skip to content

Add redis_calls metric for persistent object cache integration#219

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/integrate-persistent-object-caches
Draft

Add redis_calls metric for persistent object cache integration#219
Copilot wants to merge 3 commits intomainfrom
copilot/integrate-persistent-object-caches

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

Persistent object cache plugins like WP Redis expose $wp_object_cache->redis_calls (an associative array of Redis command → count), but wp profile had no way to surface this data.

Changes

  • src/Logger.php — adds $redis_calls public property; start() captures array_sum($wp_object_cache->redis_calls) as an offset, stop() computes and stores the delta. Gracefully no-ops when redis_calls is absent (default WP object cache).
  • src/Profiler.php — adds $tick_redis_calls_offset for tick-based (function-level) profiling; mirrors the same offset/delta pattern in handle_function_tick().
  • src/Command.php — adds redis_calls to the $metrics fields for stage, hook, eval, and eval-file subcommands.
  • features/profile-eval.feature — two new scenarios: one asserting redis_calls = 0 with the default cache; one using a minimal object-cache.php drop-in that mimics WP Redis's redis_calls tracking to assert the count is correct.

Example output

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

Any persistent object cache that stores call counts in $wp_object_cache->redis_calls (WP Redis and compatible plugins) will automatically benefit from this integration.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 53.84615% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Profiler.php 0.00% 12 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
'cache_hits' => 0,
'cache_misses' => 0,
'cache_ratio' => null,
'redis_calls' => 0,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@copilot instead of redis_calls it might be worth using cache_commands or cache_calls to also support memcached or sqlite later.

Comment thread src/Profiler.php
$this->tick_query_offset = ! empty( $wpdb->queries ) ? count( $wpdb->queries ) : 0;
$this->tick_cache_hit_offset = ! empty( $wp_object_cache->cache_hits ) ? $wp_object_cache->cache_hits : 0;
$this->tick_cache_miss_offset = ! empty( $wp_object_cache->cache_misses ) ? $wp_object_cache->cache_misses : 0;
$this->tick_redis_calls_offset = isset( $wp_object_cache->redis_calls ) && is_array( $wp_object_cache->redis_calls ) ? (int) array_sum( $wp_object_cache->redis_calls ) : null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Each plugin has their own property with slightly different names.

WP Redis: $redis_calls
Redis Object Cache: $cache_calls
Object Cache Pro: metrics()->storeReads + metrics()->storeWrites

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

3 participants