From 4c2e8a8892a765c9e2ed175b6e636d7c82226b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 17:58:41 +0200 Subject: [PATCH 1/8] Helpers: Add method for find best queryTime class. --- src/Database/Helpers.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 9623a049b..f9b6ee6b3 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -299,4 +299,20 @@ public static function findDuplicates(\PDOStatement $statement): string } return implode(', ', $duplicates); } + + + public static function queryTimeClass(float $time): ?string + { + if ($time === null || $time < 5) { + return null; + } + + foreach ([500, 300, 150, 75, 15, 5] as $durationClass) { + if ($durationClass <= $time) { + return (string) $durationClass; + } + } + + return null; + } } From bdd81e7259482137b7ae30d1d70b1fed7c83201a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 17:59:26 +0200 Subject: [PATCH 2/8] ConnectionPanel: Added performance colors --- .../DatabaseTracy/templates/ConnectionPanel.panel.phtml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml index ef83eddf9..59cf3760f 100644 --- a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml +++ b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml @@ -15,6 +15,12 @@ use Tracy\Helpers; #tracy-debug td.nette-DbConnectionPanel-sql-insert { background: #E7ffE7 !important } #tracy-debug td.nette-DbConnectionPanel-sql-delete { background: #FFE7E7 !important } #tracy-debug td.nette-DbConnectionPanel-sql-update { background: #E7FBFF !important } + #tracy-debug td.nette-DbConnectionPanel-queryTime-500 { background: #f30808 !important; color: white } + #tracy-debug td.nette-DbConnectionPanel-queryTime-300 { background: #ff5f17 !important; color: white } + #tracy-debug td.nette-DbConnectionPanel-queryTime-150 { background: #fb834d !important; color: white } + #tracy-debug td.nette-DbConnectionPanel-queryTime-75 { background: #fb9567 !important; color: white } + #tracy-debug td.nette-DbConnectionPanel-queryTime-15 { background: #ffae89 !important; color: black } + #tracy-debug td.nette-DbConnectionPanel-queryTime-5 { background: #fbccb7 !important; color: black }

