From d38050cf52a623a0a4d29044bb50d3c247c8245c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 01:16:57 +0200 Subject: [PATCH 1/9] Add an EventLogger interface to allow apps to get a log of the request timeline --- lib/private/debug/dummyeventlogger.php | 40 ++++++++++++ lib/private/debug/event.php | 86 ++++++++++++++++++++++++++ lib/private/debug/eventlogger.php | 36 +++++++++++ lib/private/server.php | 32 ++++++++-- lib/public/debug/ievent.php | 36 +++++++++++ lib/public/debug/ieventlogger.php | 31 ++++++++++ lib/public/iservercontainer.php | 7 +++ 7 files changed, 262 insertions(+), 6 deletions(-) create mode 100644 lib/private/debug/dummyeventlogger.php create mode 100644 lib/private/debug/event.php create mode 100644 lib/private/debug/eventlogger.php create mode 100644 lib/public/debug/ievent.php create mode 100644 lib/public/debug/ieventlogger.php diff --git a/lib/private/debug/dummyeventlogger.php b/lib/private/debug/dummyeventlogger.php new file mode 100644 index 0000000000..7aa4c21b67 --- /dev/null +++ b/lib/private/debug/dummyeventlogger.php @@ -0,0 +1,40 @@ + + * 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 0000000000..b03fdeabc1 --- /dev/null +++ b/lib/private/debug/event.php @@ -0,0 +1,86 @@ + + * 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 0000000000..2127a624ed --- /dev/null +++ b/lib/private/debug/eventlogger.php @@ -0,0 +1,36 @@ + + * 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 d2728d2b6e..263f991902 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 0000000000..1cebb274e5 --- /dev/null +++ b/lib/public/debug/ievent.php @@ -0,0 +1,36 @@ + + * 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 0000000000..7a7bff521d --- /dev/null +++ b/lib/public/debug/ieventlogger.php @@ -0,0 +1,31 @@ + + * 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 a093ff3a64..57bbf62899 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(); } From b71d1d3616115653eb928489093fc2581d830cf5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 01:35:07 +0200 Subject: [PATCH 2/9] Add QueryLogger interface to allow apps to get a list of used queries --- lib/private/debug/dummyquerylogger.php | 31 ++++++++++++++ lib/private/debug/query.php | 57 ++++++++++++++++++++++++++ lib/private/debug/querylogger.php | 47 +++++++++++++++++++++ lib/private/server.php | 20 +++++++++ lib/public/debug/iquery.php | 26 ++++++++++++ lib/public/debug/iquerylogger.php | 27 ++++++++++++ lib/public/iservercontainer.php | 9 ++++ 7 files changed, 217 insertions(+) create mode 100644 lib/private/debug/dummyquerylogger.php create mode 100644 lib/private/debug/query.php create mode 100644 lib/private/debug/querylogger.php create mode 100644 lib/public/debug/iquery.php create mode 100644 lib/public/debug/iquerylogger.php diff --git a/lib/private/debug/dummyquerylogger.php b/lib/private/debug/dummyquerylogger.php new file mode 100644 index 0000000000..0c2664e400 --- /dev/null +++ b/lib/private/debug/dummyquerylogger.php @@ -0,0 +1,31 @@ + + * 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\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\Debug\IQuery[] + */ + public function getQueries() { + return array(); + } +} diff --git a/lib/private/debug/query.php b/lib/private/debug/query.php new file mode 100644 index 0000000000..351c7d9dac --- /dev/null +++ b/lib/private/debug/query.php @@ -0,0 +1,57 @@ + + * 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\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/debug/querylogger.php b/lib/private/debug/querylogger.php new file mode 100644 index 0000000000..990188da97 --- /dev/null +++ b/lib/private/debug/querylogger.php @@ -0,0 +1,47 @@ + + * 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\IQueryLogger; + +class QueryLogger implements IQueryLogger { + /** + * @var \OC\Debug\Query + */ + protected $activeQuery; + + /** + * @var \OC\Debug\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\Debug\IQuery[] + */ + public function getQueries() { + return $this->queries; + } +} diff --git a/lib/private/server.php b/lib/private/server.php index 263f991902..c0b94a5b4c 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -6,7 +6,9 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Db\Db; use OC\AppFramework\Utility\SimpleContainer; use OC\Cache\UserCache; +use OC\Debug\DummyQueryLogger; use OC\Debug\EventLogger; +use OC\Debug\QueryLogger; use OC\Security\CertificateManager; use OC\DB\ConnectionWrapper; use OC\Files\Node\Root; @@ -229,6 +231,13 @@ class Server extends SimpleContainer implements IServerContainer { return new DummyEventLogger(); } }); + $this->registerService('QueryLogger', function ($c) { + if (defined('DEBUG') and DEBUG) { + return new QueryLogger(); + } else { + return new DummyQueryLogger(); + } + }); } /** @@ -579,4 +588,15 @@ class Server extends SimpleContainer implements IServerContainer { function getEventLogger() { return $this->query('EventLogger'); } + + /** + * Get the active query logger + * + * The returned logger only logs data when debug mode is enabled + * + * @return \OCP\Debug\IQueryLogger + */ + function getQueryLogger() { + return $this->query('EventLogger'); + } } diff --git a/lib/public/debug/iquery.php b/lib/public/debug/iquery.php new file mode 100644 index 0000000000..070c4d6119 --- /dev/null +++ b/lib/public/debug/iquery.php @@ -0,0 +1,26 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\Debug; + +interface IQuery { + /** + * @return string + */ + public function getSql(); + + /** + * @return array + */ + public function getParams(); + + /** + * @return float + */ + public function getDuration(); +} diff --git a/lib/public/debug/iquerylogger.php b/lib/public/debug/iquerylogger.php new file mode 100644 index 0000000000..fe8eae089d --- /dev/null +++ b/lib/public/debug/iquerylogger.php @@ -0,0 +1,27 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\Debug; + +use Doctrine\DBAL\Logging\SQLLogger; + +interface IQueryLogger extends SQLLogger { + /** + * @param string $sql + * @param array $params + * @param array $types + */ + public function startQuery($sql, array $params = null, array $types = null); + + public function stopQuery(); + + /** + * @return \OCP\Debug\IQuery[] + */ + public function getQueries(); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 57bbf62899..97ff74385a 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -255,4 +255,13 @@ interface IServerContainer { * @return \OCP\Debug\IEventLogger */ function getEventLogger(); + + /** + * Get the active query logger + * + * The returned logger only logs data when debug mode is enabled + * + * @return \OCP\Debug\IQueryLogger + */ + function getQueryLogger(); } From 2790bda4f8d6452e65e28935cee62e1ab5468acf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 01:36:31 +0200 Subject: [PATCH 3/9] Activate the query logger on connect --- lib/private/db.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/db.php b/lib/private/db.php index 80163415a9..ba069977d3 100644 --- a/lib/private/db.php +++ b/lib/private/db.php @@ -91,6 +91,7 @@ class OC_DB { try { self::$connection = $factory->getConnection($type, $connectionParams); + self::$connection->getConfiguration()->setSQLLogger(\OC::$server->getQueryLogger()); } catch(\Doctrine\DBAL\DBALException $e) { OC_Log::write('core', $e->getMessage(), OC_Log::FATAL); OC_User::setUserId(null); From 6e08014781ea0099d7e4466dd48d80af63d8ab69 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 20:39:09 +0200 Subject: [PATCH 4/9] Rename namespace to Diagnostics --- .../{debug => diagnostics}/dummyeventlogger.php | 6 +++--- .../{debug => diagnostics}/dummyquerylogger.php | 6 +++--- lib/private/{debug => diagnostics}/event.php | 4 ++-- lib/private/{debug => diagnostics}/eventlogger.php | 8 ++++---- lib/private/{debug => diagnostics}/query.php | 4 ++-- lib/private/{debug => diagnostics}/querylogger.php | 10 +++++----- lib/private/server.php | 14 +++++++------- lib/public/{debug => diagnostics}/ievent.php | 2 +- lib/public/{debug => diagnostics}/ieventlogger.php | 4 ++-- lib/public/{debug => diagnostics}/iquery.php | 2 +- lib/public/{debug => diagnostics}/iquerylogger.php | 4 ++-- lib/public/iservercontainer.php | 4 ++-- 12 files changed, 34 insertions(+), 34 deletions(-) rename lib/private/{debug => diagnostics}/dummyeventlogger.php (85%) rename lib/private/{debug => diagnostics}/dummyquerylogger.php (83%) rename lib/private/{debug => diagnostics}/event.php (95%) rename lib/private/{debug => diagnostics}/eventlogger.php (82%) rename lib/private/{debug => diagnostics}/query.php (93%) rename lib/private/{debug => diagnostics}/querylogger.php (83%) rename lib/public/{debug => diagnostics}/ievent.php (94%) rename lib/public/{debug => diagnostics}/ieventlogger.php (88%) rename lib/public/{debug => diagnostics}/iquery.php (93%) rename lib/public/{debug => diagnostics}/iquerylogger.php (88%) diff --git a/lib/private/debug/dummyeventlogger.php b/lib/private/diagnostics/dummyeventlogger.php similarity index 85% rename from lib/private/debug/dummyeventlogger.php rename to lib/private/diagnostics/dummyeventlogger.php index 7aa4c21b67..f1386d2e88 100644 --- a/lib/private/debug/dummyeventlogger.php +++ b/lib/private/diagnostics/dummyeventlogger.php @@ -6,9 +6,9 @@ * See the COPYING-README file. */ -namespace OC\Debug; +namespace OC\Diagnostics; -use OCP\Debug\IEventLogger; +use OCP\Diagnostics\IEventLogger; /** * Dummy event logger that doesn't actually log anything @@ -32,7 +32,7 @@ class DummyEventLogger implements IEventLogger { } /** - * @return \OCP\Debug\IEvent[] + * @return \OCP\Diagnostics\IEvent[] */ public function getEvents(){ return array(); diff --git a/lib/private/debug/dummyquerylogger.php b/lib/private/diagnostics/dummyquerylogger.php similarity index 83% rename from lib/private/debug/dummyquerylogger.php rename to lib/private/diagnostics/dummyquerylogger.php index 0c2664e400..1617b204e9 100644 --- a/lib/private/debug/dummyquerylogger.php +++ b/lib/private/diagnostics/dummyquerylogger.php @@ -6,9 +6,9 @@ * See the COPYING-README file. */ -namespace OC\Debug; +namespace OC\Diagnostics; -use OCP\Debug\IQueryLogger; +use OCP\Diagnostics\IQueryLogger; class DummyQueryLogger implements IQueryLogger { /** @@ -23,7 +23,7 @@ class DummyQueryLogger implements IQueryLogger { } /** - * @return \OCP\Debug\IQuery[] + * @return \OCP\Diagnostics\IQuery[] */ public function getQueries() { return array(); diff --git a/lib/private/debug/event.php b/lib/private/diagnostics/event.php similarity index 95% rename from lib/private/debug/event.php rename to lib/private/diagnostics/event.php index b03fdeabc1..063c0c49dc 100644 --- a/lib/private/debug/event.php +++ b/lib/private/diagnostics/event.php @@ -6,9 +6,9 @@ * See the COPYING-README file. */ -namespace OC\Debug; +namespace OC\Diagnostics; -use OCP\Debug\IEvent; +use OCP\Diagnostics\IEvent; class Event implements IEvent { /** diff --git a/lib/private/debug/eventlogger.php b/lib/private/diagnostics/eventlogger.php similarity index 82% rename from lib/private/debug/eventlogger.php rename to lib/private/diagnostics/eventlogger.php index 2127a624ed..46084a1d49 100644 --- a/lib/private/debug/eventlogger.php +++ b/lib/private/diagnostics/eventlogger.php @@ -6,13 +6,13 @@ * See the COPYING-README file. */ -namespace OC\Debug; +namespace OC\Diagnostics; -use OCP\Debug\IEventLogger; +use OCP\Diagnostics\IEventLogger; class EventLogger implements IEventLogger { /** - * @var \OC\Debug\Event[] + * @var \OC\Diagnostics\Event[] */ private $events = array(); @@ -28,7 +28,7 @@ class EventLogger implements IEventLogger { } /** - * @return \OCP\Debug\IEvent[] + * @return \OCP\Diagnostics\IEvent[] */ public function getEvents() { return $this->events; diff --git a/lib/private/debug/query.php b/lib/private/diagnostics/query.php similarity index 93% rename from lib/private/debug/query.php rename to lib/private/diagnostics/query.php index 351c7d9dac..d50d759263 100644 --- a/lib/private/debug/query.php +++ b/lib/private/diagnostics/query.php @@ -6,9 +6,9 @@ * See the COPYING-README file. */ -namespace OC\Debug; +namespace OC\Diagnostics; -use OCP\Debug\IQuery; +use OCP\Diagnostics\IQuery; class Query implements IQuery { private $sql; diff --git a/lib/private/debug/querylogger.php b/lib/private/diagnostics/querylogger.php similarity index 83% rename from lib/private/debug/querylogger.php rename to lib/private/diagnostics/querylogger.php index 990188da97..1f80f90717 100644 --- a/lib/private/debug/querylogger.php +++ b/lib/private/diagnostics/querylogger.php @@ -6,18 +6,18 @@ * See the COPYING-README file. */ -namespace OC\Debug; +namespace OC\Diagnostics; -use OCP\Debug\IQueryLogger; +use OCP\Diagnostics\IQueryLogger; class QueryLogger implements IQueryLogger { /** - * @var \OC\Debug\Query + * @var \OC\Diagnostics\Query */ protected $activeQuery; /** - * @var \OC\Debug\Query[] + * @var \OC\Diagnostics\Query[] */ protected $queries = array(); @@ -39,7 +39,7 @@ class QueryLogger implements IQueryLogger { } /** - * @return \OCP\Debug\IQuery[] + * @return \OCP\Diagnostics\IQuery[] */ public function getQueries() { return $this->queries; diff --git a/lib/private/server.php b/lib/private/server.php index c0b94a5b4c..7b8ed2cabf 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -6,16 +6,16 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Db\Db; use OC\AppFramework\Utility\SimpleContainer; use OC\Cache\UserCache; -use OC\Debug\DummyQueryLogger; -use OC\Debug\EventLogger; -use OC\Debug\QueryLogger; +use OC\Diagnostics\DummyQueryLogger; +use OC\Diagnostics\EventLogger; +use OC\Diagnostics\QueryLogger; 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 OC\Diagnostics\DummyEventLogger; use OCP\IServerContainer; use OCP\ISession; use OC\Tagging\TagMapper; @@ -583,7 +583,7 @@ class Server extends SimpleContainer implements IServerContainer { * * The returned logger only logs data when debug mode is enabled * - * @return \OCP\Debug\IEventLogger + * @return \OCP\Diagnostics\IEventLogger */ function getEventLogger() { return $this->query('EventLogger'); @@ -594,9 +594,9 @@ class Server extends SimpleContainer implements IServerContainer { * * The returned logger only logs data when debug mode is enabled * - * @return \OCP\Debug\IQueryLogger + * @return \OCP\Diagnostics\IQueryLogger */ function getQueryLogger() { - return $this->query('EventLogger'); + return $this->query('QueryLogger'); } } diff --git a/lib/public/debug/ievent.php b/lib/public/diagnostics/ievent.php similarity index 94% rename from lib/public/debug/ievent.php rename to lib/public/diagnostics/ievent.php index 1cebb274e5..a2a3461f68 100644 --- a/lib/public/debug/ievent.php +++ b/lib/public/diagnostics/ievent.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -namespace OCP\Debug; +namespace OCP\Diagnostics; interface IEvent { /** diff --git a/lib/public/debug/ieventlogger.php b/lib/public/diagnostics/ieventlogger.php similarity index 88% rename from lib/public/debug/ieventlogger.php rename to lib/public/diagnostics/ieventlogger.php index 7a7bff521d..fa5880bfea 100644 --- a/lib/public/debug/ieventlogger.php +++ b/lib/public/diagnostics/ieventlogger.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -namespace OCP\Debug; +namespace OCP\Diagnostics; interface IEventLogger { /** @@ -25,7 +25,7 @@ interface IEventLogger { public function end($id); /** - * @return \OCP\Debug\IEvent[] + * @return \OCP\Diagnostics\IEvent[] */ public function getEvents(); } diff --git a/lib/public/debug/iquery.php b/lib/public/diagnostics/iquery.php similarity index 93% rename from lib/public/debug/iquery.php rename to lib/public/diagnostics/iquery.php index 070c4d6119..f1111e069b 100644 --- a/lib/public/debug/iquery.php +++ b/lib/public/diagnostics/iquery.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -namespace OCP\Debug; +namespace OCP\Diagnostics; interface IQuery { /** diff --git a/lib/public/debug/iquerylogger.php b/lib/public/diagnostics/iquerylogger.php similarity index 88% rename from lib/public/debug/iquerylogger.php rename to lib/public/diagnostics/iquerylogger.php index fe8eae089d..0fba9eb8b1 100644 --- a/lib/public/debug/iquerylogger.php +++ b/lib/public/diagnostics/iquerylogger.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -namespace OCP\Debug; +namespace OCP\Diagnostics; use Doctrine\DBAL\Logging\SQLLogger; @@ -21,7 +21,7 @@ interface IQueryLogger extends SQLLogger { public function stopQuery(); /** - * @return \OCP\Debug\IQuery[] + * @return \OCP\Diagnostics\IQuery[] */ public function getQueries(); } diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 97ff74385a..55c2c89b71 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -252,7 +252,7 @@ interface IServerContainer { /** * Get the active event logger * - * @return \OCP\Debug\IEventLogger + * @return \OCP\Diagnostics\IEventLogger */ function getEventLogger(); @@ -261,7 +261,7 @@ interface IServerContainer { * * The returned logger only logs data when debug mode is enabled * - * @return \OCP\Debug\IQueryLogger + * @return \OCP\Diagnostics\IQueryLogger */ function getQueryLogger(); } From 1e69f5e7ac3414f307aac16842655a34a2f3c709 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 22:13:55 +0200 Subject: [PATCH 5/9] Log some basic events --- lib/base.php | 14 ++++++++++---- lib/private/app.php | 2 ++ lib/private/diagnostics/event.php | 3 +++ lib/private/route/router.php | 4 ++++ lib/private/server.php | 1 + lib/private/util.php | 4 ++++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/base.php b/lib/base.php index 0086531e52..1201e46d54 100644 --- a/lib/base.php +++ b/lib/base.php @@ -454,6 +454,11 @@ class OC { self::$loader->registerPrefix('Pimple', '3rdparty/Pimple'); spl_autoload_register(array(self::$loader, 'load')); + // setup the basic server + self::$server = new \OC\Server(); + self::initPaths(); + \OC::$server->getEventLogger()->start('boot', 'Initialize'); + // set some stuff //ob_start(); error_reporting(E_ALL | E_STRICT); @@ -469,7 +474,6 @@ class OC { if (get_magic_quotes_gpc() == 1) { ini_set('magic_quotes_runtime', 0); } - //try to configure php to enable big file uploads. //this doesn´t work always depending on the webserver and php configuration. //Let´s try to overwrite some defaults anyways @@ -485,9 +489,9 @@ class OC { @ini_set('file_uploads', '50'); self::handleAuthHeaders(); - self::initPaths(); self::registerAutoloaderCache(); + OC_Util::isSetLocaleWorking(); // setup 3rdparty autoloader @@ -516,9 +520,8 @@ class OC { stream_wrapper_register('quota', 'OC\Files\Stream\Quota'); stream_wrapper_register('oc', 'OC\Files\Stream\OC'); - // setup the basic server - self::$server = new \OC\Server(); + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); self::initTemplateEngine(); OC_App::loadApps(array('session')); if (self::$CLI) { @@ -526,6 +529,7 @@ class OC { } else { self::initSession(); } + \OC::$server->getEventLogger()->end('init_session'); self::checkConfig(); self::checkInstalled(); self::checkSSL(); @@ -612,6 +616,7 @@ class OC { exit(); } + \OC::$server->getEventLogger()->end('boot'); } private static function registerLocalAddressBook() { @@ -701,6 +706,7 @@ class OC { * Handle the request */ public static function handleRequest() { + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); // load all the classpaths from the enabled apps so they are available // in the routing files of each app OC::loadAppClassPaths(); diff --git a/lib/private/app.php b/lib/private/app.php index a97db7b5e5..8fcffbad95 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -89,6 +89,7 @@ class OC_App { */ public static function loadApp($app, $checkUpgrade = true) { if (is_file(self::getAppPath($app) . '/appinfo/app.php')) { + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); if ($checkUpgrade and self::shouldUpgrade($app)) { throw new \OC\NeedsUpdateException(); } @@ -100,6 +101,7 @@ class OC_App { // enabled for groups self::$enabledAppsCache = array(); } + \OC::$server->getEventLogger()->end('load_app_' . $app); } } diff --git a/lib/private/diagnostics/event.php b/lib/private/diagnostics/event.php index 063c0c49dc..af5d2ff884 100644 --- a/lib/private/diagnostics/event.php +++ b/lib/private/diagnostics/event.php @@ -81,6 +81,9 @@ class Event implements IEvent { * @return float */ public function getDuration() { + if (!$this->end) { + $this->end = microtime(true); + } return $this->end - $this->start; } } diff --git a/lib/private/route/router.php b/lib/private/route/router.php index aa3d05dcb8..fd6d993918 100644 --- a/lib/private/route/router.php +++ b/lib/private/route/router.php @@ -202,6 +202,7 @@ class Router implements IRouter { * @return void */ public function match($url) { + \OC::$server->getEventLogger()->start('load_routes', 'Load routes'); if (substr($url, 0, 6) === '/apps/') { // empty string / 'apps' / $app / rest of the route list(, , $app,) = explode('/', $url, 4); @@ -216,6 +217,7 @@ class Router implements IRouter { } else { $this->loadRoutes(); } + \OC::$server->getEventLogger()->end('load_routes'); $matcher = new UrlMatcher($this->root, $this->context); try { @@ -236,6 +238,7 @@ class Router implements IRouter { } } + \OC::$server->getEventLogger()->start('run_route', 'Run route'); if (isset($parameters['action'])) { $action = $parameters['action']; if (!is_callable($action)) { @@ -249,6 +252,7 @@ class Router implements IRouter { } else { throw new \Exception('no action available'); } + \OC::$server->getEventLogger()->end('run_route'); } /** diff --git a/lib/private/server.php b/lib/private/server.php index 7b8ed2cabf..496c26e250 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -225,6 +225,7 @@ class Server extends SimpleContainer implements IServerContainer { return new HTTPHelper($config); }); $this->registerService('EventLogger', function ($c) { + /** @var Server $c */ if (defined('DEBUG') and DEBUG) { return new EventLogger(); } else { diff --git a/lib/private/util.php b/lib/private/util.php index d6515872c5..858138f58f 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -64,6 +64,8 @@ class OC_Util { return false; } + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); + // If we are not forced to load a specific user we load the one that is logged in if ($user == "" && OC_User::isLoggedIn()) { $user = OC_User::getUser(); @@ -88,6 +90,7 @@ class OC_Util { } if ($user != '' && !OCP\User::userExists($user)) { + \OC::$server->getEventLogger()->end('setup_fs'); return false; } @@ -128,6 +131,7 @@ class OC_Util { OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); } + \OC::$server->getEventLogger()->end('setup_fs'); return true; } From 4a8358bc509ed4f7771ae68f69fafed811a7e568 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 14 Oct 2014 15:49:00 +0200 Subject: [PATCH 6/9] Rename to NullQueryLogger --- .../{dummyeventlogger.php => nulleventlogger.php} | 2 +- .../{dummyquerylogger.php => nullquerylogger.php} | 2 +- lib/private/server.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) rename lib/private/diagnostics/{dummyeventlogger.php => nulleventlogger.php} (92%) rename lib/private/diagnostics/{dummyquerylogger.php => nullquerylogger.php} (91%) diff --git a/lib/private/diagnostics/dummyeventlogger.php b/lib/private/diagnostics/nulleventlogger.php similarity index 92% rename from lib/private/diagnostics/dummyeventlogger.php rename to lib/private/diagnostics/nulleventlogger.php index f1386d2e88..fd71ee9e11 100644 --- a/lib/private/diagnostics/dummyeventlogger.php +++ b/lib/private/diagnostics/nulleventlogger.php @@ -13,7 +13,7 @@ use OCP\Diagnostics\IEventLogger; /** * Dummy event logger that doesn't actually log anything */ -class DummyEventLogger implements IEventLogger { +class NullEventLogger implements IEventLogger { /** * Mark the start of an event * diff --git a/lib/private/diagnostics/dummyquerylogger.php b/lib/private/diagnostics/nullquerylogger.php similarity index 91% rename from lib/private/diagnostics/dummyquerylogger.php rename to lib/private/diagnostics/nullquerylogger.php index 1617b204e9..8467b4dd26 100644 --- a/lib/private/diagnostics/dummyquerylogger.php +++ b/lib/private/diagnostics/nullquerylogger.php @@ -10,7 +10,7 @@ namespace OC\Diagnostics; use OCP\Diagnostics\IQueryLogger; -class DummyQueryLogger implements IQueryLogger { +class NullQueryLogger implements IQueryLogger { /** * @param string $sql * @param array $params diff --git a/lib/private/server.php b/lib/private/server.php index 496c26e250..f7ffee484e 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -6,7 +6,7 @@ use OC\AppFramework\Http\Request; use OC\AppFramework\Db\Db; use OC\AppFramework\Utility\SimpleContainer; use OC\Cache\UserCache; -use OC\Diagnostics\DummyQueryLogger; +use OC\Diagnostics\NullQueryLogger; use OC\Diagnostics\EventLogger; use OC\Diagnostics\QueryLogger; use OC\Security\CertificateManager; @@ -15,7 +15,7 @@ use OC\Files\Node\Root; use OC\Files\View; use OC\Security\Crypto; use OC\Security\SecureRandom; -use OC\Diagnostics\DummyEventLogger; +use OC\Diagnostics\NullEventLogger; use OCP\IServerContainer; use OCP\ISession; use OC\Tagging\TagMapper; @@ -229,14 +229,14 @@ class Server extends SimpleContainer implements IServerContainer { if (defined('DEBUG') and DEBUG) { return new EventLogger(); } else { - return new DummyEventLogger(); + return new NullEventLogger(); } }); $this->registerService('QueryLogger', function ($c) { if (defined('DEBUG') and DEBUG) { return new QueryLogger(); } else { - return new DummyQueryLogger(); + return new NullQueryLogger(); } }); } From beb1c6ad74015a8065d0ee00c6dba24cdc699477 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 15 Oct 2014 13:14:13 +0200 Subject: [PATCH 7/9] Allow adding events that hapend before the event logger was loaded --- lib/private/diagnostics/eventlogger.php | 5 +++++ lib/private/diagnostics/nulleventlogger.php | 5 ++++- lib/public/diagnostics/ieventlogger.php | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/private/diagnostics/eventlogger.php b/lib/private/diagnostics/eventlogger.php index 46084a1d49..9e557ebd30 100644 --- a/lib/private/diagnostics/eventlogger.php +++ b/lib/private/diagnostics/eventlogger.php @@ -27,6 +27,11 @@ class EventLogger implements IEventLogger { } } + public function log($id, $description, $start, $end) { + $this->events[$id] = new Event($id, $description, $start); + $this->events[$id]->end($end); + } + /** * @return \OCP\Diagnostics\IEvent[] */ diff --git a/lib/private/diagnostics/nulleventlogger.php b/lib/private/diagnostics/nulleventlogger.php index fd71ee9e11..bf203cbfef 100644 --- a/lib/private/diagnostics/nulleventlogger.php +++ b/lib/private/diagnostics/nulleventlogger.php @@ -31,10 +31,13 @@ class NullEventLogger implements IEventLogger { public function end($id) { } + public function log($id, $description, $start, $end) { + } + /** * @return \OCP\Diagnostics\IEvent[] */ - public function getEvents(){ + public function getEvents() { return array(); } } diff --git a/lib/public/diagnostics/ieventlogger.php b/lib/public/diagnostics/ieventlogger.php index fa5880bfea..cd9f2768ca 100644 --- a/lib/public/diagnostics/ieventlogger.php +++ b/lib/public/diagnostics/ieventlogger.php @@ -24,6 +24,14 @@ interface IEventLogger { */ public function end($id); + /** + * @param string $id + * @param string $description + * @param float $start + * @param float $end + */ + public function log($id, $description, $start, $end); + /** * @return \OCP\Diagnostics\IEvent[] */ From 9fd234f63f2e576c996bed69f2e9972aeff945e8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 15 Oct 2014 13:53:19 +0200 Subject: [PATCH 8/9] Log some additional events --- lib/base.php | 3 +++ lib/private/route/router.php | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/base.php b/lib/base.php index 1201e46d54..ef654e916e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -444,6 +444,7 @@ class OC { public static function init() { // register autoloader + $loaderStart = microtime(true); require_once __DIR__ . '/autoloader.php'; self::$loader = new \OC\Autoloader(); self::$loader->registerPrefix('Doctrine\\Common', 'doctrine/common/lib'); @@ -453,10 +454,12 @@ class OC { self::$loader->registerPrefix('Patchwork', '3rdparty'); self::$loader->registerPrefix('Pimple', '3rdparty/Pimple'); spl_autoload_register(array(self::$loader, 'load')); + $loaderEnd = microtime(true); // setup the basic server self::$server = new \OC\Server(); self::initPaths(); + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); \OC::$server->getEventLogger()->start('boot', 'Initialize'); // set some stuff diff --git a/lib/private/route/router.php b/lib/private/route/router.php index fd6d993918..645d614196 100644 --- a/lib/private/route/router.php +++ b/lib/private/route/router.php @@ -106,6 +106,7 @@ class Router implements IRouter { * @return void */ public function loadRoutes($app = null) { + $requestedApp = $app; if ($this->loaded) { return; } @@ -123,6 +124,7 @@ class Router implements IRouter { $routingFiles = array(); } } + \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes'); foreach ($routingFiles as $app => $file) { if (!isset($this->loadedApps[$app])) { $this->loadedApps[$app] = true; @@ -145,6 +147,7 @@ class Router implements IRouter { $collection->addPrefix('/ocs'); $this->root->addCollection($collection); } + \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); } /** @@ -202,7 +205,6 @@ class Router implements IRouter { * @return void */ public function match($url) { - \OC::$server->getEventLogger()->start('load_routes', 'Load routes'); if (substr($url, 0, 6) === '/apps/') { // empty string / 'apps' / $app / rest of the route list(, , $app,) = explode('/', $url, 4); @@ -217,7 +219,6 @@ class Router implements IRouter { } else { $this->loadRoutes(); } - \OC::$server->getEventLogger()->end('load_routes'); $matcher = new UrlMatcher($this->root, $this->context); try { From 2814a294c8a80b179c1087eb5a09ced555c3aca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 21 Oct 2014 14:10:57 +0200 Subject: [PATCH 9/9] call initPaths() right before the server is instantiated --- lib/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base.php b/lib/base.php index ef654e916e..fd3493782a 100644 --- a/lib/base.php +++ b/lib/base.php @@ -457,8 +457,8 @@ class OC { $loaderEnd = microtime(true); // setup the basic server - self::$server = new \OC\Server(); self::initPaths(); + self::$server = new \OC\Server(); \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); \OC::$server->getEventLogger()->start('boot', 'Initialize');