Merge "Allow wildcard searching in wiki IDs for interwiki user rights logs"
[lhc/web/wiklou.git] / includes / profiler / Profiler.php
index 677f473..779f8b6 100644 (file)
@@ -126,7 +126,7 @@ abstract class Profiler {
                        if ( is_array( $wgProfiler ) ) {
                                if ( !isset( $wgProfiler['class'] ) ) {
                                        $class = 'ProfilerStub';
-                               } elseif ( $wgProfiler['class'] === 'Profiler'  ) {
+                               } elseif ( $wgProfiler['class'] === 'Profiler' ) {
                                        $class = 'ProfilerStub'; // b/c; don't explode
                                } else {
                                        $class = $wgProfiler['class'];
@@ -357,7 +357,7 @@ abstract class Profiler {
  */
 class TransactionProfiler {
        /** @var float seconds */
-       protected $mDBLockThreshold = 5.0;
+       protected $mDBLockThreshold = 3.0;
        /** @var array DB/server name => (active trx count, time, DBs involved) */
        protected $mDBTrxHoldingLocks = array();
        /** @var array DB/server name => list of (function name, elapsed time) */
@@ -370,17 +370,17 @@ class TransactionProfiler {
         *
         * @param string $server DB server
         * @param string $db DB name
-        * @param string $id Resource ID string of connection
+        * @param string $id ID string of transaction
         */
        public function transactionWritingIn( $server, $db, $id ) {
-               $name = "{$server} ({$db}) ($id)";
+               $name = "{$server} ({$db}) (TRX#$id)";
                if ( isset( $this->mDBTrxHoldingLocks[$name] ) ) {
-                       ++$this->mDBTrxHoldingLocks[$name]['refs'];
-               } else {
-                       $this->mDBTrxHoldingLocks[$name] = array(
-                               'refs' => 1, 'start' => microtime( true ), 'conns' => array() );
-                       $this->mDBTrxMethodTimes[$name] = array();
+                       wfDebugLog( 'DBPerformance', "Nested transaction for '$name' - out of sync." );
                }
+               $this->mDBTrxHoldingLocks[$name] =
+                       array( 'start' => microtime( true ), 'conns' => array() );
+               $this->mDBTrxMethodTimes[$name] = array();
+
                foreach ( $this->mDBTrxHoldingLocks as $name => &$info ) {
                        $info['conns'][$name] = 1; // track all DBs in transactions for this transaction
                }
@@ -421,30 +421,32 @@ class TransactionProfiler {
         *
         * @param string $server DB server
         * @param string $db DB name
-        * @param string $id Resource ID string of connection
+        * @param string $id ID string of transaction
         */
        public function transactionWritingOut( $server, $db, $id ) {
-               $name = "{$server} ({$db}) ($id)";
-               if ( --$this->mDBTrxHoldingLocks[$name]['refs'] <= 0 ) {
-                       $slow = false;
-                       foreach ( $this->mDBTrxMethodTimes[$name] as $info ) {
-                               $realtime = $info[1];
-                               if ( $realtime >= $this->mDBLockThreshold ) {
-                                       $slow = true;
-                                       break;
-                               }
+               $name = "{$server} ({$db}) (TRX#$id)";
+               if ( !isset( $this->mDBTrxMethodTimes[$name] ) ) {
+                       wfDebugLog( 'DBPerformance', "Detected no transaction for '$name' - out of sync." );
+                       return;
+               }
+               $slow = false;
+               foreach ( $this->mDBTrxMethodTimes[$name] as $info ) {
+                       $realtime = $info[1];
+                       if ( $realtime >= $this->mDBLockThreshold ) {
+                               $slow = true;
+                               break;
                        }
-                       if ( $slow ) {
-                               $dbs = implode( ', ', array_keys( $this->mDBTrxHoldingLocks[$name]['conns'] ) );
-                               $msg = "Sub-optimal transaction on DB(s) [{$dbs}]:\n";
-                               foreach ( $this->mDBTrxMethodTimes[$name] as $i => $info ) {
-                                       list( $method, $realtime ) = $info;
-                                       $msg .= sprintf( "%d\t%.6f\t%s\n", $i, $realtime, $method );
-                               }
-                               wfDebugLog( 'DBPerformance', $msg );
+               }
+               if ( $slow ) {
+                       $dbs = implode( ', ', array_keys( $this->mDBTrxHoldingLocks[$name]['conns'] ) );
+                       $msg = "Sub-optimal transaction on DB(s) [{$dbs}]:\n";
+                       foreach ( $this->mDBTrxMethodTimes[$name] as $i => $info ) {
+                               list( $method, $realtime ) = $info;
+                               $msg .= sprintf( "%d\t%.6f\t%s\n", $i, $realtime, $method );
                        }
-                       unset( $this->mDBTrxHoldingLocks[$name] );
-                       unset( $this->mDBTrxMethodTimes[$name] );
+                       wfDebugLog( 'DBPerformance', $msg );
                }
+               unset( $this->mDBTrxHoldingLocks[$name] );
+               unset( $this->mDBTrxMethodTimes[$name] );
        }
 }