Change-Id: Id78c41623641562abe57546dfeb027fd0f437a15
$wgTitle = $title;
$trxProfiler = Profiler::instance()->getTransactionProfiler();
$wgTitle = $title;
$trxProfiler = Profiler::instance()->getTransactionProfiler();
+ $trxProfiler->setLogger( MWLoggerFactory::getInstance( 'DBPerformance' ) );
// Aside from rollback, master queries should not happen on GET requests.
// Periodic or "in passing" updates on GET should use the job queue.
// Aside from rollback, master queries should not happen on GET requests.
// Periodic or "in passing" updates on GET should use the job queue.
* @author Aaron Schulz
*/
* @author Aaron Schulz
*/
+use Psr\Log\LoggerInterface;
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\NullLogger;
/**
* Helper class that detects high-contention DB queries via profiling calls
*
/**
* Helper class that detects high-contention DB queries via profiling calls
*
-class TransactionProfiler {
+class TransactionProfiler implements LoggerAwareInterface {
/** @var float Seconds */
protected $dbLockThreshold = 3.0;
/** @var float Seconds */
/** @var float Seconds */
protected $dbLockThreshold = 3.0;
/** @var float Seconds */
/** @var array */
protected $expectBy = array();
/** @var array */
protected $expectBy = array();
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ public function __construct() {
+ $this->setLogger( new NullLogger() );
+ }
+
+ public function setLogger( LoggerInterface $logger ) {
+ $this->logger = $logger;
+ }
+
/**
* Set performance expectations
*
/**
* Set performance expectations
*
public function transactionWritingIn( $server, $db, $id ) {
$name = "{$server} ({$db}) (TRX#$id)";
if ( isset( $this->dbTrxHoldingLocks[$name] ) ) {
public function transactionWritingIn( $server, $db, $id ) {
$name = "{$server} ({$db}) (TRX#$id)";
if ( isset( $this->dbTrxHoldingLocks[$name] ) ) {
- wfDebugLog( 'DBPerformance', "Nested transaction for '$name' - out of sync." );
+ $this->logger->info( "Nested transaction for '$name' - out of sync." );
}
$this->dbTrxHoldingLocks[$name] = array(
'start' => microtime( true ),
}
$this->dbTrxHoldingLocks[$name] = array(
'start' => microtime( true ),
$elapsed = ( $eTime - $sTime );
if ( $isWrite && $n > $this->expect['maxAffected'] ) {
$elapsed = ( $eTime - $sTime );
if ( $isWrite && $n > $this->expect['maxAffected'] ) {
- wfDebugLog( 'DBPerformance',
- "Query affected $n row(s):\n" . $query . "\n" . wfBacktrace( true ) );
+ $this->logger->info( "Query affected $n row(s):\n" . $query . "\n" . wfBacktrace( true ) );
}
// Report when too many writes/queries happen...
}
// Report when too many writes/queries happen...
public function transactionWritingOut( $server, $db, $id ) {
$name = "{$server} ({$db}) (TRX#$id)";
if ( !isset( $this->dbTrxMethodTimes[$name] ) ) {
public function transactionWritingOut( $server, $db, $id ) {
$name = "{$server} ({$db}) (TRX#$id)";
if ( !isset( $this->dbTrxMethodTimes[$name] ) ) {
- wfDebugLog( 'DBPerformance', "Detected no transaction for '$name' - out of sync." );
+ $this->logger->info( "Detected no transaction for '$name' - out of sync." );
return;
}
// Fill in the last non-query period...
return;
}
// Fill in the last non-query period...
list( $query, $sTime, $end ) = $info;
$msg .= sprintf( "%d\t%.6f\t%s\n", $i, ( $end - $sTime ), $query );
}
list( $query, $sTime, $end ) = $info;
$msg .= sprintf( "%d\t%.6f\t%s\n", $i, ( $end - $sTime ), $query );
}
- wfDebugLog( 'DBPerformance', $msg );
+ $this->logger->info( $msg );
}
unset( $this->dbTrxHoldingLocks[$name] );
unset( $this->dbTrxMethodTimes[$name] );
}
unset( $this->dbTrxHoldingLocks[$name] );
unset( $this->dbTrxMethodTimes[$name] );
protected function reportExpectationViolated( $expect, $query ) {
$n = $this->expect[$expect];
$by = $this->expectBy[$expect];
protected function reportExpectationViolated( $expect, $query ) {
$n = $this->expect[$expect];
$by = $this->expectBy[$expect];
- wfDebugLog( 'DBPerformance',
- "Expectation ($expect <= $n) by $by not met:\n$query\n" . wfBacktrace( true ) );
+ $this->logger->info(
+ "Expectation ($expect <= $n) by $by not met:\n$query\n" . wfBacktrace( true )
+ );