From 78b167b7636fa2b86ba40de55c9578f560b4e555 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sat, 20 Aug 2016 18:40:26 -0700 Subject: [PATCH] debug: Don't separately calculate query runtime It is already calculated for the transaction profiler, so re-use that. Change-Id: Ifcc43484c25e00e2409fbfb421ca2f9cecd67492 --- includes/db/Database.php | 4 +--- includes/debug/MWDebug.php | 21 +++------------------ 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 0e48d919f7..186a87bb53 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -849,8 +849,6 @@ abstract class DatabaseBase implements IDatabase { wfDebugLog( 'queries', sprintf( "%s: %s", $this->mDBname, $commentedSql ) ); } - $queryId = MWDebug::query( $sql, $fname, $isMaster ); - # Avoid fatals if close() was called $this->assertOpen(); @@ -862,7 +860,7 @@ abstract class DatabaseBase implements IDatabase { $this->getTransactionProfiler()->recordQueryCompletion( $queryProf, $startTime, $isWriteQuery, $this->affectedRows() ); - MWDebug::queryTime( $queryId ); + MWDebug::query( $sql, $fname, $isMaster, $queryRuntime ); # Try reconnecting if the connection was lost if ( false === $ret && $this->wasErrorReissuable() ) { diff --git a/includes/debug/MWDebug.php b/includes/debug/MWDebug.php index d90ef8a7d1..6ce5829388 100644 --- a/includes/debug/MWDebug.php +++ b/includes/debug/MWDebug.php @@ -347,10 +347,11 @@ class MWDebug { * @param string $sql * @param string $function * @param bool $isMaster + * @param float $runTime Query run time * @return int ID number of the query to pass to queryTime or -1 if the * debugger is disabled */ - public static function query( $sql, $function, $isMaster ) { + public static function query( $sql, $function, $isMaster, $runTime ) { if ( !self::$enabled ) { return -1; } @@ -384,28 +385,12 @@ class MWDebug { 'sql' => $sql, 'function' => $function, 'master' => (bool)$isMaster, - 'time' => 0.0, - '_start' => microtime( true ), + 'time' => $runTime, ]; return count( self::$query ) - 1; } - /** - * Calculates how long a query took. - * - * @since 1.19 - * @param int $id - */ - public static function queryTime( $id ) { - if ( $id === -1 || !self::$enabled ) { - return; - } - - self::$query[$id]['time'] = microtime( true ) - self::$query[$id]['_start']; - unset( self::$query[$id]['_start'] ); - } - /** * Returns a list of files included, along with their size * -- 2.20.1