diff options
author | Joas Schilling <coding@schilljs.com> | 2016-08-25 16:43:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-25 16:43:08 +0200 |
commit | 680d7f22bbdcc41a89a333d19ec3f55bc75dd525 (patch) | |
tree | c6265a099f8cbc7316af06f1fb4dfbbcbbce91da /lib | |
parent | 00c767f0d53742dc27a60d6fa3d855249b5f81fd (diff) | |
parent | 1c3b1e5797da8a7a398a59a353e1616ba518fc59 (diff) | |
download | nextcloud-server-680d7f22bbdcc41a89a333d19ec3f55bc75dd525.tar.gz nextcloud-server-680d7f22bbdcc41a89a333d19ec3f55bc75dd525.zip |
Merge pull request #1036 from nextcloud/query-logger-stack
add stacktrace to query logger
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Diagnostics/Query.php | 13 | ||||
-rw-r--r-- | lib/private/Diagnostics/QueryLogger.php | 10 | ||||
-rw-r--r-- | lib/public/Diagnostics/IQuery.php | 12 |
3 files changed, 33 insertions, 2 deletions
diff --git a/lib/private/Diagnostics/Query.php b/lib/private/Diagnostics/Query.php index 908ad17f9db..8ac2cc0eeac 100644 --- a/lib/private/Diagnostics/Query.php +++ b/lib/private/Diagnostics/Query.php @@ -34,15 +34,18 @@ class Query implements IQuery { private $end; + private $stack; + /** * @param string $sql * @param array $params * @param int $start */ - public function __construct($sql, $params, $start) { + public function __construct($sql, $params, $start, array $stack) { $this->sql = $sql; $this->params = $params; $this->start = $start; + $this->stack = $stack; } public function end($time) { @@ -69,4 +72,12 @@ class Query implements IQuery { public function getDuration() { return $this->end - $this->start; } + + public function getStartTime() { + return $this->start; + } + + public function getStacktrace() { + return $this->stack; + } } diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php index 5cf7e0689f8..a30f8c7b02a 100644 --- a/lib/private/Diagnostics/QueryLogger.php +++ b/lib/private/Diagnostics/QueryLogger.php @@ -42,7 +42,15 @@ class QueryLogger implements IQueryLogger { * @param array $types */ public function startQuery($sql, array $params = null, array $types = null) { - $this->activeQuery = new Query($sql, $params, microtime(true)); + $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); + } + + private function getStack() { + $stack = debug_backtrace(); + array_shift($stack); + array_shift($stack); + array_shift($stack); + return $stack; } public function stopQuery() { diff --git a/lib/public/Diagnostics/IQuery.php b/lib/public/Diagnostics/IQuery.php index 9aaf7c423b9..0bd1a6d9685 100644 --- a/lib/public/Diagnostics/IQuery.php +++ b/lib/public/Diagnostics/IQuery.php @@ -47,4 +47,16 @@ interface IQuery { * @since 8.0.0 */ public function getDuration(); + + /** + * @return float + * @since 9.2.0 + */ + public function getStartTime(); + + /** + * @return array + * @since 9.2.0 + */ + public function getStacktrace(); } |