Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to toggle query background on/off #1196

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
'backtrace' => true, // Use a backtrace to find the origin of the query in your files.
'backtrace_exclude_paths' => [], // Paths to exclude from backtrace. (in addition to defaults)
'timeline' => false, // Add the queries to the timeline
'duration_background' => true, // Show shaded background on each query relative to how long it took to execute.
'explain' => [ // Show EXPLAIN output on queries
'enabled' => false,
'types' => ['SELECT'], // Deprecated setting, is always only SELECT
Expand Down
39 changes: 26 additions & 13 deletions src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QueryCollector extends PDOCollector
protected $renderSqlWithParams = false;
protected $findSource = false;
protected $middleware = [];
protected $durationBackground = true;
protected $explainQuery = false;
protected $explainTypes = ['SELECT']; // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+
protected $showHints = false;
Expand Down Expand Up @@ -89,6 +90,16 @@ public function mergeBacktraceExcludePaths(array $excludePaths)
$this->backtraceExcludePaths = array_merge($this->backtraceExcludePaths, $excludePaths);
}

/**
* Enable/disable the shaded duration background on queries
*
* @param bool $enabled
*/
public function setDurationBackground($enabled)
{
$this->durationBackground = $enabled;
}

/**
* Enable/disable the EXPLAIN queries
*
Expand Down Expand Up @@ -493,23 +504,25 @@ public function collect()
}
}

if ($totalTime > 0) {
// For showing background measure on Queries tab
$start_percent = 0;
if ($this->durationBackground) {
if ($totalTime > 0) {
// For showing background measure on Queries tab
$start_percent = 0;

foreach ($statements as $i => $statement) {
if (! isset($statement['duration'])) {
continue;
}
foreach ($statements as $i => $statement) {
if (!isset($statement['duration'])) {
continue;
}

$width_percent = $statement['duration'] / $totalTime * 100;
$width_percent = $statement['duration'] / $totalTime * 100;

$statements[$i] = array_merge($statement, [
'start_percent' => round($start_percent, 3),
'width_percent' => round($width_percent, 3),
]);
$statements[$i] = array_merge($statement, [
'start_percent' => round($start_percent, 3),
'width_percent' => round($width_percent, 3),
]);

$start_percent += $width_percent;
$start_percent += $width_percent;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ function ($level, $message = null, $context = null) use ($logger) {
$queryCollector->mergeBacktraceExcludePaths($excludePaths);
}

$queryCollector->setDurationBackground($this->app['config']->get('debugbar.options.db.duration_background'));

if ($this->app['config']->get('debugbar.options.db.explain.enabled')) {
$types = $this->app['config']->get('debugbar.options.db.explain.types');
$queryCollector->setExplainSource(true, $types);
Expand Down