Added backtraces to SQL record descriptions.
This commit is contained in:
1 parent
1e3195ffc8
commit
1f85d65b9b
1 file changed
+12
-1
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Rarst\Laps\Record;
|
namespace Rarst\Laps\Record;
|
||||||
|
|
||||||
|
use Rarst\Laps\Formatter\Backtrace_Formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes SQL events from data logged by wpdb.
|
* Processes SQL events from data logged by wpdb.
|
||||||
*/
|
*/
|
||||||
@@ -10,11 +12,16 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
|||||||
/** @var array $query_starts Log of query start times. */
|
/** @var array $query_starts Log of query start times. */
|
||||||
protected $query_starts = [];
|
protected $query_starts = [];
|
||||||
|
|
||||||
|
/** @var Backtrace_Formatter $formatter */
|
||||||
|
protected $formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the query start time log.
|
* Sets up the query start time log.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
|
||||||
|
$this->formatter = new Backtrace_Formatter();
|
||||||
|
|
||||||
if ( $this->is_savequeries() ) {
|
if ( $this->is_savequeries() ) {
|
||||||
add_filter( 'query', [ $this, 'query' ], 20 ); // TODO refactor when core provides time start data in 5.0.
|
add_filter( 'query', [ $this, 'query' ], 20 ); // TODO refactor when core provides time start data in 5.0.
|
||||||
}
|
}
|
||||||
@@ -84,6 +91,10 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
|||||||
}
|
}
|
||||||
$last_query_end = $query_start + $duration;
|
$last_query_end = $query_start + $duration;
|
||||||
|
|
||||||
return new Record( $sql, $query_start, $duration, '', $category );
|
$desc_duration = round( $duration * 1000 );
|
||||||
|
$backtrace = $this->formatter->format( $caller );
|
||||||
|
$description = $sql . ' – ' . $desc_duration . 'ms<br />' . implode( ' → ', $backtrace );
|
||||||
|
|
||||||
|
return new Record( $sql, $query_start, $duration, $description, $category );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user