From a1276fd709069e31f2ab3c33cdf06d0b80854ee7 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 19 May 2015 09:41:18 +0200 Subject: [PATCH] Benchmark all queries by default, not only db queries --- library/Icinga/Data/Db/DbConnection.php | 11 ++------- library/Icinga/Data/Db/DbQuery.php | 5 +--- library/Icinga/Data/SimpleQuery.php | 31 ++++++++++++++++++++----- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php index 9960fd491..6167a23db 100644 --- a/library/Icinga/Data/Db/DbConnection.php +++ b/library/Icinga/Data/Db/DbConnection.php @@ -6,7 +6,6 @@ namespace Icinga\Data\Db; use PDO; use Iterator; use Zend_Db; -use Icinga\Application\Benchmark; use Icinga\Data\ConfigObject; use Icinga\Data\Db\DbQuery; use Icinga\Data\Extensible; @@ -233,10 +232,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible */ public function fetchAll(DbQuery $query) { - Benchmark::measure('DB is fetching All'); - $result = $this->dbAdapter->fetchAll($query->getSelectQuery()); - Benchmark::measure('DB fetch done'); - return $result; + return $this->dbAdapter->fetchAll($query->getSelectQuery()); } /** @@ -248,10 +244,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible */ public function fetchRow(DbQuery $query) { - Benchmark::measure('DB is fetching row'); - $result = $this->dbAdapter->fetchRow($query->getSelectQuery()); - Benchmark::measure('DB row done'); - return $result; + return $this->dbAdapter->fetchRow($query->getSelectQuery()); } /** diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 1149fbeec..ee0128608 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -4,9 +4,7 @@ namespace Icinga\Data\Db; use Icinga\Data\SimpleQuery; -use Icinga\Application\Benchmark; use Icinga\Data\Filter\FilterChain; -use Icinga\Data\Filter\FilterExpression; use Icinga\Data\Filter\FilterOr; use Icinga\Data\Filter\FilterAnd; use Icinga\Data\Filter\FilterNot; @@ -296,10 +294,9 @@ class DbQuery extends SimpleQuery public function count() { if ($this->count === null) { - Benchmark::measure('DB is counting'); $this->count = parent::count(); - Benchmark::measure('DB finished count'); } + return $this->count; } diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index c2dd5c1d9..876e76b55 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -4,6 +4,7 @@ namespace Icinga\Data; use IteratorAggregate; +use Icinga\Application\Benchmark; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; @@ -357,7 +358,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate */ public function fetchAll() { - return $this->ds->fetchAll($this); + Benchmark::measure('Fetching all results started'); + $results = $this->ds->fetchAll($this); + Benchmark::measure('Fetching all results finished'); + return $results; } /** @@ -367,7 +371,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate */ public function fetchRow() { - return $this->ds->fetchRow($this); + Benchmark::measure('Fetching one row started'); + $row = $this->ds->fetchRow($this); + Benchmark::measure('Fetching one row finished'); + return $row; } /** @@ -379,7 +386,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate */ public function fetchColumn($columnIndex = 0) { - return $this->ds->fetchColumn($this, $columnIndex); + Benchmark::measure('Fetching one column started'); + $values = $this->ds->fetchColumn($this, $columnIndex); + Benchmark::measure('Fetching one column finished'); + return $values; } /** @@ -389,7 +399,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate */ public function fetchOne() { - return $this->ds->fetchOne($this); + Benchmark::measure('Fetching one value started'); + $value = $this->ds->fetchOne($this); + Benchmark::measure('Fetching one value finished'); + return $value; } /** @@ -401,7 +414,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate */ public function fetchPairs() { - return $this->ds->fetchPairs($this); + Benchmark::measure('Fetching pairs started'); + $pairs = $this->ds->fetchPairs($this); + Benchmark::measure('Fetching pairs finished'); + return $pairs; } /** @@ -413,7 +429,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate { $query = clone $this; $query->limit(0, 0); - return $this->ds->count($query); + Benchmark::measure('Counting all results started'); + $count = $this->ds->count($query); + Benchmark::measure('Counting all results finished'); + return $count; } /**