Loading core/lib/Drupal/Core/Database/Log.php +12 −7 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ class Log { * * array( * $logging_key = array( * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0), * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0), * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0, 'start' => 0), * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0, 'start' => 0), * ), * ); * Loading Loading @@ -103,14 +103,18 @@ public function end($logging_key) { /** * Log a query to all active logging keys. * * @param $statement * @param \Drupal\Core\Database\StatementInterface $statement * The prepared statement object to log. * @param $args * @param array $args * The arguments passed to the statement object. * @param $time * The time in milliseconds the query took to execute. * @param float $time * The time the query took to execute as a float (in seconds with * microsecond precision). * @param float $start * The time the query started as a float (in seconds since the Unix epoch * with microsecond precision). */ public function log(StatementInterface $statement, $args, $time) { public function log(StatementInterface $statement, $args, $time, float $start = NULL) { foreach (array_keys($this->queryLog) as $key) { $this->queryLog[$key][] = [ 'query' => $statement->getQueryString(), Loading @@ -118,6 +122,7 @@ public function log(StatementInterface $statement, $args, $time) { 'target' => $statement->dbh->getTarget(), 'caller' => $this->findCaller(), 'time' => $time, 'start' => $start, ]; } } Loading core/lib/Drupal/Core/Database/Statement.php +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public function execute($args = [], $options = []) { if (!empty($logger)) { $query_end = microtime(TRUE); $logger->log($this, $args, $query_end - $query_start); $logger->log($this, $args, $query_end - $query_start, $query_start); } return $return; Loading core/lib/Drupal/Core/Database/StatementPrefetch.php +1 −1 Original line number Diff line number Diff line Loading @@ -186,7 +186,7 @@ public function execute($args = [], $options = []) { if (!empty($logger)) { $query_end = microtime(TRUE); $logger->log($this, $args, $query_end - $query_start); $logger->log($this, $args, $query_end - $query_start, $query_start); } // Initialize the first row in $this->currentRow. Loading core/lib/Drupal/Core/Database/StatementWrapper.php +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public function execute($args = [], $options = []) { if (!empty($logger)) { $query_end = microtime(TRUE); $logger->log($this, $args, $query_end - $query_start); $logger->log($this, $args, $query_end - $query_start, $query_start); } return $return; Loading core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ class LoggingTest extends DatabaseTestBase { public function testEnableLogging() { Database::startLog('testing'); $start = microtime(TRUE); $this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol(); $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol(); Loading @@ -32,6 +33,8 @@ public function testEnableLogging() { foreach ($queries as $query) { $this->assertEqual(__FUNCTION__, $query['caller']['function'], 'Correct function in query log.'); $this->assertIsFloat($query['start']); $this->assertGreaterThanOrEqual($start, $query['start']); } } Loading Loading
core/lib/Drupal/Core/Database/Log.php +12 −7 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ class Log { * * array( * $logging_key = array( * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0), * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0), * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0, 'start' => 0), * array('query' => '', 'args' => array(), 'caller' => '', 'target' => '', 'time' => 0, 'start' => 0), * ), * ); * Loading Loading @@ -103,14 +103,18 @@ public function end($logging_key) { /** * Log a query to all active logging keys. * * @param $statement * @param \Drupal\Core\Database\StatementInterface $statement * The prepared statement object to log. * @param $args * @param array $args * The arguments passed to the statement object. * @param $time * The time in milliseconds the query took to execute. * @param float $time * The time the query took to execute as a float (in seconds with * microsecond precision). * @param float $start * The time the query started as a float (in seconds since the Unix epoch * with microsecond precision). */ public function log(StatementInterface $statement, $args, $time) { public function log(StatementInterface $statement, $args, $time, float $start = NULL) { foreach (array_keys($this->queryLog) as $key) { $this->queryLog[$key][] = [ 'query' => $statement->getQueryString(), Loading @@ -118,6 +122,7 @@ public function log(StatementInterface $statement, $args, $time) { 'target' => $statement->dbh->getTarget(), 'caller' => $this->findCaller(), 'time' => $time, 'start' => $start, ]; } } Loading
core/lib/Drupal/Core/Database/Statement.php +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public function execute($args = [], $options = []) { if (!empty($logger)) { $query_end = microtime(TRUE); $logger->log($this, $args, $query_end - $query_start); $logger->log($this, $args, $query_end - $query_start, $query_start); } return $return; Loading
core/lib/Drupal/Core/Database/StatementPrefetch.php +1 −1 Original line number Diff line number Diff line Loading @@ -186,7 +186,7 @@ public function execute($args = [], $options = []) { if (!empty($logger)) { $query_end = microtime(TRUE); $logger->log($this, $args, $query_end - $query_start); $logger->log($this, $args, $query_end - $query_start, $query_start); } // Initialize the first row in $this->currentRow. Loading
core/lib/Drupal/Core/Database/StatementWrapper.php +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ public function execute($args = [], $options = []) { if (!empty($logger)) { $query_end = microtime(TRUE); $logger->log($this, $args, $query_end - $query_start); $logger->log($this, $args, $query_end - $query_start, $query_start); } return $return; Loading
core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ class LoggingTest extends DatabaseTestBase { public function testEnableLogging() { Database::startLog('testing'); $start = microtime(TRUE); $this->connection->query('SELECT [name] FROM {test} WHERE [age] > :age', [':age' => 25])->fetchCol(); $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchCol(); Loading @@ -32,6 +33,8 @@ public function testEnableLogging() { foreach ($queries as $query) { $this->assertEqual(__FUNCTION__, $query['caller']['function'], 'Correct function in query log.'); $this->assertIsFloat($query['start']); $this->assertGreaterThanOrEqual($start, $query['start']); } } Loading