summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-10-03 01:16:57 +0200
committerRobin Appelman <icewind@owncloud.com>2014-10-20 13:38:37 +0200
commitd38050cf52a623a0a4d29044bb50d3c247c8245c (patch)
treee0e64990ef04d98b8a42f94cd9fca47f3cef060c /lib
parentcb3a4d22b17ee3dd016faf52530b8f888cef5723 (diff)
downloadnextcloud-server-d38050cf52a623a0a4d29044bb50d3c247c8245c.tar.gz
nextcloud-server-d38050cf52a623a0a4d29044bb50d3c247c8245c.zip
Add an EventLogger interface to allow apps to get a log of the request timeline
Diffstat (limited to 'lib')
-rw-r--r--lib/private/debug/dummyeventlogger.php40
-rw-r--r--lib/private/debug/event.php86
-rw-r--r--lib/private/debug/eventlogger.php36
-rw-r--r--lib/private/server.php32
-rw-r--r--lib/public/debug/ievent.php36
-rw-r--r--lib/public/debug/ieventlogger.php31
-rw-r--r--lib/public/iservercontainer.php7
7 files changed, 262 insertions, 6 deletions
diff --git a/lib/private/debug/dummyeventlogger.php b/lib/private/debug/dummyeventlogger.php
new file mode 100644
index 00000000000..7aa4c21b674
--- /dev/null
+++ b/lib/private/debug/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\Debug;
+
+use OCP\Debug\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\Debug\IEvent[]
+ */
+ public function getEvents(){
+ return array();
+ }
+}
diff --git a/lib/private/debug/event.php b/lib/private/debug/event.php
new file mode 100644
index 00000000000..b03fdeabc14
--- /dev/null
+++ b/lib/private/debug/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\Debug;
+
+use OCP\Debug\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/debug/eventlogger.php b/lib/private/debug/eventlogger.php
new file mode 100644
index 00000000000..2127a624ed5
--- /dev/null
+++ b/lib/private/debug/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\Debug;
+
+use OCP\Debug\IEventLogger;
+
+class EventLogger implements IEventLogger {
+ /**
+ * @var \OC\Debug\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\Debug\IEvent[]
+ */
+ public function getEvents() {
+ return $this->events;
+ }
+}
diff --git a/lib/private/server.php b/lib/private/server.php
index d2728d2b6ef..263f9919023 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -6,12 +6,14 @@ use OC\AppFramework\Http\Request;
use OC\AppFramework\Db\Db;
use OC\AppFramework\Utility\SimpleContainer;
use OC\Cache\UserCache;
+use OC\Debug\EventLogger;
use OC\Security\CertificateManager;
use OC\DB\ConnectionWrapper;
use OC\Files\Node\Root;
use OC\Files\View;
use OC\Security\Crypto;
use OC\Security\SecureRandom;
+use OC\Debug\DummyEventLogger;
use OCP\IServerContainer;
use OCP\ISession;
use OC\Tagging\TagMapper;
@@ -24,7 +26,6 @@ use OC\Tagging\TagMapper;
* TODO: hookup all manager classes
*/
class Server extends SimpleContainer implements IServerContainer {
-
function __construct() {
$this->registerService('ContactsManager', function ($c) {
return new ContactsManager();
@@ -59,8 +60,8 @@ class Server extends SimpleContainer implements IServerContainer {
'env' => $_ENV,
'cookies' => $_COOKIE,
'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
- ? $_SERVER['REQUEST_METHOD']
- : null,
+ ? $_SERVER['REQUEST_METHOD']
+ : null,
'urlParams' => $urlParams,
'requesttoken' => $requestToken,
), $stream
@@ -208,10 +209,10 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('Search', function ($c) {
return new Search();
});
- $this->registerService('SecureRandom', function($c) {
+ $this->registerService('SecureRandom', function ($c) {
return new SecureRandom();
});
- $this->registerService('Crypto', function($c) {
+ $this->registerService('Crypto', function ($c) {
return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom());
});
$this->registerService('Db', function ($c) {
@@ -221,6 +222,13 @@ class Server extends SimpleContainer implements IServerContainer {
$config = $c->query('AllConfig');
return new HTTPHelper($config);
});
+ $this->registerService('EventLogger', function ($c) {
+ if (defined('DEBUG') and DEBUG) {
+ return new EventLogger();
+ } else {
+ return new DummyEventLogger();
+ }
+ });
}
/**
@@ -285,7 +293,7 @@ class Server extends SimpleContainer implements IServerContainer {
* @return \OCP\Files\Folder
*/
function getUserFolder($userId = null) {
- if($userId === null) {
+ if ($userId === null) {
$user = $this->getUserSession()->getUser();
if (!$user) {
return null;
@@ -528,6 +536,7 @@ class Server extends SimpleContainer implements IServerContainer {
/**
* Returns an instance of the HTTP helper class
+ *
* @return \OC\HTTPHelper
*/
function getHTTPHelper() {
@@ -559,4 +568,15 @@ class Server extends SimpleContainer implements IServerContainer {
function createEventSource() {
return new \OC_EventSource();
}
+
+ /**
+ * Get the active event logger
+ *
+ * The returned logger only logs data when debug mode is enabled
+ *
+ * @return \OCP\Debug\IEventLogger
+ */
+ function getEventLogger() {
+ return $this->query('EventLogger');
+ }
}
diff --git a/lib/public/debug/ievent.php b/lib/public/debug/ievent.php
new file mode 100644
index 00000000000..1cebb274e58
--- /dev/null
+++ b/lib/public/debug/ievent.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 OCP\Debug;
+
+interface IEvent {
+ /**
+ * @return string
+ */
+ public function getId();
+
+ /**
+ * @return string
+ */
+ public function getDescription();
+
+ /**
+ * @return float
+ */
+ public function getStart();
+
+ /**
+ * @return float
+ */
+ public function getEnd();
+
+ /**
+ * @return float
+ */
+ public function getDuration();
+}
diff --git a/lib/public/debug/ieventlogger.php b/lib/public/debug/ieventlogger.php
new file mode 100644
index 00000000000..7a7bff521db
--- /dev/null
+++ b/lib/public/debug/ieventlogger.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 OCP\Debug;
+
+interface IEventLogger {
+ /**
+ * Mark the start of an event
+ *
+ * @param string $id
+ * @param string $description
+ */
+ public function start($id, $description);
+
+ /**
+ * Mark the end of an event
+ *
+ * @param string $id
+ */
+ public function end($id);
+
+ /**
+ * @return \OCP\Debug\IEvent[]
+ */
+ public function getEvents();
+}
diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php
index a093ff3a640..57bbf628993 100644
--- a/lib/public/iservercontainer.php
+++ b/lib/public/iservercontainer.php
@@ -248,4 +248,11 @@ interface IServerContainer {
* @return \OC\HTTPHelper
*/
function getHTTPHelper();
+
+ /**
+ * Get the active event logger
+ *
+ * @return \OCP\Debug\IEventLogger
+ */
+ function getEventLogger();
}