Queries: - + > ERROR From a6ac1ab328f6b22eab7096048b2c97aaaa11907c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 21:15:07 +0200 Subject: [PATCH 3/8] Helpers: Better function for custom performance configuration. --- src/Database/Helpers.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index f9b6ee6b3..98063bd38 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -35,6 +35,9 @@ class Helpers 'BYTEA|(TINY|MEDIUM|LONG|)BLOB|(LONG )?(VAR)?BINARY|IMAGE' => IStructure::FIELD_BINARY, ]; + /** @var int[] (millisecond => percentage) */ + public static $queryPerformanceScale = [10 => 10, 30 => 25, 50 => 50, 100 => 75, 200 => 90, 300 => 100]; + /** * Displays complete result set as HTML table for debug purposes. @@ -301,18 +304,20 @@ public static function findDuplicates(\PDOStatement $statement): string } - public static function queryTimeClass(float $time): ?string + public static function queryPerformanceOpacity(float $time): float { - if ($time === null || $time < 5) { - return null; + if ($time < (array_keys(self::$queryPerformanceScale)[0] ?? 0)) { + return 0; } - foreach ([500, 300, 150, 75, 15, 5] as $durationClass) { - if ($durationClass <= $time) { - return (string) $durationClass; + $matchedPercentage = 100; + foreach (self::$queryPerformanceScale as $timeItem => $percentage) { + if ($timeItem >= $time) { + $matchedPercentage = $percentage; + break; } } - return null; + return (($matchedPercentage + ($timeItem ?? 0)) / 2) / 100; } } From f4bcd921b89bc9effee8376e32c3e18dc80eb0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 21:15:40 +0200 Subject: [PATCH 4/8] Panel performance: Use background with opacity. --- .../DatabaseTracy/templates/ConnectionPanel.panel.phtml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml index 59cf3760f..8d980d217 100644 --- a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml +++ b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml @@ -15,12 +15,6 @@ use Tracy\Helpers; #tracy-debug td.nette-DbConnectionPanel-sql-insert { background: #E7ffE7 !important } #tracy-debug td.nette-DbConnectionPanel-sql-delete { background: #FFE7E7 !important } #tracy-debug td.nette-DbConnectionPanel-sql-update { background: #E7FBFF !important } - #tracy-debug td.nette-DbConnectionPanel-queryTime-500 { background: #f30808 !important; color: white } - #tracy-debug td.nette-DbConnectionPanel-queryTime-300 { background: #ff5f17 !important; color: white } - #tracy-debug td.nette-DbConnectionPanel-queryTime-150 { background: #fb834d !important; color: white } - #tracy-debug td.nette-DbConnectionPanel-queryTime-75 { background: #fb9567 !important; color: white } - #tracy-debug td.nette-DbConnectionPanel-queryTime-15 { background: #ffae89 !important; color: black } - #tracy-debug td.nette-DbConnectionPanel-queryTime-5 { background: #fbccb7 !important; color: black }

Queries: - > + ERROR From db5ddfe8e6dfb97b59d042534ab6a8a6959fe460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 22:29:10 +0200 Subject: [PATCH 5/8] Panel: Compute query performance by single constant. --- src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml index 8d980d217..9f04734c9 100644 --- a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml +++ b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml @@ -29,7 +29,7 @@ use Tracy\Helpers; [$connection, $sql, $params, $source, $time, $rows, $error, $command, $explain] = $query; ?> - + ERROR From a186a1a7ce39890138e5d761e4a3d68f1fe21b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 22:29:44 +0200 Subject: [PATCH 6/8] Helpers: Define only one constant $queryPerformanceScale. --- src/Database/Helpers.php | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 98063bd38..4a8507b9a 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -34,9 +34,10 @@ class Helpers '(SMALL)?DATETIME(OFFSET)?\d*|TIME(STAMP.*)?' => IStructure::FIELD_DATETIME, 'BYTEA|(TINY|MEDIUM|LONG|)BLOB|(LONG )?(VAR)?BINARY|IMAGE' => IStructure::FIELD_BINARY, ]; + - /** @var int[] (millisecond => percentage) */ - public static $queryPerformanceScale = [10 => 10, 30 => 25, 50 => 50, 100 => 75, 200 => 90, 300 => 100]; + /** @var float */ + public static $queryPerformanceScale = 0.25; /** @@ -302,22 +303,4 @@ public static function findDuplicates(\PDOStatement $statement): string } return implode(', ', $duplicates); } - - - public static function queryPerformanceOpacity(float $time): float - { - if ($time < (array_keys(self::$queryPerformanceScale)[0] ?? 0)) { - return 0; - } - - $matchedPercentage = 100; - foreach (self::$queryPerformanceScale as $timeItem => $percentage) { - if ($timeItem >= $time) { - $matchedPercentage = $percentage; - break; - } - } - - return (($matchedPercentage + ($timeItem ?? 0)) / 2) / 100; - } } From 08fd03cab95ee0a6eca9a36aa4d3e06531958250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 22:37:23 +0200 Subject: [PATCH 7/8] Helpers: Fix CS --- src/Database/Helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Helpers.php b/src/Database/Helpers.php index 4a8507b9a..a7ce75769 100644 --- a/src/Database/Helpers.php +++ b/src/Database/Helpers.php @@ -34,7 +34,7 @@ class Helpers '(SMALL)?DATETIME(OFFSET)?\d*|TIME(STAMP.*)?' => IStructure::FIELD_DATETIME, 'BYTEA|(TINY|MEDIUM|LONG|)BLOB|(LONG )?(VAR)?BINARY|IMAGE' => IStructure::FIELD_BINARY, ]; - + /** @var float */ public static $queryPerformanceScale = 0.25; From 060e65ef089c564a96d11c20fef397c81fe363fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Mon, 1 Jun 2020 22:46:17 +0200 Subject: [PATCH 8/8] Panel: Add number formatting to 3 decimals. --- src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml index 9f04734c9..5cf1e2f7f 100644 --- a/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml +++ b/src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml @@ -29,7 +29,7 @@ use Tracy\Helpers; [$connection, $sql, $params, $source, $time, $rows, $error, $command, $explain] = $query; ?> - + ERROR