mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Merge pull request #35 from runcommand/break-apart-fields
Break apart logger headers
This commit is contained in:
commit
a28bf64745
3 changed files with 47 additions and 61 deletions
|
@ -95,26 +95,39 @@ class Command {
|
|||
$fields = array(
|
||||
'hook',
|
||||
'time',
|
||||
'queries',
|
||||
'cache',
|
||||
'requests',
|
||||
'query_time',
|
||||
'query_count',
|
||||
'cache_hits',
|
||||
'cache_misses',
|
||||
'cache_ratio',
|
||||
'request_time',
|
||||
'request_count',
|
||||
);
|
||||
} else if ( $this->focus_hook ) {
|
||||
$fields = array(
|
||||
'callback',
|
||||
'time',
|
||||
'queries',
|
||||
'cache',
|
||||
'requests',
|
||||
'query_time',
|
||||
'query_count',
|
||||
'cache_hits',
|
||||
'cache_misses',
|
||||
'cache_ratio',
|
||||
'request_time',
|
||||
'request_count',
|
||||
);
|
||||
} else {
|
||||
$fields = array(
|
||||
'scope',
|
||||
'time',
|
||||
'queries',
|
||||
'cache',
|
||||
'hooks',
|
||||
'requests',
|
||||
'query_time',
|
||||
'query_count',
|
||||
'cache_hits',
|
||||
'cache_misses',
|
||||
'cache_ratio',
|
||||
'hook_time',
|
||||
'hook_count',
|
||||
'request_time',
|
||||
'request_count',
|
||||
);
|
||||
}
|
||||
$formatter = new Formatter( $assoc_args, $fields );
|
||||
|
|
|
@ -70,30 +70,11 @@ class Formatter {
|
|||
continue;
|
||||
}
|
||||
if ( ! isset( $totals[ $i ] ) ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$totals[ $i ] = array();
|
||||
} else {
|
||||
$totals[ $i ] = 0;
|
||||
}
|
||||
$totals[ $i ] = 0;
|
||||
}
|
||||
if ( is_array( $value ) ) {
|
||||
$new_value = '';
|
||||
foreach( $value as $k => $j ) {
|
||||
if ( ! isset( $totals[ $i ][ $k ] ) ) {
|
||||
$totals[ $i ][ $k ] = 0;
|
||||
}
|
||||
$totals[ $i ][ $k ] += $j;
|
||||
if ( 'time' === $k ) {
|
||||
$j = round( $j, 4 ) . 's';
|
||||
}
|
||||
$new_value .= "{$j} / ";
|
||||
}
|
||||
$values[ $i ] = rtrim( $new_value, '/ ' );
|
||||
} else {
|
||||
$totals[ $i ] += $value;
|
||||
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
|
||||
$values[ $i ] = round( $value, 4 ) . 's';
|
||||
}
|
||||
$totals[ $i ] += $value;
|
||||
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
|
||||
$values[ $i ] = round( $value, 4 ) . 's';
|
||||
}
|
||||
}
|
||||
$table->addRow( $values );
|
||||
|
|
|
@ -5,23 +5,15 @@ namespace runcommand\Profile;
|
|||
class Logger {
|
||||
|
||||
public $time = 0;
|
||||
public $queries = array(
|
||||
'count' => 0,
|
||||
'time' => 0,
|
||||
);
|
||||
public $cache = array(
|
||||
'ratio' => 0,
|
||||
'hits' => 0,
|
||||
'misses' => 0,
|
||||
);
|
||||
public $hooks = array(
|
||||
'count' => 0,
|
||||
'time' => 0,
|
||||
);
|
||||
public $requests = array(
|
||||
'count' => 0,
|
||||
'time' => 0,
|
||||
);
|
||||
public $query_count = 0;
|
||||
public $query_time = 0;
|
||||
public $cache_hits = 0;
|
||||
public $cache_misses = 0;
|
||||
public $cache_ratio = 0;
|
||||
public $hook_count = 0;
|
||||
public $hook_time = 0;
|
||||
public $request_count = 0;
|
||||
public $request_time = 0;
|
||||
|
||||
private $start_time = null;
|
||||
private $query_offset = null;
|
||||
|
@ -62,20 +54,20 @@ class Logger {
|
|||
}
|
||||
if ( ! is_null( $this->query_offset ) ) {
|
||||
for ( $i = $this->query_offset; $i < count( $wpdb->queries ); $i++ ) {
|
||||
$this->queries['time'] += $wpdb->queries[ $i ][1];
|
||||
$this->queries['count']++;
|
||||
$this->query_time += $wpdb->queries[ $i ][1];
|
||||
$this->query_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_null( $this->cache_hit_offset ) && ! is_null( $this->cache_miss_offset ) ) {
|
||||
$cache_hits = ! empty( $wp_object_cache->cache_hits ) ? $wp_object_cache->cache_hits : 0;
|
||||
$cache_misses = ! empty( $wp_object_cache->cache_misses ) ? $wp_object_cache->cache_misses : 0;
|
||||
$this->cache['hits'] = $cache_hits - $this->cache_hit_offset;
|
||||
$this->cache['misses'] = $cache_misses - $this->cache_miss_offset;
|
||||
$cache_total = $this->cache['hits'] + $this->cache['misses'];
|
||||
$this->cache_hits = $cache_hits - $this->cache_hit_offset;
|
||||
$this->cache_misses = $cache_misses - $this->cache_miss_offset;
|
||||
$cache_total = $this->cache_hits + $this->cache_misses;
|
||||
if ( $cache_total ) {
|
||||
$ratio = ( $this->cache['hits'] / $cache_total ) * 100;
|
||||
$this->cache['ratio'] = round( $ratio, 2 ) . '%';
|
||||
$ratio = ( $this->cache_hits / $cache_total ) * 100;
|
||||
$this->cache_ratio = round( $ratio, 2 ) . '%';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +84,7 @@ class Logger {
|
|||
* Start this logger's hook timer
|
||||
*/
|
||||
public function start_hook_timer() {
|
||||
$this->hooks['count']++;
|
||||
$this->hook_count++;
|
||||
// Timer already running means a subhook has been called
|
||||
if ( ! is_null( $this->hook_start_time ) ) {
|
||||
$this->hook_depth++;
|
||||
|
@ -109,7 +101,7 @@ class Logger {
|
|||
$this->hook_depth--;
|
||||
} else {
|
||||
if ( ! is_null( $this->hook_start_time ) ) {
|
||||
$this->hooks['time'] += microtime( true ) - $this->hook_start_time;
|
||||
$this->hook_time += microtime( true ) - $this->hook_start_time;
|
||||
}
|
||||
$this->hook_start_time = null;
|
||||
}
|
||||
|
@ -119,7 +111,7 @@ class Logger {
|
|||
* Start this logger's request timer
|
||||
*/
|
||||
public function start_request_timer() {
|
||||
$this->requests['count']++;
|
||||
$this->request_count++;
|
||||
$this->request_start_time = microtime( true );
|
||||
}
|
||||
|
||||
|
@ -128,7 +120,7 @@ class Logger {
|
|||
*/
|
||||
public function stop_request_timer() {
|
||||
if ( ! is_null( $this->request_start_time ) ) {
|
||||
$this->requests['time'] += microtime( true ) - $this->request_start_time;
|
||||
$this->request_time += microtime( true ) - $this->request_start_time;
|
||||
}
|
||||
$this->request_start_time = null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue