Create a smaller chart by collapsing fields

This commit is contained in:
Daniel Bachhuber 2016-08-26 08:46:22 -07:00
parent 80cf90c427
commit aff0a95333
3 changed files with 54 additions and 22 deletions

View file

@ -119,12 +119,9 @@ class Command {
$fields = array( $fields = array(
'scope', 'scope',
'execution_time', 'execution_time',
'query_count', 'queries',
'query_time', 'hooks',
'hook_count', 'requests',
'hook_time',
'request_count',
'request_time',
); );
$data = $this->scope_log; $data = $this->scope_log;
} }

View file

@ -70,19 +70,48 @@ class Formatter {
continue; continue;
} }
if ( ! isset( $totals[ $i ] ) ) { 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; $totals[ $i ] += $value;
if ( stripos( $fields[ $i ], '_time' ) ) { if ( stripos( $fields[ $i ], '_time' ) ) {
$values[ $i ] = round( $value, 4 ) . 's'; $values[ $i ] = round( $value, 4 ) . 's';
} }
} }
}
$table->addRow( $values ); $table->addRow( $values );
} }
foreach( $totals as $i => $value ) { foreach( $totals as $i => $value ) {
if ( stripos( $fields[ $i ], '_time' ) ) { if ( stripos( $fields[ $i ], '_time' ) ) {
$totals[ $i ] = round( $value, 4 ) . 's'; $totals[ $i ] = round( $value, 4 ) . 's';
} }
if ( is_array( $value ) ) {
$new_value = '';
foreach( $value as $k => $j ) {
if ( 'time' === $k ) {
$j = round( $j, 4 ) . 's';
}
$new_value .= "{$j} / ";
}
$totals[ $i ] = rtrim( $new_value, '/ ' );
}
} }
$table->setFooters( $totals ); $table->setFooters( $totals );

View file

@ -5,12 +5,18 @@ namespace runcommand\Profile;
class Logger { class Logger {
public $execution_time = 0; public $execution_time = 0;
public $query_count = 0; public $queries = array(
public $query_time = 0; 'count' => 0,
public $hook_count = 0; 'time' => 0,
public $hook_time = 0; );
public $request_count = 0; public $hooks = array(
public $request_time = 0; 'count' => 0,
'time' => 0,
);
public $requests = array(
'count' => 0,
'time' => 0,
);
private $start_time = null; private $start_time = null;
private $query_offset = null; private $query_offset = null;
@ -47,8 +53,8 @@ class Logger {
} }
if ( ! is_null( $this->query_offset ) ) { if ( ! is_null( $this->query_offset ) ) {
for ( $i = $this->query_offset; $i < count( $wpdb->queries ); $i++ ) { for ( $i = $this->query_offset; $i < count( $wpdb->queries ); $i++ ) {
$this->query_time += $wpdb->queries[ $i ][1]; $this->queries['time'] += $wpdb->queries[ $i ][1];
$this->query_count++; $this->queries['count']++;
} }
} }
@ -67,7 +73,7 @@ class Logger {
if ( ! is_null( $this->hook_start_time ) ) { if ( ! is_null( $this->hook_start_time ) ) {
$this->hook_depth++; $this->hook_depth++;
} else { } else {
$this->hook_count++; $this->hooks['count']++;
$this->hook_start_time = microtime( true ); $this->hook_start_time = microtime( true );
} }
} }
@ -80,7 +86,7 @@ class Logger {
$this->hook_depth--; $this->hook_depth--;
} else { } else {
if ( ! is_null( $this->hook_start_time ) ) { if ( ! is_null( $this->hook_start_time ) ) {
$this->hook_time += microtime( true ) - $this->hook_start_time; $this->hooks['time'] += microtime( true ) - $this->hook_start_time;
} }
$this->hook_start_time = null; $this->hook_start_time = null;
} }
@ -90,7 +96,7 @@ class Logger {
* Start this logger's request timer * Start this logger's request timer
*/ */
public function start_request_timer() { public function start_request_timer() {
$this->request_count++; $this->requests['count']++;
$this->request_start_time = microtime( true ); $this->request_start_time = microtime( true );
} }
@ -99,7 +105,7 @@ class Logger {
*/ */
public function stop_request_timer() { public function stop_request_timer() {
if ( ! is_null( $this->request_start_time ) ) { if ( ! is_null( $this->request_start_time ) ) {
$this->request_time += microtime( true ) - $this->request_start_time; $this->requests['time'] += microtime( true ) - $this->request_start_time;
} }
$this->request_start_time = null; $this->request_start_time = null;
} }