Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311298

Change subject: Inject Profiler into Database objects
......................................................................

Inject Profiler into Database objects

* This removes the Profiler::instance() depedency.
* Also removed unused setTransactionProfiler() method

Change-Id: Iec735a130914090dc51aed30a283565a66aabee6
---
M includes/db/loadbalancer/LBFactoryMW.php
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/lbfactory/LBFactory.php
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
4 files changed, 18 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/98/311298/1

diff --git a/includes/db/loadbalancer/LBFactoryMW.php 
b/includes/db/loadbalancer/LBFactoryMW.php
index 49d0624..b36197a 100644
--- a/includes/db/loadbalancer/LBFactoryMW.php
+++ b/includes/db/loadbalancer/LBFactoryMW.php
@@ -42,6 +42,7 @@
                $defaults = [
                        'localDomain' => wfWikiID(),
                        'hostname' => wfHostname(),
+                       'profiler' => Profiler::instance(),
                        'trxProfiler' => 
Profiler::instance()->getTransactionProfiler(),
                        'replLogger' => LoggerFactory::getInstance( 
'DBReplication' ),
                        'queryLogger' => LoggerFactory::getInstance( 
'wfLogDBError' ),
diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index 9a63b7f..34b4b53 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -223,7 +223,7 @@
        /** @var int[] Prior mFlags values */
        private $priorFlags = [];
 
-       /** @var Profiler */
+       /** @var object|string Class name or object With profileIn/profileOut 
methods */
        protected $profiler;
        /** @var TransactionProfiler */
        protected $trxProfiler;
@@ -272,9 +272,7 @@
                        ? $params['srvCache']
                        : new HashBagOStuff();
 
-               $this->profiler = isset( $params['profiler'] )
-                       ? $params['profiler']
-                       : Profiler::instance(); // @TODO: remove global state
+               $this->profiler = isset( $params['profiler'] ) ? 
$params['profiler'] : null;
                $this->trxProfiler = isset( $params['trxProfiler'] )
                        ? $params['trxProfiler']
                        : new TransactionProfiler();
@@ -496,14 +494,6 @@
         */
        public function getLazyMasterHandle() {
                return $this->lazyMasterHandle;
-       }
-
-       /**
-        * @param TransactionProfiler $profiler
-        * @since 1.27
-        */
-       public function setTransactionProfiler( TransactionProfiler $profiler ) 
{
-               $this->trxProfiler = $profiler;
        }
 
        public function implicitGroupby() {
@@ -892,9 +882,13 @@
                $queryProf .= $this->mTrxShortId ? " 
[TRX#{$this->mTrxShortId}]" : "";
 
                $startTime = microtime( true );
-               $this->profiler->profileIn( $queryProf );
+               if ( $this->profiler ) {
+                       call_user_func( [ $this->profiler, 'profileIn' ], 
$queryProf );
+               }
                $ret = $this->doQuery( $commentedSql );
-               $this->profiler->profileOut( $queryProf );
+               if ( $this->profiler ) {
+                       call_user_func( [ $this->profiler, 'profileOut' ], 
$queryProf );
+               }
                $queryRuntime = max( microtime( true ) - $startTime, 0.0 );
 
                unset( $queryProfSection ); // profile out (if set)
diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php 
b/includes/libs/rdbms/lbfactory/LBFactory.php
index 49fac6a..72f2b5d 100644
--- a/includes/libs/rdbms/lbfactory/LBFactory.php
+++ b/includes/libs/rdbms/lbfactory/LBFactory.php
@@ -30,6 +30,8 @@
 abstract class LBFactory {
        /** @var ChronologyProtector */
        protected $chronProt;
+       /** @var object|string Class name or object With profileIn/profileOut 
methods */
+       protected $profiler;
        /** @var TransactionProfiler */
        protected $trxProfiler;
        /** @var LoggerInterface */
@@ -106,6 +108,8 @@
                $this->chronProt = isset( $conf['chronProt'] )
                        ? $conf['chronProt']
                        : $this->newChronologyProtector();
+
+               $this->profiler = isset( $params['profiler'] ) ? 
$params['profiler'] : null;
                $this->trxProfiler = isset( $conf['trxProfiler'] )
                        ? $conf['trxProfiler']
                        : new TransactionProfiler();
@@ -611,6 +615,7 @@
                        'readOnlyReason' => $this->readOnlyReason,
                        'srvCache' => $this->srvCache,
                        'wanCache' => $this->wanCache,
+                       'profiler' => $this->profiler,
                        'trxProfiler' => $this->trxProfiler,
                        'queryLogger' => $this->queryLogger,
                        'connLogger' => $this->connLogger,
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php 
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index 57c905f..8cd79a3 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -53,6 +53,8 @@
        private $memCache;
        /** @var WANObjectCache */
        private $wanCache;
+       /** @var object|string Class name or object With profileIn/profileOut 
methods */
+       protected $profiler;
        /** @var TransactionProfiler */
        protected $trxProfiler;
        /** @var LoggerInterface */
@@ -170,6 +172,7 @@
                } else {
                        $this->wanCache = WANObjectCache::newEmpty();
                }
+               $this->profiler = isset( $params['profiler'] ) ? 
$params['profiler'] : null;
                if ( isset( $params['trxProfiler'] ) ) {
                        $this->trxProfiler = $params['trxProfiler'];
                } else {
@@ -821,6 +824,7 @@
                // Set loggers
                $server['connLogger'] = $this->connLogger;
                $server['queryLogger'] = $this->queryLogger;
+               $server['profiler'] = $this->profiler;
                $server['trxProfiler'] = $this->trxProfiler;
                $server['cliMode'] = $this->cliMode;
                $server['errorLogger'] = $this->errorLogger;

-- 
To view, visit https://gerrit.wikimedia.org/r/311298
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec735a130914090dc51aed30a283565a66aabee6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to