Compare commits

..

No commits in common. "cc09ca2f50aad186af02516a1d05bf6f5871f22c" and "9e5aa60f35cc7d95e65e3a31e8fdf11f4595cb6e" have entirely different histories.

3 changed files with 8 additions and 27 deletions

View file

@ -565,11 +565,7 @@ class Command {
// Set up profiler to track hooks and callbacks // Set up profiler to track hooks and callbacks
$type = null; $type = null;
$focus = null; $focus = null;
if ( $hook && $callback ) { if ( $hook ) {
// When both are provided, profile all hooks to find the specific callback
$type = 'hook';
$focus = true;
} elseif ( $hook ) {
$type = 'hook'; $type = 'hook';
$focus = $hook; $focus = $hook;
} elseif ( $callback ) { } elseif ( $callback ) {
@ -585,22 +581,17 @@ class Command {
if ( $hook || $callback ) { if ( $hook || $callback ) {
$loggers = $profiler->get_loggers(); $loggers = $profiler->get_loggers();
foreach ( $loggers as $logger ) { 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 // Skip if filtering by callback and this isn't the right one
if ( $callback && isset( $logger->callback ) ) { if ( $callback && isset( $logger->callback ) ) {
// Normalize callback for comparison // Normalize callback for comparison
$normalized_callback = trim((string) $logger->callback); $normalized_callback = str_replace( array( '->', '::' ), '', (string) $logger->callback );
$normalized_filter = trim($callback); $normalized_filter = str_replace( array( '->', '::' ), '', $callback );
if ( false === stripos( $normalized_callback, $normalized_filter ) ) { if ( false === stripos( $normalized_callback, $normalized_filter ) ) {
continue; 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 ) { if ( $hook && isset( $logger->hook ) && $logger->hook !== $hook ) {
continue; continue;
} }

View file

@ -107,7 +107,6 @@ class Formatter {
} }


$location_index = array_search( 'location', $fields, true ); $location_index = array_search( 'location', $fields, true );
$non_numeric_fields = array( 'query', 'caller', 'hook', 'callback' );
foreach ( $items as $item ) { foreach ( $items as $item ) {
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) ); $values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
foreach ( $values as $i => $value ) { foreach ( $values as $i => $value ) {
@ -120,11 +119,6 @@ class Formatter {
continue; continue;
} }


// Ignore non-numeric fields (query, caller, hook, callback)
if ( in_array( $fields[ $i ], $non_numeric_fields, true ) ) {
continue;
}

if ( null === $totals[ $i ] ) { if ( null === $totals[ $i ] ) {
if ( stripos( $fields[ $i ], '_ratio' ) ) { if ( stripos( $fields[ $i ], '_ratio' ) ) {
$totals[ $i ] = array(); $totals[ $i ] = array();
@ -137,10 +131,7 @@ class Formatter {
$totals[ $i ][] = $value; $totals[ $i ][] = $value;
} }
} else { } else {
// Only add numeric values to prevent warnings $totals[ $i ] += $value;
if ( is_numeric( $value ) ) {
$totals[ $i ] += $value;
}
} }
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) { if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
$values[ $i ] = round( $value, 4 ) . 's'; $values[ $i ] = round( $value, 4 ) . 's';

View file

@ -4,9 +4,9 @@ namespace WP_CLI\Profile;


class Logger { class Logger {


public $time = 0; public $time = 0;
public $query_count = 0; public $query_count = 0;
public $query_time = 0; public $query_time = 0;
/** /**
* @var array Array of query indices tracked during this logger's execution. * @var array Array of query indices tracked during this logger's execution.
*/ */
@ -111,7 +111,6 @@ class Logger {
$this->query_offset = null; $this->query_offset = null;
$this->cache_hit_offset = null; $this->cache_hit_offset = null;
$this->cache_miss_offset = null; $this->cache_miss_offset = null;
$this->query_indices = array();
$key = array_search( $this, self::$active_loggers, true ); $key = array_search( $this, self::$active_loggers, true );


if ( false !== $key ) { if ( false !== $key ) {