Skip to content

Commit

Permalink
Merge pull request #1036 from nextcloud/query-logger-stack
Browse files Browse the repository at this point in the history
add stacktrace to query logger
  • Loading branch information
nickvergessen committed Aug 25, 2016
2 parents 00c767f + 1c3b1e5 commit 680d7f2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/private/Diagnostics/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -69,4 +72,12 @@ public function getSql() {
public function getDuration() {
return $this->end - $this->start;
}

public function getStartTime() {
return $this->start;
}

public function getStacktrace() {
return $this->stack;
}
}
10 changes: 9 additions & 1 deletion lib/private/Diagnostics/QueryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions lib/public/Diagnostics/IQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ public function getParams();
* @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();
}

0 comments on commit 680d7f2

Please sign in to comment.