Made TransactionProfiler handle nested transactions to the same server/DB
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 1 May 2014 07:08:52 +0000 (00:08 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 1 May 2014 19:38:39 +0000 (19:38 +0000)
Change-Id: Ie4dfd4af88a9da76c76b21053bbd125c6ad3b193

includes/db/Database.php
includes/profiler/Profiler.php
includes/profiler/ProfilerStub.php

index 8288e65..f7fe980 100644 (file)
@@ -1054,7 +1054,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                # Keep track of whether the transaction has write queries pending
                if ( $this->mTrxLevel && !$this->mTrxDoneWrites && $this->isWriteQuery( $sql ) ) {
                        $this->mTrxDoneWrites = true;
-                       Profiler::instance()->transactionWritingIn( $this->mServer, $this->mDBname );
+                       $id = spl_object_hash( $this );
+                       Profiler::instance()->transactionWritingIn( $this->mServer, $this->mDBname, $id );
                }
 
                $queryProf = '';
@@ -3410,7 +3411,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        $this->runOnTransactionPreCommitCallbacks();
                        $this->doCommit( $fname );
                        if ( $this->mTrxDoneWrites ) {
-                               Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname );
+                               $id = spl_object_hash( $this );
+                               Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname, $id );
                        }
                        $this->runOnTransactionIdleCallbacks();
                }
@@ -3476,7 +3478,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                $this->runOnTransactionPreCommitCallbacks();
                $this->doCommit( $fname );
                if ( $this->mTrxDoneWrites ) {
-                       Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname );
+                       $id = spl_object_hash( $this );
+                       Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname, $id );
                }
                $this->runOnTransactionIdleCallbacks();
        }
@@ -3527,7 +3530,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                $this->mTrxPreCommitCallbacks = array(); // cancel
                $this->mTrxAtomicLevels = new SplStack;
                if ( $this->mTrxDoneWrites ) {
-                       Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname );
+                       $id = spl_object_hash( $this );
+                       Profiler::instance()->transactionWritingOut( $this->mServer, $this->mDBname, $id );
                }
        }
 
index b709498..efbdf05 100644 (file)
@@ -205,9 +205,10 @@ abstract class Profiler {
         *
         * @param string $server DB server
         * @param string $db DB name
+        * @param string $id Resource ID string of connection
         */
-       public function transactionWritingIn( $server, $db ) {
-               $this->trxProfiler->transactionWritingIn( $server, $db );
+       public function transactionWritingIn( $server, $db, $id = '' ) {
+               $this->trxProfiler->transactionWritingIn( $server, $db, $id );
        }
 
        /**
@@ -219,9 +220,10 @@ abstract class Profiler {
         *
         * @param string $server DB server
         * @param string $db DB name
+        * @param string $id Resource ID string of connection
         */
-       public function transactionWritingOut( $server, $db ) {
-               $this->trxProfiler->transactionWritingOut( $server, $db );
+       public function transactionWritingOut( $server, $db, $id = '' ) {
+               $this->trxProfiler->transactionWritingOut( $server, $db, $id );
        }
 
        /**
@@ -366,9 +368,10 @@ class TransactionProfiler {
         *
         * @param string $server DB server
         * @param string $db DB name
+        * @param string $id Resource ID string of connection
         */
-       public function transactionWritingIn( $server, $db ) {
-               $name = "{$server} ({$db})";
+       public function transactionWritingIn( $server, $db, $id ) {
+               $name = "{$server} ({$db}) ($id)";
                if ( isset( $this->mDBTrxHoldingLocks[$name] ) ) {
                        ++$this->mDBTrxHoldingLocks[$name]['refs'];
                } else {
@@ -412,9 +415,10 @@ class TransactionProfiler {
         *
         * @param string $server DB server
         * @param string $db DB name
+        * @param string $id Resource ID string of connection
         */
-       public function transactionWritingOut( $server, $db ) {
-               $name = "{$server} ({$db})";
+       public function transactionWritingOut( $server, $db, $id ) {
+               $name = "{$server} ({$db}) ($id)";
                if ( --$this->mDBTrxHoldingLocks[$name]['refs'] <= 0 ) {
                        $slow = false;
                        foreach ( $this->mDBTrxMethodTimes[$name] as $info ) {
index 7b310c1..6de97ba 100644 (file)
@@ -39,7 +39,7 @@ class ProfilerStub extends Profiler {
        public function close() {}
        public function logData() {}
        public function getCurrentSection() { return ''; }
-       public function transactionWritingIn( $server, $db ) {}
-       public function transactionWritingOut( $server, $db ) {}
+       public function transactionWritingIn( $server, $db, $id = '' ) {}
+       public function transactionWritingOut( $server, $db, $id = '' ) {}
        public function getRawData() { return array(); }
 }