summaryrefslogtreecommitdiffstats
path: root/lib/private/diagnostics
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-10-03 20:39:09 +0200
committerRobin Appelman <icewind@owncloud.com>2014-10-20 13:38:38 +0200
commit6e08014781ea0099d7e4466dd48d80af63d8ab69 (patch)
tree393c2848c85c56faf108fb4add77ad26a3156f78 /lib/private/diagnostics
parent2790bda4f8d6452e65e28935cee62e1ab5468acf (diff)
downloadnextcloud-server-6e08014781ea0099d7e4466dd48d80af63d8ab69.tar.gz
nextcloud-server-6e08014781ea0099d7e4466dd48d80af63d8ab69.zip
Rename namespace to Diagnostics
Diffstat (limited to 'lib/private/diagnostics')
-rw-r--r--lib/private/diagnostics/dummyeventlogger.php40
-rw-r--r--lib/private/diagnostics/dummyquerylogger.php31
-rw-r--r--lib/private/diagnostics/event.php86
-rw-r--r--lib/private/diagnostics/eventlogger.php36
-rw-r--r--lib/private/diagnostics/query.php57
-rw-r--r--lib/private/diagnostics/querylogger.php47
6 files changed, 297 insertions, 0 deletions
diff --git a/lib/private/diagnostics/dummyeventlogger.php b/lib/private/diagnostics/dummyeventlogger.php
new file mode 100644
index 00000000000..f1386d2e88c
--- /dev/null
+++ b/lib/private/diagnostics/dummyeventlogger.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Diagnostics;
+
+use OCP\Diagnostics\IEventLogger;
+
+/**
+ * Dummy event logger that doesn't actually log anything
+ */
+class DummyEventLogger 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) {
+ }
+
+ /**
+ * @return \OCP\Diagnostics\IEvent[]
+ */
+ public function getEvents(){
+ return array();
+ }
+}
diff --git a/lib/private/diagnostics/dummyquerylogger.php b/lib/private/diagnostics/dummyquerylogger.php
new file mode 100644
index 00000000000..1617b204e90
--- /dev/null
+++ b/lib/private/diagnostics/dummyquerylogger.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Diagnostics;
+
+use OCP\Diagnostics\IQueryLogger;
+
+class DummyQueryLogger 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/event.php b/lib/private/diagnostics/event.php
new file mode 100644
index 00000000000..063c0c49dc2
--- /dev/null
+++ b/lib/private/diagnostics/event.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+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() {
+ 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..46084a1d496
--- /dev/null
+++ b/lib/private/diagnostics/eventlogger.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+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));
+ }
+ }
+
+ /**
+ * @return \OCP\Diagnostics\IEvent[]
+ */
+ public function getEvents() {
+ return $this->events;
+ }
+}
diff --git a/lib/private/diagnostics/query.php b/lib/private/diagnostics/query.php
new file mode 100644
index 00000000000..d50d7592636
--- /dev/null
+++ b/lib/private/diagnostics/query.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+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..1f80f907173
--- /dev/null
+++ b/lib/private/diagnostics/querylogger.php
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+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 \OCP\Diagnostics\IQuery[]
+ */
+ public function getQueries() {
+ return $this->queries;
+ }
+}