1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-07-23 17:51:56 +02:00

Slow threshold highlight on queries (#790)

This commit is contained in:
erikn69
2025-07-21 04:20:28 -05:00
committed by GitHub
parent 0c72dd9fc5
commit 86eb2323a2
3 changed files with 27 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
protected $durationBackground = false;
protected $slowThreshold;
/**
* @param \PDO $pdo
* @param TimeDataCollector $timeCollector
@@ -55,6 +57,16 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
$this->durationBackground = $enabled;
}
/**
* Highlights queries that exceed the threshold
*
* @param int|float $threshold miliseconds value
*/
public function setSlowThreshold($threshold)
{
$this->slowThreshold = $threshold;
}
/**
* @return bool
*/
@@ -162,7 +174,8 @@ class PDOCollector extends DataCollector implements Renderable, AssetProvider
'end_memory_str' => $this->getDataFormatter()->formatBytes($stmt->getEndMemory()),
'is_success' => $stmt->isSuccess(),
'error_code' => $stmt->getErrorCode(),
'error_message' => $stmt->getErrorMessage()
'error_message' => $stmt->getErrorMessage(),
'slow' => $this->slowThreshold && $this->slowThreshold <= $stmt->getDuration()
);
if ($timeCollector !== null) {
$timeCollector->addMeasure($stmt->getSql(), $stmt->getStartTime(), $stmt->getEndTime(), array(), $connectionName);

View File

@@ -98,12 +98,20 @@ code.phpdebugbar-widgets-sql {
word-wrap: break-word;
}
div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-slow {
background-color: #ffe4e4;
}
div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-duplicate {
background-color: #F7EDED;
background-color: #fdfdcd;
}
div.phpdebugbar[data-theme='dark'] div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-slow {
background-color: #623100;
}
div.phpdebugbar[data-theme='dark'] div.phpdebugbar-widgets-sqlqueries li.phpdebugbar-widgets-list-item.phpdebugbar-widgets-sql-duplicate {
background-color: #473e00;
background-color: #565602;
}
div.phpdebugbar-widgets-sqlqueries div.phpdebugbar-widgets-toolbar {

View File

@@ -74,6 +74,9 @@
var filters = [], self = this;
this.$list = new PhpDebugBar.Widgets.ListWidget({ itemRenderer: function(li, stmt) {
if (stmt.slow) {
li.addClass(csscls('sql-slow'))
}
if (stmt.width_percent) {
$('<div />').addClass(csscls('bg-measure')).append(
$('<div />').addClass(csscls('value')).css({