Merge pull request #11416 from owncloud/eventlogger
Allow apps to gather performance diagnisticsremotes/origin/fix-10825
commit
e2ff180521
@ -0,0 +1,89 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Diagnostics; |
||||
|
||||
use OCP\Diagnostics\IEvent; |
||||
|
||||
class Event implements IEvent { |
||||
/** |
||||
* @var string |
||||
*/ |
||||
protected $id; |
||||
|
||||
/** |
||||
* @var float |
||||
*/ |
||||
protected $start; |
||||
|
||||
/** |
||||
* @var float |
||||
*/ |
||||
protected $end; |
||||
|
||||
/** |
||||
* @var string |
||||
*/ |
||||
protected $description; |
||||
|
||||
/** |
||||
* @param string $id |
||||
* @param string $description |
||||
* @param float $start |
||||
*/ |
||||
public function __construct($id, $description, $start) { |
||||
$this->id = $id; |
||||
$this->description = $description; |
||||
$this->start = $start; |
||||
} |
||||
|
||||
/** |
||||
* @param float $time |
||||
*/ |
||||
public function end($time) { |
||||
$this->end = $time; |
||||
} |
||||
|
||||
/** |
||||
* @return float |
||||
*/ |
||||
public function getStart() { |
||||
return $this->start; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function getId() { |
||||
return $this->id; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function getDescription() { |
||||
return $this->description; |
||||
} |
||||
|
||||
/** |
||||
* @return float |
||||
*/ |
||||
public function getEnd() { |
||||
return $this->end; |
||||
} |
||||
|
||||
/** |
||||
* @return float |
||||
*/ |
||||
public function getDuration() { |
||||
if (!$this->end) { |
||||
$this->end = microtime(true); |
||||
} |
||||
return $this->end - $this->start; |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Diagnostics; |
||||
|
||||
use OCP\Diagnostics\IEventLogger; |
||||
|
||||
class EventLogger implements IEventLogger { |
||||
/** |
||||
* @var \OC\Diagnostics\Event[] |
||||
*/ |
||||
private $events = array(); |
||||
|
||||
public function start($id, $description) { |
||||
$this->events[$id] = new Event($id, $description, microtime(true)); |
||||
} |
||||
|
||||
public function end($id) { |
||||
if (isset($this->events[$id])) { |
||||
$timing = $this->events[$id]; |
||||
$timing->end(microtime(true)); |
||||
} |
||||
} |
||||
|
||||
public function log($id, $description, $start, $end) { |
||||
$this->events[$id] = new Event($id, $description, $start); |
||||
$this->events[$id]->end($end); |
||||
} |
||||
|
||||
/** |
||||
* @return \OCP\Diagnostics\IEvent[] |
||||
*/ |
||||
public function getEvents() { |
||||
return $this->events; |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Diagnostics; |
||||
|
||||
use OCP\Diagnostics\IEventLogger; |
||||
|
||||
/** |
||||
* Dummy event logger that doesn't actually log anything |
||||
*/ |
||||
class 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) { |
||||
} |
||||
|
||||
public function log($id, $description, $start, $end) { |
||||
} |
||||
|
||||
/** |
||||
* @return \OCP\Diagnostics\IEvent[] |
||||
*/ |
||||
public function getEvents() { |
||||
return array(); |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Diagnostics; |
||||
|
||||
use OCP\Diagnostics\IQueryLogger; |
||||
|
||||
class 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(); |
||||
} |
||||
} |
||||
@ -0,0 +1,57 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Diagnostics; |
||||
|
||||
use OCP\Diagnostics\IQuery; |
||||
|
||||
class Query implements IQuery { |
||||
private $sql; |
||||
|
||||
private $params; |
||||
|
||||
private $start; |
||||
|
||||
private $end; |
||||
|
||||
/** |
||||
* @param string $sql |
||||
* @param array $params |
||||
* @param int $start |
||||
*/ |
||||
public function __construct($sql, $params, $start) { |
||||
$this->sql = $sql; |
||||
$this->params = $params; |
||||
$this->start = $start; |
||||
} |
||||
|
||||
public function end($time) { |
||||
$this->end = $time; |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getParams() { |
||||
return $this->params; |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function getSql() { |
||||
return $this->sql; |
||||
} |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getDuration() { |
||||
return $this->end - $this->start; |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
<?php |
||||
/** |
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> |
||||
* This file is licensed under the Affero General Public License version 3 or |
||||
* later. |
||||
* See the COPYING-README file. |
||||
*/ |
||||
|
||||
namespace OC\Diagnostics; |
||||
|
||||
use OCP\Diagnostics\IQueryLogger; |
||||
|
||||
class QueryLogger implements IQueryLogger { |
||||
/** |
||||
* @var \OC\Diagnostics\Query |
||||
*/ |
||||
protected $activeQuery; |
||||
|
||||
/** |
||||
* @var \OC\Diagnostics\Query[] |
||||
*/ |
||||
protected $queries = array(); |
||||
|
||||
/** |
||||
* @param string $sql |
||||
* @param array $params |
||||
* @param array $types |
||||
*/ |
||||
public function startQuery($sql, array $params = null, array $types = null) { |
||||
$this->activeQuery = new Query($sql, $params, microtime(true)); |
||||
} |
||||
|
||||
public function stopQuery() { |
||||
if ($this->activeQuery) { |
||||
$this->activeQuery->end(microtime(true)); |
||||
$this->queries[] = $this->activeQuery; |
||||
$this->activeQuery = null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return \OCP\Diagnostics\IQuery[] |
||||
*/ |
||||
public function getQueries() { |
||||
return $this->queries; |
||||
} |
||||
} |
||||
@ -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\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(); |
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
<?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\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); |
||||
|
||||
/** |
||||
* @param string $id |
||||
* @param string $description |
||||
* @param float $start |
||||
* @param float $end |
||||
*/ |
||||
public function log($id, $description, $start, $end); |
||||
|
||||
/** |
||||
* @return \OCP\Diagnostics\IEvent[] |
||||
*/ |
||||
public function getEvents(); |
||||
} |
||||
@ -0,0 +1,26 @@ |
||||
<?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\Diagnostics; |
||||
|
||||
interface IQuery { |
||||
/** |
||||
* @return string |
||||
*/ |
||||
public function getSql(); |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public function getParams(); |
||||
|
||||
/** |
||||
* @return float |
||||
*/ |
||||
public function getDuration(); |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?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\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(); |
||||
} |
||||
Loading…
Reference in new issue