mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-11-22 04:46:25 +08:00
Compare commits
4 commits
9e5aa60f35
...
cc09ca2f50
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc09ca2f50 | ||
|
|
1f255b9f5e | ||
|
|
28e1e4d616 | ||
|
|
ec1564a4d0 |
3 changed files with 27 additions and 8 deletions
|
|
@ -565,7 +565,11 @@ 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 ) {
|
if ( $hook && $callback ) {
|
||||||
|
// 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 ) {
|
||||||
|
|
@ -581,17 +585,22 @@ 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 = str_replace( array( '->', '::' ), '', (string) $logger->callback );
|
$normalized_callback = trim((string) $logger->callback);
|
||||||
$normalized_filter = str_replace( array( '->', '::' ), '', $callback );
|
$normalized_filter = trim($callback);
|
||||||
if ( false === stripos( $normalized_callback, $normalized_filter ) ) {
|
if ( false === stripos( $normalized_callback, $normalized_filter ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if filtering by hook and this isn't the right one
|
// Skip if filtering for a specific 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ 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 ) {
|
||||||
|
|
@ -119,6 +120,11 @@ 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();
|
||||||
|
|
@ -131,7 +137,10 @@ class Formatter {
|
||||||
$totals[ $i ][] = $value;
|
$totals[ $i ][] = $value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$totals[ $i ] += $value;
|
// Only add numeric values to prevent warnings
|
||||||
|
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';
|
||||||
|
|
|
||||||
|
|
@ -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,6 +111,7 @@ 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 ) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue