aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Diagnostics
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-04-19 19:29:47 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-04-19 19:29:47 +0200
commite2bff0b35d7856ec23a4279b50261faebedd655f (patch)
tree093938b8a6b368abc62c27aaaab404a15357409d /lib/private/Diagnostics
parentb441d3dcb32ef2cf2aa0e088ed320996b67e8fd5 (diff)
downloadnextcloud-server-e2bff0b35d7856ec23a4279b50261faebedd655f.tar.gz
nextcloud-server-e2bff0b35d7856ec23a4279b50261faebedd655f.zip
Move \OC\Diagnostics to PSR-4
Diffstat (limited to 'lib/private/Diagnostics')
-rw-r--r--lib/private/Diagnostics/Event.php103
-rw-r--r--lib/private/Diagnostics/EventLogger.php55
-rw-r--r--lib/private/Diagnostics/NullEventLogger.php57
-rw-r--r--lib/private/Diagnostics/NullQueryLogger.php45
-rw-r--r--lib/private/Diagnostics/Query.php71
-rw-r--r--lib/private/Diagnostics/QueryLogger.php61
6 files changed, 392 insertions, 0 deletions
diff --git a/lib/private/Diagnostics/Event.php b/lib/private/Diagnostics/Event.php
new file mode 100644
index 00000000000..8b5bb7e3bd8
--- /dev/null
+++ b/lib/private/Diagnostics/Event.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\IEvent;
+
+class Event implements IEvent {
+ /**
+ * @var string
+ */
+ protected $id;
+
+ /**
+ * @var float
+ */
+ protected $start;
+
+ /**
+ * @var float
+ */
+ protected $end;
+
+ /**
+ * @var string
+ */
+ protected $description;
+
+ /**
+ * @param string $id
+ * @param string $description
+ * @param float $start
+ */
+ public function __construct($id, $description, $start) {
+ $this->id = $id;
+ $this->description = $description;
+ $this->start = $start;
+ }
+
+ /**
+ * @param float $time
+ */
+ public function end($time) {
+ $this->end = $time;
+ }
+
+ /**
+ * @return float
+ */
+ public function getStart() {
+ return $this->start;
+ }
+
+ /**
+ * @return string
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getDescription() {
+ return $this->description;
+ }
+
+ /**
+ * @return float
+ */
+ public function getEnd() {
+ return $this->end;
+ }
+
+ /**
+ * @return float
+ */
+ public function getDuration() {
+ if (!$this->end) {
+ $this->end = microtime(true);
+ }
+ return $this->end - $this->start;
+ }
+}
diff --git a/lib/private/Diagnostics/EventLogger.php b/lib/private/Diagnostics/EventLogger.php
new file mode 100644
index 00000000000..3d909ce79cd
--- /dev/null
+++ b/lib/private/Diagnostics/EventLogger.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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;
+
+class EventLogger implements IEventLogger {
+ /**
+ * @var \OC\Diagnostics\Event[]
+ */
+ private $events = array();
+
+ public function start($id, $description) {
+ $this->events[$id] = new Event($id, $description, microtime(true));
+ }
+
+ public function end($id) {
+ if (isset($this->events[$id])) {
+ $timing = $this->events[$id];
+ $timing->end(microtime(true));
+ }
+ }
+
+ public function log($id, $description, $start, $end) {
+ $this->events[$id] = new Event($id, $description, $start);
+ $this->events[$id]->end($end);
+ }
+
+ /**
+ * @return \OCP\Diagnostics\IEvent[]
+ */
+ public function getEvents() {
+ return $this->events;
+ }
+}
diff --git a/lib/private/Diagnostics/NullEventLogger.php b/lib/private/Diagnostics/NullEventLogger.php
new file mode 100644
index 00000000000..1b5e7af3ac9
--- /dev/null
+++ b/lib/private/Diagnostics/NullEventLogger.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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
new file mode 100644
index 00000000000..98ddef2e783
--- /dev/null
+++ b/lib/private/Diagnostics/NullQueryLogger.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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
new file mode 100644
index 00000000000..567bc83ed4b
--- /dev/null
+++ b/lib/private/Diagnostics/Query.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\IQuery;
+
+class Query implements IQuery {
+ private $sql;
+
+ private $params;
+
+ private $start;
+
+ private $end;
+
+ /**
+ * @param string $sql
+ * @param array $params
+ * @param int $start
+ */
+ public function __construct($sql, $params, $start) {
+ $this->sql = $sql;
+ $this->params = $params;
+ $this->start = $start;
+ }
+
+ public function end($time) {
+ $this->end = $time;
+ }
+
+ /**
+ * @return array
+ */
+ public function getParams() {
+ return $this->params;
+ }
+
+ /**
+ * @return string
+ */
+ public function getSql() {
+ return $this->sql;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDuration() {
+ return $this->end - $this->start;
+ }
+}
diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php
new file mode 100644
index 00000000000..66a65b71d04
--- /dev/null
+++ b/lib/private/Diagnostics/QueryLogger.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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 QueryLogger implements IQueryLogger {
+ /**
+ * @var \OC\Diagnostics\Query
+ */
+ protected $activeQuery;
+
+ /**
+ * @var \OC\Diagnostics\Query[]
+ */
+ protected $queries = array();
+
+ /**
+ * @param string $sql
+ * @param array $params
+ * @param array $types
+ */
+ public function startQuery($sql, array $params = null, array $types = null) {
+ $this->activeQuery = new Query($sql, $params, microtime(true));
+ }
+
+ public function stopQuery() {
+ if ($this->activeQuery) {
+ $this->activeQuery->end(microtime(true));
+ $this->queries[] = $this->activeQuery;
+ $this->activeQuery = null;
+ }
+ }
+
+ /**
+ * @return Query[]
+ */
+ public function getQueries() {
+ return $this->queries;
+ }
+}