Browse Source
Add an EventLogger interface to allow apps to get a log of the request timeline
remotes/origin/fix-10825
Add an EventLogger interface to allow apps to get a log of the request timeline
remotes/origin/fix-10825
7 changed files with 262 additions and 6 deletions
-
40lib/private/debug/dummyeventlogger.php
-
86lib/private/debug/event.php
-
36lib/private/debug/eventlogger.php
-
32lib/private/server.php
-
36lib/public/debug/ievent.php
-
31lib/public/debug/ieventlogger.php
-
7lib/public/iservercontainer.php
@ -0,0 +1,40 @@ |
|||
<?php |
|||
/** |
|||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
namespace OC\Debug; |
|||
|
|||
use OCP\Debug\IEventLogger; |
|||
|
|||
/** |
|||
* Dummy event logger that doesn't actually log anything |
|||
*/ |
|||
class DummyEventLogger implements IEventLogger { |
|||
/** |
|||
* Mark the start of an event |
|||
* |
|||
* @param $id |
|||
* @param $description |
|||
*/ |
|||
public function start($id, $description) { |
|||
} |
|||
|
|||
/** |
|||
* Mark the end of an event |
|||
* |
|||
* @param $id |
|||
*/ |
|||
public function end($id) { |
|||
} |
|||
|
|||
/** |
|||
* @return \OCP\Debug\IEvent[] |
|||
*/ |
|||
public function getEvents(){ |
|||
return array(); |
|||
} |
|||
} |
|||
@ -0,0 +1,86 @@ |
|||
<?php |
|||
/** |
|||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
namespace OC\Debug; |
|||
|
|||
use OCP\Debug\IEvent; |
|||
|
|||
class Event implements IEvent { |
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $id; |
|||
|
|||
/** |
|||
* @var float |
|||
*/ |
|||
protected $start; |
|||
|
|||
/** |
|||
* @var float |
|||
*/ |
|||
protected $end; |
|||
|
|||
/** |
|||
* @var string |
|||
*/ |
|||
protected $description; |
|||
|
|||
/** |
|||
* @param string $id |
|||
* @param string $description |
|||
* @param float $start |
|||
*/ |
|||
public function __construct($id, $description, $start) { |
|||
$this->id = $id; |
|||
$this->description = $description; |
|||
$this->start = $start; |
|||
} |
|||
|
|||
/** |
|||
* @param float $time |
|||
*/ |
|||
public function end($time) { |
|||
$this->end = $time; |
|||
} |
|||
|
|||
/** |
|||
* @return float |
|||
*/ |
|||
public function getStart() { |
|||
return $this->start; |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getId() { |
|||
return $this->id; |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getDescription() { |
|||
return $this->description; |
|||
} |
|||
|
|||
/** |
|||
* @return float |
|||
*/ |
|||
public function getEnd() { |
|||
return $this->end; |
|||
} |
|||
|
|||
/** |
|||
* @return float |
|||
*/ |
|||
public function getDuration() { |
|||
return $this->end - $this->start; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
<?php |
|||
/** |
|||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
namespace OC\Debug; |
|||
|
|||
use OCP\Debug\IEventLogger; |
|||
|
|||
class EventLogger implements IEventLogger { |
|||
/** |
|||
* @var \OC\Debug\Event[] |
|||
*/ |
|||
private $events = array(); |
|||
|
|||
public function start($id, $description) { |
|||
$this->events[$id] = new Event($id, $description, microtime(true)); |
|||
} |
|||
|
|||
public function end($id) { |
|||
if (isset($this->events[$id])) { |
|||
$timing = $this->events[$id]; |
|||
$timing->end(microtime(true)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* @return \OCP\Debug\IEvent[] |
|||
*/ |
|||
public function getEvents() { |
|||
return $this->events; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
<?php |
|||
/** |
|||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
namespace OCP\Debug; |
|||
|
|||
interface IEvent { |
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getId(); |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function getDescription(); |
|||
|
|||
/** |
|||
* @return float |
|||
*/ |
|||
public function getStart(); |
|||
|
|||
/** |
|||
* @return float |
|||
*/ |
|||
public function getEnd(); |
|||
|
|||
/** |
|||
* @return float |
|||
*/ |
|||
public function getDuration(); |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<?php |
|||
/** |
|||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
|||
* This file is licensed under the Affero General Public License version 3 or |
|||
* later. |
|||
* See the COPYING-README file. |
|||
*/ |
|||
|
|||
namespace OCP\Debug; |
|||
|
|||
interface IEventLogger { |
|||
/** |
|||
* Mark the start of an event |
|||
* |
|||
* @param string $id |
|||
* @param string $description |
|||
*/ |
|||
public function start($id, $description); |
|||
|
|||
/** |
|||
* Mark the end of an event |
|||
* |
|||
* @param string $id |
|||
*/ |
|||
public function end($id); |
|||
|
|||
/** |
|||
* @return \OCP\Debug\IEvent[] |
|||
*/ |
|||
public function getEvents(); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue