Using the eval-file
command in wp profile
, you can profile key performance metrics for a WP REST API response by mocking, executing, and evaluating the request with a one-off file. These key performance metrics include execution time, query count, cache hit/miss ratio, and more.
For example, to mock a call to GET /wp/v2/posts?per_page=100
, you’d create a get-posts.php
file like this:
<?php
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
$request->set_param( 'per_page', 100 );
$server = rest_get_server();
$server->dispatch( $request );
Then, profile get-posts.php
by running wp profile eval-file get-posts.php
:
$ wp profile eval-file get-posts.php
+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| time | query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+
| 0.9429s | 0.002s | 5 | 96.39% | 7599 | 285 | 0s | 0 |
+---------+------------+-------------+-------------+------------+--------------+--------------+---------------+