2016-07-25 07:36:55 -07:00
|
|
|
|
<?php
|
|
|
|
|
|
2016-08-26 06:13:19 -07:00
|
|
|
|
namespace runcommand\Profile;
|
|
|
|
|
|
|
|
|
|
use WP_CLI;
|
|
|
|
|
use WP_CLI\Utils;
|
|
|
|
|
|
|
|
|
|
class Command {
|
2016-07-25 07:36:55 -07:00
|
|
|
|
|
|
|
|
|
/**
|
2016-10-04 06:49:18 -07:00
|
|
|
|
* Profile each stage of the WordPress load process (bootstrap, main_query, template).
|
2016-07-25 07:36:55 -07:00
|
|
|
|
*
|
2016-11-03 07:18:24 -07:00
|
|
|
|
* When WordPress handles a request from a browser, it’s essentially
|
|
|
|
|
* executing as one long PHP script. `wp profile stage` breaks the script
|
|
|
|
|
* into three stages:
|
|
|
|
|
*
|
|
|
|
|
* * **bootstrap** is where WordPress is setting itself up, loading plugins
|
|
|
|
|
* and the main theme, and firing the `init` hook.
|
|
|
|
|
* * **main_query** is how WordPress transforms the request (e.g. `/2016/10/21/moms-birthday/`)
|
|
|
|
|
* into the primary WP_Query.
|
|
|
|
|
* * **template** is where WordPress determines which theme template to
|
|
|
|
|
* render based on the main query, and renders it.
|
|
|
|
|
*
|
|
|
|
|
* ```
|
|
|
|
|
* # `wp profile stage` gives an overview of each stage.
|
|
|
|
|
* $ wp profile stage --fields=stage,time,cache_ratio
|
|
|
|
|
* +------------+---------+-------------+
|
|
|
|
|
* | stage | time | cache_ratio |
|
|
|
|
|
* +------------+---------+-------------+
|
|
|
|
|
* | bootstrap | 0.7994s | 93.21% |
|
|
|
|
|
* | main_query | 0.0123s | 94.29% |
|
|
|
|
|
* | template | 0.792s | 91.23% |
|
|
|
|
|
* +------------+---------+-------------+
|
|
|
|
|
* | total (3) | 1.6037s | 92.91% |
|
|
|
|
|
* +------------+---------+-------------+
|
|
|
|
|
*
|
|
|
|
|
* # Then, dive into hooks for each stage with `wp profile stage <stage>`
|
|
|
|
|
* $ wp profile stage bootstrap --fields=hook,time,cache_ratio --spotlight
|
|
|
|
|
* +--------------------------+---------+-------------+
|
|
|
|
|
* | hook | time | cache_ratio |
|
|
|
|
|
* +--------------------------+---------+-------------+
|
|
|
|
|
* | muplugins_loaded:before | 0.2335s | 40% |
|
|
|
|
|
* | muplugins_loaded | 0.0007s | 50% |
|
|
|
|
|
* | plugins_loaded:before | 0.2792s | 77.63% |
|
|
|
|
|
* | plugins_loaded | 0.1502s | 100% |
|
|
|
|
|
* | after_setup_theme:before | 0.068s | 100% |
|
|
|
|
|
* | init | 0.2643s | 96.88% |
|
|
|
|
|
* | wp_loaded:after | 0.0377s | |
|
|
|
|
|
* +--------------------------+---------+-------------+
|
|
|
|
|
* | total (7) | 1.0335s | 77.42% |
|
|
|
|
|
* +--------------------------+---------+-------------+
|
|
|
|
|
* ```
|
|
|
|
|
*
|
2016-07-25 07:59:37 -07:00
|
|
|
|
* ## OPTIONS
|
|
|
|
|
*
|
2016-10-04 06:47:01 -07:00
|
|
|
|
* [<stage>]
|
2016-08-27 07:05:35 -07:00
|
|
|
|
* : Drill down into a specific stage.
|
2016-08-24 16:57:37 -07:00
|
|
|
|
*
|
2016-10-07 15:45:48 -07:00
|
|
|
|
* [--all]
|
|
|
|
|
* : Expand upon all stages.
|
|
|
|
|
*
|
2016-10-26 05:40:34 -07:00
|
|
|
|
* [--spotlight]
|
|
|
|
|
* : Filter out logs with zero-ish values from the set.
|
|
|
|
|
*
|
2016-10-04 06:47:01 -07:00
|
|
|
|
* [--url=<url>]
|
|
|
|
|
* : Execute a request against a specified URL. Defaults to the home URL.
|
2016-08-25 07:00:39 -07:00
|
|
|
|
*
|
2016-07-25 10:17:10 -07:00
|
|
|
|
* [--fields=<fields>]
|
2016-10-19 05:27:31 -07:00
|
|
|
|
* : Limit the output to specific fields. Default is all fields.
|
2016-07-25 08:00:59 -07:00
|
|
|
|
*
|
|
|
|
|
* [--format=<format>]
|
|
|
|
|
* : Render output in a particular format.
|
2017-10-10 18:54:40 +05:30
|
|
|
|
*
|
|
|
|
|
* [--order=<order>]
|
2017-10-13 12:14:03 +05:30
|
|
|
|
* : Ascending or Descending order.
|
|
|
|
|
* ---
|
|
|
|
|
* default: ASC
|
|
|
|
|
* options:
|
|
|
|
|
* - ASC
|
|
|
|
|
* - DESC
|
|
|
|
|
* ---
|
2017-10-10 18:54:40 +05:30
|
|
|
|
*
|
|
|
|
|
* [--orderby=<orderby>]
|
|
|
|
|
* : Order by fields.
|
|
|
|
|
*
|
2016-07-25 08:00:59 -07:00
|
|
|
|
* ---
|
|
|
|
|
* default: table
|
|
|
|
|
* options:
|
|
|
|
|
* - table
|
|
|
|
|
* - json
|
|
|
|
|
* - yaml
|
|
|
|
|
* - csv
|
|
|
|
|
* ---
|
|
|
|
|
*
|
2016-07-25 07:36:55 -07:00
|
|
|
|
* @when before_wp_load
|
|
|
|
|
*/
|
2016-10-04 06:47:01 -07:00
|
|
|
|
public function stage( $args, $assoc_args ) {
|
2016-07-25 08:10:43 -07:00
|
|
|
|
global $wpdb;
|
|
|
|
|
|
2017-10-11 13:27:14 +05:30
|
|
|
|
$focus = Utils\get_flag_value( $assoc_args, 'all', isset( $args[0] ) ? $args[0] : null );
|
|
|
|
|
|
|
|
|
|
$order = Utils\get_flag_value( $assoc_args, 'order', 'ASC' );
|
|
|
|
|
$orderby = Utils\get_flag_value( $assoc_args, 'orderby', null );
|
2016-08-24 16:57:37 -07:00
|
|
|
|
|
2016-10-04 06:47:01 -07:00
|
|
|
|
$valid_stages = array( 'bootstrap', 'main_query', 'template' );
|
2016-10-08 07:27:46 -07:00
|
|
|
|
if ( $focus && ( true !== $focus && ! in_array( $focus, $valid_stages, true ) ) ) {
|
2016-10-07 15:45:48 -07:00
|
|
|
|
WP_CLI::error( 'Invalid stage. Must be one of ' . implode( ', ', $valid_stages ) . ', or use --all.' );
|
2016-07-25 07:59:37 -07:00
|
|
|
|
}
|
2016-10-04 06:47:01 -07:00
|
|
|
|
|
2016-10-08 07:27:46 -07:00
|
|
|
|
$profiler = new Profiler( 'stage', $focus );
|
2016-10-08 06:37:41 -07:00
|
|
|
|
$profiler->run();
|
2016-07-25 07:59:37 -07:00
|
|
|
|
|
2016-10-08 07:27:46 -07:00
|
|
|
|
if ( $focus ) {
|
2016-10-26 05:40:34 -07:00
|
|
|
|
$base = array(
|
2016-08-24 16:57:37 -07:00
|
|
|
|
'hook',
|
2016-10-07 16:18:04 -07:00
|
|
|
|
'callback_count',
|
2016-10-26 05:40:34 -07:00
|
|
|
|
);
|
|
|
|
|
$metrics = array(
|
2016-08-26 13:00:32 -07:00
|
|
|
|
'time',
|
2016-08-26 13:19:09 -07:00
|
|
|
|
'query_time',
|
|
|
|
|
'query_count',
|
2016-08-26 14:58:37 -07:00
|
|
|
|
'cache_ratio',
|
2016-08-26 13:19:09 -07:00
|
|
|
|
'cache_hits',
|
|
|
|
|
'cache_misses',
|
|
|
|
|
'request_time',
|
|
|
|
|
'request_count',
|
2016-08-24 16:57:37 -07:00
|
|
|
|
);
|
|
|
|
|
} else {
|
2016-10-26 05:40:34 -07:00
|
|
|
|
$base = array(
|
2016-08-27 07:05:35 -07:00
|
|
|
|
'stage',
|
2016-10-26 05:40:34 -07:00
|
|
|
|
);
|
|
|
|
|
$metrics = array(
|
2016-08-26 13:00:32 -07:00
|
|
|
|
'time',
|
2016-08-26 13:19:09 -07:00
|
|
|
|
'query_time',
|
|
|
|
|
'query_count',
|
2016-08-26 14:58:37 -07:00
|
|
|
|
'cache_ratio',
|
2016-08-26 13:19:09 -07:00
|
|
|
|
'cache_hits',
|
|
|
|
|
'cache_misses',
|
|
|
|
|
'hook_time',
|
|
|
|
|
'hook_count',
|
|
|
|
|
'request_time',
|
|
|
|
|
'request_count',
|
2016-08-26 07:42:05 -07:00
|
|
|
|
);
|
2016-07-25 10:17:10 -07:00
|
|
|
|
}
|
2016-10-26 05:40:34 -07:00
|
|
|
|
$fields = array_merge( $base, $metrics );
|
2016-08-26 07:05:20 -07:00
|
|
|
|
$formatter = new Formatter( $assoc_args, $fields );
|
2016-10-26 05:40:34 -07:00
|
|
|
|
$loggers = $profiler->get_loggers();
|
|
|
|
|
if ( Utils\get_flag_value( $assoc_args, 'spotlight' ) ) {
|
|
|
|
|
$loggers = self::shine_spotlight( $loggers, $metrics );
|
|
|
|
|
}
|
2017-10-10 18:54:40 +05:30
|
|
|
|
|
2017-10-13 12:14:03 +05:30
|
|
|
|
$formatter->display_items( $loggers, true, $order, $orderby );
|
2017-10-10 18:54:40 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 06:47:01 -07:00
|
|
|
|
/**
|
2016-10-08 07:27:46 -07:00
|
|
|
|
* Profile key metrics for WordPress hooks (actions and filters).
|
2016-10-04 06:47:01 -07:00
|
|
|
|
*
|
2016-10-12 05:01:32 -07:00
|
|
|
|
* In order to profile callbacks on a specific hook, the action or filter
|
|
|
|
|
* will need to execute during the course of the request.
|
|
|
|
|
*
|
2016-10-04 06:47:01 -07:00
|
|
|
|
* ## OPTIONS
|
|
|
|
|
*
|
2016-10-08 07:27:46 -07:00
|
|
|
|
* [<hook>]
|
2016-10-08 16:18:48 -07:00
|
|
|
|
* : Drill into key metrics of callbacks on a specific WordPress hook.
|
|
|
|
|
*
|
|
|
|
|
* [--all]
|
|
|
|
|
* : Profile callbacks for all WordPress hooks.
|
2016-10-04 06:47:01 -07:00
|
|
|
|
*
|
2016-10-26 05:40:34 -07:00
|
|
|
|
* [--spotlight]
|
|
|
|
|
* : Filter out logs with zero-ish values from the set.
|
|
|
|
|
*
|
2016-10-04 06:47:01 -07:00
|
|
|
|
* [--url=<url>]
|
|
|
|
|
* : Execute a request against a specified URL. Defaults to the home URL.
|
|
|
|
|
*
|
|
|
|
|
* [--fields=<fields>]
|
|
|
|
|
* : Display one or more fields.
|
|
|
|
|
*
|
|
|
|
|
* [--format=<format>]
|
|
|
|
|
* : Render output in a particular format.
|
2017-10-11 13:27:14 +05:30
|
|
|
|
*
|
|
|
|
|
* [--order=<order>]
|
2017-10-13 12:14:03 +05:30
|
|
|
|
* : Ascending or Descending order.
|
|
|
|
|
* ---
|
|
|
|
|
* default: ASC
|
|
|
|
|
* options:
|
|
|
|
|
* - ASC
|
|
|
|
|
* - DESC
|
|
|
|
|
* ---
|
2017-10-11 13:27:14 +05:30
|
|
|
|
*
|
|
|
|
|
* [--orderby=<orderby>]
|
|
|
|
|
* : Order by fields.
|
|
|
|
|
*
|
2016-10-04 06:47:01 -07:00
|
|
|
|
* default: table
|
|
|
|
|
* options:
|
|
|
|
|
* - table
|
|
|
|
|
* - json
|
|
|
|
|
* - yaml
|
|
|
|
|
* - csv
|
|
|
|
|
* ---
|
|
|
|
|
*
|
|
|
|
|
* @when before_wp_load
|
|
|
|
|
*/
|
|
|
|
|
public function hook( $args, $assoc_args ) {
|
|
|
|
|
|
2016-10-08 16:18:48 -07:00
|
|
|
|
$focus = Utils\get_flag_value( $assoc_args, 'all', isset( $args[0] ) ? $args[0] : null );
|
2016-10-08 06:37:41 -07:00
|
|
|
|
|
2017-10-11 13:27:14 +05:30
|
|
|
|
$order = Utils\get_flag_value( $assoc_args, 'order', 'ASC' );
|
|
|
|
|
$orderby = Utils\get_flag_value( $assoc_args, 'orderby', null );
|
|
|
|
|
|
2016-10-08 06:37:41 -07:00
|
|
|
|
$profiler = new Profiler( 'hook', $focus );
|
|
|
|
|
$profiler->run();
|
2016-10-04 06:47:01 -07:00
|
|
|
|
|
2016-10-04 14:10:27 -07:00
|
|
|
|
// 'shutdown' won't actually fire until script completion
|
|
|
|
|
// but we can mock it
|
2016-10-08 06:37:41 -07:00
|
|
|
|
if ( 'shutdown' === $focus ) {
|
2016-10-04 14:10:27 -07:00
|
|
|
|
do_action( 'shutdown' );
|
|
|
|
|
remove_all_actions( 'shutdown' );
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 07:27:46 -07:00
|
|
|
|
if ( $focus ) {
|
|
|
|
|
$base = array( 'callback', 'location' );
|
|
|
|
|
} else {
|
|
|
|
|
$base = array( 'hook', 'callback_count' );
|
|
|
|
|
}
|
|
|
|
|
$metrics = array(
|
2016-10-04 06:47:01 -07:00
|
|
|
|
'time',
|
|
|
|
|
'query_time',
|
|
|
|
|
'query_count',
|
|
|
|
|
'cache_ratio',
|
|
|
|
|
'cache_hits',
|
|
|
|
|
'cache_misses',
|
|
|
|
|
'request_time',
|
|
|
|
|
'request_count',
|
|
|
|
|
);
|
2016-10-08 07:27:46 -07:00
|
|
|
|
$fields = array_merge( $base, $metrics );
|
2016-10-04 06:47:01 -07:00
|
|
|
|
$formatter = new Formatter( $assoc_args, $fields );
|
2016-10-26 05:40:34 -07:00
|
|
|
|
$loggers = $profiler->get_loggers();
|
|
|
|
|
if ( Utils\get_flag_value( $assoc_args, 'spotlight' ) ) {
|
|
|
|
|
$loggers = self::shine_spotlight( $loggers, $metrics );
|
|
|
|
|
}
|
2017-10-13 12:14:03 +05:30
|
|
|
|
$formatter->display_items( $loggers, true, $order, $orderby );
|
2016-10-04 06:47:01 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 12:57:10 -07:00
|
|
|
|
/**
|
|
|
|
|
* Profile arbitrary code execution.
|
|
|
|
|
*
|
2016-10-04 14:38:12 -07:00
|
|
|
|
* Code execution happens after WordPress has loaded entirely, which means
|
|
|
|
|
* you can use any utilities defined in WordPress, active plugins, or the
|
|
|
|
|
* current theme.
|
|
|
|
|
*
|
2016-10-04 12:57:10 -07:00
|
|
|
|
* ## OPTIONS
|
|
|
|
|
*
|
|
|
|
|
* <php-code>
|
|
|
|
|
* : The code to execute, as a string.
|
|
|
|
|
*
|
2016-11-14 06:30:19 -08:00
|
|
|
|
* [--hook[=<hook>]]
|
|
|
|
|
* : Focus on key metrics for all hooks, or callbacks on a specific hook.
|
|
|
|
|
*
|
2016-10-04 12:57:10 -07:00
|
|
|
|
* [--fields=<fields>]
|
|
|
|
|
* : Display one or more fields.
|
|
|
|
|
*
|
|
|
|
|
* [--format=<format>]
|
|
|
|
|
* : Render output in a particular format.
|
2017-10-11 14:39:22 +05:30
|
|
|
|
*
|
|
|
|
|
* [--order=<order>]
|
2017-10-13 12:14:03 +05:30
|
|
|
|
* : Ascending or Descending order.
|
|
|
|
|
* ---
|
|
|
|
|
* default: ASC
|
|
|
|
|
* options:
|
|
|
|
|
* - ASC
|
|
|
|
|
* - DESC
|
|
|
|
|
* ---
|
2017-10-11 14:39:22 +05:30
|
|
|
|
*
|
|
|
|
|
* [--orderby=<orderby>]
|
|
|
|
|
* : Order by fields.
|
|
|
|
|
*
|
2016-10-04 12:57:10 -07:00
|
|
|
|
* ---
|
|
|
|
|
* default: table
|
|
|
|
|
* options:
|
|
|
|
|
* - table
|
|
|
|
|
* - json
|
|
|
|
|
* - yaml
|
|
|
|
|
* - csv
|
|
|
|
|
* ---
|
|
|
|
|
*
|
|
|
|
|
* @subcommand eval
|
|
|
|
|
*/
|
|
|
|
|
public function eval_( $args, $assoc_args ) {
|
2016-11-14 06:30:19 -08:00
|
|
|
|
$statement = $args[0];
|
2017-10-11 14:39:22 +05:30
|
|
|
|
|
|
|
|
|
$order = Utils\get_flag_value( $assoc_args, 'order', 'ASC' );
|
|
|
|
|
$orderby = Utils\get_flag_value( $assoc_args, 'orderby', null );
|
|
|
|
|
|
2017-10-11 14:49:42 +05:30
|
|
|
|
self::profile_eval_ish( $assoc_args, function() use ( $statement ) {
|
2016-11-14 06:30:19 -08:00
|
|
|
|
eval( $statement );
|
2017-10-11 14:49:42 +05:30
|
|
|
|
}, $order, $orderby );
|
2016-10-04 12:57:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 14:38:12 -07:00
|
|
|
|
/**
|
|
|
|
|
* Profile execution of an arbitrary file.
|
|
|
|
|
*
|
|
|
|
|
* File execution happens after WordPress has loaded entirely, which means
|
|
|
|
|
* you can use any utilities defined in WordPress, active plugins, or the
|
|
|
|
|
* current theme.
|
|
|
|
|
*
|
|
|
|
|
* ## OPTIONS
|
|
|
|
|
*
|
|
|
|
|
* <file>
|
|
|
|
|
* : The path to the PHP file to execute and profile.
|
|
|
|
|
*
|
2016-11-14 06:30:19 -08:00
|
|
|
|
* [--hook[=<hook>]]
|
|
|
|
|
* : Focus on key metrics for all hooks, or callbacks on a specific hook.
|
|
|
|
|
*
|
2016-10-04 14:38:12 -07:00
|
|
|
|
* [--fields=<fields>]
|
|
|
|
|
* : Display one or more fields.
|
|
|
|
|
*
|
|
|
|
|
* [--format=<format>]
|
|
|
|
|
* : Render output in a particular format.
|
2017-10-11 14:39:22 +05:30
|
|
|
|
*
|
|
|
|
|
* [--order=<order>]
|
2017-10-13 12:14:03 +05:30
|
|
|
|
* : Ascending or Descending order.
|
|
|
|
|
* ---
|
|
|
|
|
* default: ASC
|
|
|
|
|
* options:
|
|
|
|
|
* - ASC
|
|
|
|
|
* - DESC
|
|
|
|
|
* ---
|
2017-10-11 14:39:22 +05:30
|
|
|
|
*
|
|
|
|
|
* [--orderby=<orderby>]
|
|
|
|
|
* : Order by fields.
|
|
|
|
|
*
|
2016-10-04 14:38:12 -07:00
|
|
|
|
* ---
|
|
|
|
|
* default: table
|
|
|
|
|
* options:
|
|
|
|
|
* - table
|
|
|
|
|
* - json
|
|
|
|
|
* - yaml
|
|
|
|
|
* - csv
|
|
|
|
|
* ---
|
|
|
|
|
*
|
|
|
|
|
* @subcommand eval-file
|
|
|
|
|
*/
|
|
|
|
|
public function eval_file( $args, $assoc_args ) {
|
|
|
|
|
|
|
|
|
|
$file = $args[0];
|
2017-10-11 14:39:22 +05:30
|
|
|
|
|
|
|
|
|
$order = Utils\get_flag_value( $assoc_args, 'order', 'ASC' );
|
|
|
|
|
$orderby = Utils\get_flag_value( $assoc_args, 'orderby', null );
|
|
|
|
|
|
2016-10-04 14:38:12 -07:00
|
|
|
|
if ( ! file_exists( $file ) ) {
|
|
|
|
|
WP_CLI::error( "'$file' does not exist." );
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 06:30:19 -08:00
|
|
|
|
self::profile_eval_ish( $assoc_args, function() use ( $file ) {
|
|
|
|
|
self::include_file( $file );
|
2017-10-11 14:59:13 +05:30
|
|
|
|
}, $order, $orderby );
|
2016-11-14 06:30:19 -08:00
|
|
|
|
}
|
2016-10-04 14:38:12 -07:00
|
|
|
|
|
2016-11-14 06:30:19 -08:00
|
|
|
|
/**
|
|
|
|
|
* Profile an eval or eval-file statement.
|
|
|
|
|
*/
|
|
|
|
|
private static function profile_eval_ish( $assoc_args, $profile_callback ) {
|
|
|
|
|
$hook = Utils\get_flag_value( $assoc_args, 'hook' );
|
|
|
|
|
$type = $focus = false;
|
|
|
|
|
$fields = array();
|
|
|
|
|
if ( $hook ) {
|
|
|
|
|
$type = 'hook';
|
|
|
|
|
if ( true !== $hook ) {
|
|
|
|
|
$focus = $hook;
|
|
|
|
|
$fields[] = 'callback';
|
|
|
|
|
$fields[] = 'location';
|
|
|
|
|
} else {
|
|
|
|
|
$fields[] = 'hook';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$profiler = new Profiler( $type, $focus );
|
|
|
|
|
$profiler->run();
|
|
|
|
|
if ( $hook ) {
|
|
|
|
|
$profile_callback();
|
|
|
|
|
$loggers = $profiler->get_loggers();
|
|
|
|
|
} else {
|
|
|
|
|
$logger = new Logger();
|
|
|
|
|
$logger->start();
|
|
|
|
|
$profile_callback();
|
|
|
|
|
$logger->stop();
|
|
|
|
|
$loggers = array( $logger );
|
|
|
|
|
}
|
|
|
|
|
$fields = array_merge( $fields, array(
|
2016-10-04 14:38:12 -07:00
|
|
|
|
'time',
|
|
|
|
|
'query_time',
|
|
|
|
|
'query_count',
|
|
|
|
|
'cache_ratio',
|
|
|
|
|
'cache_hits',
|
|
|
|
|
'cache_misses',
|
|
|
|
|
'request_time',
|
|
|
|
|
'request_count',
|
2016-11-14 06:30:19 -08:00
|
|
|
|
) );
|
2016-10-04 14:38:12 -07:00
|
|
|
|
$formatter = new Formatter( $assoc_args, $fields );
|
2017-10-13 12:14:03 +05:30
|
|
|
|
$formatter->display_items( $loggers, false, $order, $orderby );
|
2016-10-04 14:38:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Include a file without exposing it to current scope
|
|
|
|
|
*
|
|
|
|
|
* @param string $file
|
|
|
|
|
*/
|
|
|
|
|
private static function include_file( $file ) {
|
|
|
|
|
include( $file );
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 05:40:34 -07:00
|
|
|
|
/**
|
|
|
|
|
* Filter loggers with zero-ish values.
|
|
|
|
|
*
|
|
|
|
|
* @param array $loggers
|
|
|
|
|
* @param array $metrics
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private static function shine_spotlight( $loggers, $metrics ) {
|
|
|
|
|
|
|
|
|
|
foreach( $loggers as $k => $logger ) {
|
|
|
|
|
$non_zero = false;
|
|
|
|
|
foreach( $metrics as $metric ) {
|
|
|
|
|
switch ( $metric ) {
|
|
|
|
|
// 100% cache ratio is fine by us
|
|
|
|
|
case 'cache_ratio':
|
|
|
|
|
case 'cache_hits':
|
|
|
|
|
case 'cache_misses':
|
|
|
|
|
if ( $logger->cache_ratio && '100%' !== $logger->cache_ratio ) {
|
|
|
|
|
$non_zero = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'time':
|
|
|
|
|
case 'query_time':
|
|
|
|
|
if ( $logger->$metric > 0.01 ) {
|
|
|
|
|
$non_zero = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if ( $logger->$metric ) {
|
|
|
|
|
$non_zero = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( ! $non_zero ) {
|
|
|
|
|
unset( $loggers[ $k ] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $loggers;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-25 07:36:55 -07:00
|
|
|
|
}
|