From d38050cf52a623a0a4d29044bb50d3c247c8245c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 01:16:57 +0200 Subject: 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 00000000000..7aa4c21b674 --- /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 00000000000..b03fdeabc14 --- /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 00000000000..2127a624ed5 --- /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 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 @@ + + * 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 @@ + + * 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(); } -- cgit v1.2.3 From b71d1d3616115653eb928489093fc2581d830cf5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 01:35:07 +0200 Subject: 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 00000000000..0c2664e4001 --- /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 00000000000..351c7d9daca --- /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 00000000000..990188da975 --- /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 263f9919023..c0b94a5b4c3 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 00000000000..070c4d61196 --- /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 00000000000..fe8eae089da --- /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 57bbf628993..97ff74385a2 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(); } -- cgit v1.2.3 From 2790bda4f8d6452e65e28935cee62e1ab5468acf Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 01:36:31 +0200 Subject: 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 80163415a90..ba069977d35 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); -- cgit v1.2.3 From 6e08014781ea0099d7e4466dd48d80af63d8ab69 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 20:39:09 +0200 Subject: Rename namespace to Diagnostics --- lib/private/debug/dummyeventlogger.php | 40 ------------- lib/private/debug/dummyquerylogger.php | 31 ---------- lib/private/debug/event.php | 86 ---------------------------- lib/private/debug/eventlogger.php | 36 ------------ lib/private/debug/query.php | 57 ------------------ lib/private/debug/querylogger.php | 47 --------------- lib/private/diagnostics/dummyeventlogger.php | 40 +++++++++++++ lib/private/diagnostics/dummyquerylogger.php | 31 ++++++++++ lib/private/diagnostics/event.php | 86 ++++++++++++++++++++++++++++ lib/private/diagnostics/eventlogger.php | 36 ++++++++++++ lib/private/diagnostics/query.php | 57 ++++++++++++++++++ lib/private/diagnostics/querylogger.php | 47 +++++++++++++++ lib/private/server.php | 14 ++--- lib/public/debug/ievent.php | 36 ------------ lib/public/debug/ieventlogger.php | 31 ---------- lib/public/debug/iquery.php | 26 --------- lib/public/debug/iquerylogger.php | 27 --------- lib/public/diagnostics/ievent.php | 36 ++++++++++++ lib/public/diagnostics/ieventlogger.php | 31 ++++++++++ lib/public/diagnostics/iquery.php | 26 +++++++++ lib/public/diagnostics/iquerylogger.php | 27 +++++++++ lib/public/iservercontainer.php | 4 +- 22 files changed, 426 insertions(+), 426 deletions(-) delete mode 100644 lib/private/debug/dummyeventlogger.php delete mode 100644 lib/private/debug/dummyquerylogger.php delete mode 100644 lib/private/debug/event.php delete mode 100644 lib/private/debug/eventlogger.php delete mode 100644 lib/private/debug/query.php delete mode 100644 lib/private/debug/querylogger.php create mode 100644 lib/private/diagnostics/dummyeventlogger.php create mode 100644 lib/private/diagnostics/dummyquerylogger.php create mode 100644 lib/private/diagnostics/event.php create mode 100644 lib/private/diagnostics/eventlogger.php create mode 100644 lib/private/diagnostics/query.php create mode 100644 lib/private/diagnostics/querylogger.php delete mode 100644 lib/public/debug/ievent.php delete mode 100644 lib/public/debug/ieventlogger.php delete mode 100644 lib/public/debug/iquery.php delete mode 100644 lib/public/debug/iquerylogger.php create mode 100644 lib/public/diagnostics/ievent.php create mode 100644 lib/public/diagnostics/ieventlogger.php create mode 100644 lib/public/diagnostics/iquery.php create mode 100644 lib/public/diagnostics/iquerylogger.php diff --git a/lib/private/debug/dummyeventlogger.php b/lib/private/debug/dummyeventlogger.php deleted file mode 100644 index 7aa4c21b674..00000000000 --- a/lib/private/debug/dummyeventlogger.php +++ /dev/null @@ -1,40 +0,0 @@ - - * 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/dummyquerylogger.php b/lib/private/debug/dummyquerylogger.php deleted file mode 100644 index 0c2664e4001..00000000000 --- a/lib/private/debug/dummyquerylogger.php +++ /dev/null @@ -1,31 +0,0 @@ - - * 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/event.php b/lib/private/debug/event.php deleted file mode 100644 index b03fdeabc14..00000000000 --- a/lib/private/debug/event.php +++ /dev/null @@ -1,86 +0,0 @@ - - * 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 deleted file mode 100644 index 2127a624ed5..00000000000 --- a/lib/private/debug/eventlogger.php +++ /dev/null @@ -1,36 +0,0 @@ - - * 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/debug/query.php b/lib/private/debug/query.php deleted file mode 100644 index 351c7d9daca..00000000000 --- a/lib/private/debug/query.php +++ /dev/null @@ -1,57 +0,0 @@ - - * 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 deleted file mode 100644 index 990188da975..00000000000 --- a/lib/private/debug/querylogger.php +++ /dev/null @@ -1,47 +0,0 @@ - - * 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/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 @@ + + * 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 @@ + + * 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 @@ + + * 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 @@ + + * 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 @@ + + * 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 @@ + + * 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; + } +} diff --git a/lib/private/server.php b/lib/private/server.php index c0b94a5b4c3..7b8ed2cabf5 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/debug/ievent.php deleted file mode 100644 index 1cebb274e58..00000000000 --- a/lib/public/debug/ievent.php +++ /dev/null @@ -1,36 +0,0 @@ - - * 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 deleted file mode 100644 index 7a7bff521db..00000000000 --- a/lib/public/debug/ieventlogger.php +++ /dev/null @@ -1,31 +0,0 @@ - - * 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/debug/iquery.php b/lib/public/debug/iquery.php deleted file mode 100644 index 070c4d61196..00000000000 --- a/lib/public/debug/iquery.php +++ /dev/null @@ -1,26 +0,0 @@ - - * 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 deleted file mode 100644 index fe8eae089da..00000000000 --- a/lib/public/debug/iquerylogger.php +++ /dev/null @@ -1,27 +0,0 @@ - - * 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/diagnostics/ievent.php b/lib/public/diagnostics/ievent.php new file mode 100644 index 00000000000..a2a3461f68a --- /dev/null +++ b/lib/public/diagnostics/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\Diagnostics; + +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/diagnostics/ieventlogger.php b/lib/public/diagnostics/ieventlogger.php new file mode 100644 index 00000000000..fa5880bfea6 --- /dev/null +++ b/lib/public/diagnostics/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\Diagnostics; + +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\Diagnostics\IEvent[] + */ + public function getEvents(); +} diff --git a/lib/public/diagnostics/iquery.php b/lib/public/diagnostics/iquery.php new file mode 100644 index 00000000000..f1111e069bb --- /dev/null +++ b/lib/public/diagnostics/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\Diagnostics; + +interface IQuery { + /** + * @return string + */ + public function getSql(); + + /** + * @return array + */ + public function getParams(); + + /** + * @return float + */ + public function getDuration(); +} diff --git a/lib/public/diagnostics/iquerylogger.php b/lib/public/diagnostics/iquerylogger.php new file mode 100644 index 00000000000..0fba9eb8b10 --- /dev/null +++ b/lib/public/diagnostics/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\Diagnostics; + +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\Diagnostics\IQuery[] + */ + public function getQueries(); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 97ff74385a2..55c2c89b710 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(); } -- cgit v1.2.3 From 1e69f5e7ac3414f307aac16842655a34a2f3c709 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Oct 2014 22:13:55 +0200 Subject: 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 0086531e523..1201e46d542 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 a97db7b5e53..8fcffbad950 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 063c0c49dc2..af5d2ff8840 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 aa3d05dcb85..fd6d9939184 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 7b8ed2cabf5..496c26e2503 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 d6515872c5a..858138f58fe 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; } -- cgit v1.2.3 From 4a8358bc509ed4f7771ae68f69fafed811a7e568 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 14 Oct 2014 15:49:00 +0200 Subject: Rename to NullQueryLogger --- lib/private/diagnostics/dummyeventlogger.php | 40 ---------------------------- lib/private/diagnostics/dummyquerylogger.php | 31 --------------------- lib/private/diagnostics/nulleventlogger.php | 40 ++++++++++++++++++++++++++++ lib/private/diagnostics/nullquerylogger.php | 31 +++++++++++++++++++++ lib/private/server.php | 8 +++--- 5 files changed, 75 insertions(+), 75 deletions(-) delete mode 100644 lib/private/diagnostics/dummyeventlogger.php delete mode 100644 lib/private/diagnostics/dummyquerylogger.php create mode 100644 lib/private/diagnostics/nulleventlogger.php create mode 100644 lib/private/diagnostics/nullquerylogger.php diff --git a/lib/private/diagnostics/dummyeventlogger.php b/lib/private/diagnostics/dummyeventlogger.php deleted file mode 100644 index f1386d2e88c..00000000000 --- a/lib/private/diagnostics/dummyeventlogger.php +++ /dev/null @@ -1,40 +0,0 @@ - - * 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 deleted file mode 100644 index 1617b204e90..00000000000 --- a/lib/private/diagnostics/dummyquerylogger.php +++ /dev/null @@ -1,31 +0,0 @@ - - * 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/nulleventlogger.php b/lib/private/diagnostics/nulleventlogger.php new file mode 100644 index 00000000000..fd71ee9e110 --- /dev/null +++ b/lib/private/diagnostics/nulleventlogger.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\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) { + } + + /** + * @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..8467b4dd26c --- /dev/null +++ b/lib/private/diagnostics/nullquerylogger.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\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/server.php b/lib/private/server.php index 496c26e2503..f7ffee484ea 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(); } }); } -- cgit v1.2.3 From beb1c6ad74015a8065d0ee00c6dba24cdc699477 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 15 Oct 2014 13:14:13 +0200 Subject: 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 46084a1d496..9e557ebd304 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 fd71ee9e110..bf203cbfefd 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 fa5880bfea6..cd9f2768ca3 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[] */ -- cgit v1.2.3 From 9fd234f63f2e576c996bed69f2e9972aeff945e8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 15 Oct 2014 13:53:19 +0200 Subject: 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 1201e46d542..ef654e916ea 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 fd6d9939184..645d6141964 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 { -- cgit v1.2.3 From 2814a294c8a80b179c1087eb5a09ced555c3aca3 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 21 Oct 2014 14:10:57 +0200 Subject: 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 ef654e916ea..fd3493782ad 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'); -- cgit v1.2.3