diff --git a/src/Command.php b/src/Command.php index 8e1830d..8bc4f82 100644 --- a/src/Command.php +++ b/src/Command.php @@ -565,11 +565,7 @@ class Command { // Set up profiler to track hooks and callbacks $type = null; $focus = null; - if ( $hook && $callback ) { - // When both are provided, profile all hooks to find the specific callback - $type = 'hook'; - $focus = true; - } elseif ( $hook ) { + if ( $hook ) { $type = 'hook'; $focus = $hook; } elseif ( $callback ) { @@ -585,22 +581,17 @@ class Command { if ( $hook || $callback ) { $loggers = $profiler->get_loggers(); foreach ( $loggers as $logger ) { - // Skip if filtering by callback and this logger doesn't have a callback - if ( $callback && ! isset( $logger->callback ) ) { - continue; - } - // Skip if filtering by callback and this isn't the right one if ( $callback && isset( $logger->callback ) ) { // Normalize callback for comparison - $normalized_callback = trim((string) $logger->callback); - $normalized_filter = trim($callback); + $normalized_callback = str_replace( array( '->', '::' ), '', (string) $logger->callback ); + $normalized_filter = str_replace( array( '->', '::' ), '', $callback ); if ( false === stripos( $normalized_callback, $normalized_filter ) ) { continue; } } - // Skip if filtering for a specific hook and this isn't the right one + // Skip if filtering by hook and this isn't the right one if ( $hook && isset( $logger->hook ) && $logger->hook !== $hook ) { continue; } diff --git a/src/Formatter.php b/src/Formatter.php index 7ea5ef5..d09101e 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -107,7 +107,6 @@ class Formatter { } $location_index = array_search( 'location', $fields, true ); - $non_numeric_fields = array( 'query', 'caller', 'hook', 'callback' ); foreach ( $items as $item ) { $values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) ); foreach ( $values as $i => $value ) { @@ -120,11 +119,6 @@ class Formatter { continue; } - // Ignore non-numeric fields (query, caller, hook, callback) - if ( in_array( $fields[ $i ], $non_numeric_fields, true ) ) { - continue; - } - if ( null === $totals[ $i ] ) { if ( stripos( $fields[ $i ], '_ratio' ) ) { $totals[ $i ] = array(); @@ -137,10 +131,7 @@ class Formatter { $totals[ $i ][] = $value; } } else { - // Only add numeric values to prevent warnings - if ( is_numeric( $value ) ) { - $totals[ $i ] += $value; - } + $totals[ $i ] += $value; } if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) { $values[ $i ] = round( $value, 4 ) . 's'; diff --git a/src/Logger.php b/src/Logger.php index 03c2d4e..2048cfe 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -4,9 +4,9 @@ namespace WP_CLI\Profile; class Logger { - public $time = 0; - public $query_count = 0; - public $query_time = 0; + public $time = 0; + public $query_count = 0; + public $query_time = 0; /** * @var array Array of query indices tracked during this logger's execution. */ @@ -111,7 +111,6 @@ class Logger { $this->query_offset = null; $this->cache_hit_offset = null; $this->cache_miss_offset = null; - $this->query_indices = array(); $key = array_search( $this, self::$active_loggers, true ); if ( false !== $key ) {