From 28bed62ae6cc1fffa47db88d8c19f31a8fe9f805 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 1 May 2014 00:08:52 -0700 Subject: [PATCH] Made TransactionProfiler handle nested transactions to the same server/DB Change-Id: Ie4dfd4af88a9da76c76b21053bbd125c6ad3b193 --- includes/db/Database.php | 12 ++++++++---- includes/profiler/Profiler.php | 20 ++++++++++++-------- includes/profiler/ProfilerStub.php | 4 ++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 8288e65201..f7fe980c95 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 ); } } diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index b709498795..efbdf05d76 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -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 ) { diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php index 7b310c1364..6de97bae25 100644 --- a/includes/profiler/ProfilerStub.php +++ b/includes/profiler/ProfilerStub.php @@ -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(); } } -- 2.20.1