diff options
author | Piotr Mrówczyński <mrow4a@yahoo.com> | 2017-04-20 11:31:00 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-04-26 13:19:43 +0200 |
commit | 9fec4031b30f5ab56af2f8c284672fcd444e8b62 (patch) | |
tree | bbecebfaa1fa8fd376b02dec9078573478fd6864 /lib/private/Diagnostics | |
parent | 5b5c3a1773dab4960d41aafc4150859a308311b7 (diff) | |
download | nextcloud-server-9fec4031b30f5ab56af2f8c284672fcd444e8b62.tar.gz nextcloud-server-9fec4031b30f5ab56af2f8c284672fcd444e8b62.zip |
Adjust query/event logging code in favour of more complex owncloud/diagnostics (#27643)
* Adjust query/event logging code in favour of more complex owncloud/diagnostics
* Add descriptions to IQueryLogger and IEventLogger interfaces
Diffstat (limited to 'lib/private/Diagnostics')
-rw-r--r-- | lib/private/Diagnostics/EventLogger.php | 39 | ||||
-rw-r--r-- | lib/private/Diagnostics/NullEventLogger.php | 58 | ||||
-rw-r--r-- | lib/private/Diagnostics/NullQueryLogger.php | 46 | ||||
-rw-r--r-- | lib/private/Diagnostics/Query.php | 9 | ||||
-rw-r--r-- | lib/private/Diagnostics/QueryLogger.php | 33 |
5 files changed, 68 insertions, 117 deletions
diff --git a/lib/private/Diagnostics/EventLogger.php b/lib/private/Diagnostics/EventLogger.php index 5abaae3f1dd..846be7efc5b 100644 --- a/lib/private/Diagnostics/EventLogger.php +++ b/lib/private/Diagnostics/EventLogger.php @@ -4,6 +4,8 @@ * * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * @author Piotr Mrowczynski <piotr@owncloud.com> * * @license AGPL-3.0 * @@ -29,28 +31,53 @@ class EventLogger implements IEventLogger { /** * @var \OC\Diagnostics\Event[] */ - private $events = array(); + private $events = []; + + /** + * @var bool - Module needs to be activated by some app + */ + private $activated = false; + /** + * @inheritdoc + */ public function start($id, $description) { - $this->events[$id] = new Event($id, $description, microtime(true)); + if ($this->activated){ + $this->events[$id] = new Event($id, $description, microtime(true)); + } } + /** + * @inheritdoc + */ public function end($id) { - if (isset($this->events[$id])) { + if ($this->activated && isset($this->events[$id])) { $timing = $this->events[$id]; $timing->end(microtime(true)); } } + /** + * @inheritdoc + */ public function log($id, $description, $start, $end) { - $this->events[$id] = new Event($id, $description, $start); - $this->events[$id]->end($end); + if ($this->activated) { + $this->events[$id] = new Event($id, $description, $start); + $this->events[$id]->end($end); + } } /** - * @return \OCP\Diagnostics\IEvent[] + * @inheritdoc */ public function getEvents() { return $this->events; } + + /** + * @inheritdoc + */ + public function activate() { + $this->activated = true; + } } diff --git a/lib/private/Diagnostics/NullEventLogger.php b/lib/private/Diagnostics/NullEventLogger.php deleted file mode 100644 index 9fe7461eb45..00000000000 --- a/lib/private/Diagnostics/NullEventLogger.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Diagnostics; - -use OCP\Diagnostics\IEventLogger; - -/** - * Dummy event logger that doesn't actually log anything - */ -class NullEventLogger implements IEventLogger { - /** - * Mark the start of an event - * - * @param $id - * @param $description - */ - public function start($id, $description) { - } - - /** - * Mark the end of an event - * - * @param $id - */ - public function end($id) { - } - - public function log($id, $description, $start, $end) { - } - - /** - * @return \OCP\Diagnostics\IEvent[] - */ - public function getEvents() { - return array(); - } -} diff --git a/lib/private/Diagnostics/NullQueryLogger.php b/lib/private/Diagnostics/NullQueryLogger.php deleted file mode 100644 index 873f556f90e..00000000000 --- a/lib/private/Diagnostics/NullQueryLogger.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OC\Diagnostics; - -use OCP\Diagnostics\IQueryLogger; - -class NullQueryLogger implements IQueryLogger { - /** - * @param string $sql - * @param array $params - * @param array $types - */ - public function startQuery($sql, array $params = null, array $types = null) { - } - - public function stopQuery() { - } - - /** - * @return \OCP\Diagnostics\IQuery[] - */ - public function getQueries() { - return array(); - } -} diff --git a/lib/private/Diagnostics/Query.php b/lib/private/Diagnostics/Query.php index 8ac2cc0eeac..7b083ed41b7 100644 --- a/lib/private/Diagnostics/Query.php +++ b/lib/private/Diagnostics/Query.php @@ -67,7 +67,14 @@ class Query implements IQuery { } /** - * @return int + * @return float + */ + public function getStart() { + return $this->start; + } + + /** + * @return float */ public function getDuration() { return $this->end - $this->start; diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php index 5f2a061a910..54ce3542f49 100644 --- a/lib/private/Diagnostics/QueryLogger.php +++ b/lib/private/Diagnostics/QueryLogger.php @@ -3,7 +3,13 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Morris Jobke <hey@morrisjobke.de> +<<<<<<< HEAD * @author Robin Appelman <robin@icewind.nl> +======= + * @author Robin Appelman <icewind@owncloud.com> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * @author Piotr Mrowczynski <piotr@owncloud.com> +>>>>>>> a5095447b7... Adjust query/event logging code in favour of more complex owncloud/diagnostics (#27643) * * @license AGPL-3.0 * @@ -46,12 +52,17 @@ class QueryLogger implements IQueryLogger { /** - * @param string $sql - * @param array $params - * @param array $types + * @var bool - Module needs to be activated by some app + */ + private $activated = false; + + /** + * @inheritdoc */ public function startQuery($sql, array $params = null, array $types = null) { - $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); + if ($this->activated) { + $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); + } } private function getStack() { @@ -62,8 +73,11 @@ class QueryLogger implements IQueryLogger { return $stack; } + /** + * @inheritdoc + */ public function stopQuery() { - if ($this->activeQuery) { + if ($this->activated && $this->activeQuery) { $this->activeQuery->end(microtime(true)); $this->queries[] = $this->activeQuery; $this->activeQuery = null; @@ -71,9 +85,16 @@ class QueryLogger implements IQueryLogger { } /** - * @return Query[] + * @inheritdoc */ public function getQueries() { return $this->queries->getData(); } + + /** + * @inheritdoc + */ + public function activate() { + $this->activated = true; + } } |