debug: Don't separately calculate query runtime
authorKunal Mehta <legoktm@member.fsf.org>
Sun, 21 Aug 2016 01:40:26 +0000 (18:40 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sun, 21 Aug 2016 06:43:15 +0000 (06:43 +0000)
It is already calculated for the transaction profiler, so re-use that.

Change-Id: Ifcc43484c25e00e2409fbfb421ca2f9cecd67492

includes/db/Database.php
includes/debug/MWDebug.php

index 0e48d91..186a87b 100644 (file)
@@ -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() ) {
index d90ef8a..6ce5829 100644 (file)
@@ -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
         *