Benchmark all queries by default, not only db queries

This commit is contained in:
Johannes Meyer 2015-05-19 09:41:18 +02:00
parent 7b6ca0826b
commit a1276fd709
3 changed files with 28 additions and 19 deletions

View File

@ -6,7 +6,6 @@ namespace Icinga\Data\Db;
use PDO; use PDO;
use Iterator; use Iterator;
use Zend_Db; use Zend_Db;
use Icinga\Application\Benchmark;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Data\Db\DbQuery; use Icinga\Data\Db\DbQuery;
use Icinga\Data\Extensible; use Icinga\Data\Extensible;
@ -233,10 +232,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible
*/ */
public function fetchAll(DbQuery $query) public function fetchAll(DbQuery $query)
{ {
Benchmark::measure('DB is fetching All'); return $this->dbAdapter->fetchAll($query->getSelectQuery());
$result = $this->dbAdapter->fetchAll($query->getSelectQuery());
Benchmark::measure('DB fetch done');
return $result;
} }
/** /**
@ -248,10 +244,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible
*/ */
public function fetchRow(DbQuery $query) public function fetchRow(DbQuery $query)
{ {
Benchmark::measure('DB is fetching row'); return $this->dbAdapter->fetchRow($query->getSelectQuery());
$result = $this->dbAdapter->fetchRow($query->getSelectQuery());
Benchmark::measure('DB row done');
return $result;
} }
/** /**

View File

@ -4,9 +4,7 @@
namespace Icinga\Data\Db; namespace Icinga\Data\Db;
use Icinga\Data\SimpleQuery; use Icinga\Data\SimpleQuery;
use Icinga\Application\Benchmark;
use Icinga\Data\Filter\FilterChain; use Icinga\Data\Filter\FilterChain;
use Icinga\Data\Filter\FilterExpression;
use Icinga\Data\Filter\FilterOr; use Icinga\Data\Filter\FilterOr;
use Icinga\Data\Filter\FilterAnd; use Icinga\Data\Filter\FilterAnd;
use Icinga\Data\Filter\FilterNot; use Icinga\Data\Filter\FilterNot;
@ -296,10 +294,9 @@ class DbQuery extends SimpleQuery
public function count() public function count()
{ {
if ($this->count === null) { if ($this->count === null) {
Benchmark::measure('DB is counting');
$this->count = parent::count(); $this->count = parent::count();
Benchmark::measure('DB finished count');
} }
return $this->count; return $this->count;
} }

View File

@ -4,6 +4,7 @@
namespace Icinga\Data; namespace Icinga\Data;
use IteratorAggregate; use IteratorAggregate;
use Icinga\Application\Benchmark;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
@ -357,7 +358,10 @@ class SimpleQuery implements QueryInterface, Queryable, IteratorAggregate
*/ */
public function fetchAll() 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() 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) 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() 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() 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 = clone $this;
$query->limit(0, 0); $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;
} }
/** /**