MediaWiki  1.27.2
TransactionProfiler Class Reference

Helper class that detects high-contention DB queries via profiling calls. More...

Inheritance diagram for TransactionProfiler:
Collaboration diagram for TransactionProfiler:

Public Member Functions

 __construct ()
 
 recordConnection ($server, $db, $isMaster)
 Mark a DB as having been connected to with a new handle. More...
 
 recordQueryCompletion ($query, $sTime, $isWrite=false, $n=0)
 Register the name and time of a method for slow DB trx detection. More...
 
 resetExpectations ()
 Reset performance expectations and hit counters. More...
 
 setExpectation ($event, $value, $fname)
 Set performance expectations. More...
 
 setExpectations (array $expects, $fname)
 Set multiple performance expectations. More...
 
 setLogger (LoggerInterface $logger)
 
 transactionWritingIn ($server, $db, $id)
 Mark a DB as in a transaction with one or more writes pending. More...
 
 transactionWritingOut ($server, $db, $id, $writeTime=0.0)
 Mark a DB as no longer in a transaction. More...
 

Protected Member Functions

 reportExpectationViolated ($expect, $query, $actual=null)
 

Protected Attributes

float $dbLockThreshold = 3.0
 Seconds. More...
 
array $dbTrxHoldingLocks = []
 transaction ID => (write start time, list of DBs involved) More...
 
array $dbTrxMethodTimes = []
 transaction ID => list of (query name, start time, end time) More...
 
float $eventThreshold = .25
 Seconds. More...
 
array array $expect
 
array array array $expectBy = []
 
array $hits
 

Private Attributes

LoggerInterface $logger
 

Detailed Description

Helper class that detects high-contention DB queries via profiling calls.

This class is meant to work with a DatabaseBase object, which manages queries

Since
1.24

Definition at line 36 of file TransactionProfiler.php.

Constructor & Destructor Documentation

TransactionProfiler::__construct ( )

Definition at line 72 of file TransactionProfiler.php.

References setLogger().

Member Function Documentation

TransactionProfiler::recordConnection (   $server,
  $db,
  $isMaster 
)

Mark a DB as having been connected to with a new handle.

Note that there can be multiple connections to a single DB.

Parameters
string$serverDB server
string$dbDB name
bool$isMaster

Definition at line 140 of file TransactionProfiler.php.

References reportExpectationViolated().

TransactionProfiler::recordQueryCompletion (   $query,
  $sTime,
  $isWrite = false,
  $n = 0 
)

Register the name and time of a method for slow DB trx detection.

This assumes that all queries are synchronous (non-overlapping)

Parameters
string$queryFunction name or generalized SQL
float$sTimeStarting UNIX wall time
bool$isWriteWhether this is a write query
integer$nNumber of affected rows

Definition at line 186 of file TransactionProfiler.php.

References $name, $query, as, reportExpectationViolated(), and wfBacktrace().

TransactionProfiler::reportExpectationViolated (   $expect,
  $query,
  $actual = null 
)
protected
Parameters
string$expect
string$query
string | float | int$actual[optional]

Definition at line 304 of file TransactionProfiler.php.

References $expect, and wfBacktrace().

Referenced by recordConnection(), recordQueryCompletion(), and transactionWritingOut().

TransactionProfiler::resetExpectations ( )

Reset performance expectations and hit counters.

Since
1.25

Definition at line 119 of file TransactionProfiler.php.

References as.

TransactionProfiler::setExpectation (   $event,
  $value,
  $fname 
)

Set performance expectations.

With conflicting expectations, the most narrow ones will be used

Parameters
string$event(writes,queries,conns,mConns)
integer$valueMaximum count of the event
string$fnameCaller
Since
1.25

Definition at line 90 of file TransactionProfiler.php.

References $fname, and $value.

Referenced by setExpectations().

TransactionProfiler::setExpectations ( array  $expects,
  $fname 
)

Set multiple performance expectations.

With conflicting expectations, the most narrow ones will be used

Parameters
array$expectsMap of (event => limit)
$fname
Since
1.26

Definition at line 108 of file TransactionProfiler.php.

References $fname, $value, as, and setExpectation().

TransactionProfiler::setLogger ( LoggerInterface  $logger)

Definition at line 76 of file TransactionProfiler.php.

References $logger.

Referenced by __construct().

TransactionProfiler::transactionWritingIn (   $server,
  $db,
  $id 
)

Mark a DB as in a transaction with one or more writes pending.

Note that there can be multiple connections to a single DB.

Parameters
string$serverDB server
string$dbDB name
string$idID string of transaction

Definition at line 159 of file TransactionProfiler.php.

References $name, and as.

TransactionProfiler::transactionWritingOut (   $server,
  $db,
  $id,
  $writeTime = 0.0 
)

Mark a DB as no longer in a transaction.

This will check if locks are possibly held for longer than needed and log any affected transactions to a special DB log. Note that there can be multiple connections to a single DB.

Parameters
string$serverDB server
string$dbDB name
string$idID string of transaction
float$writeTimeTime spent in write queries

Definition at line 251 of file TransactionProfiler.php.

References $name, $query, as, list, and reportExpectationViolated().

Member Data Documentation

float TransactionProfiler::$dbLockThreshold = 3.0
protected

Seconds.

Definition at line 38 of file TransactionProfiler.php.

array TransactionProfiler::$dbTrxHoldingLocks = []
protected

transaction ID => (write start time, list of DBs involved)

Definition at line 43 of file TransactionProfiler.php.

array TransactionProfiler::$dbTrxMethodTimes = []
protected

transaction ID => list of (query name, start time, end time)

Definition at line 45 of file TransactionProfiler.php.

float TransactionProfiler::$eventThreshold = .25
protected

Seconds.

Definition at line 40 of file TransactionProfiler.php.

array array TransactionProfiler::$expect
protected
Initial value:
= [
'writes' => INF

Definition at line 55 of file TransactionProfiler.php.

Referenced by reportExpectationViolated().

array array array TransactionProfiler::$expectBy = []
protected

Definition at line 65 of file TransactionProfiler.php.

array TransactionProfiler::$hits
protected
Initial value:
= [
'writes' => 0

Definition at line 48 of file TransactionProfiler.php.

LoggerInterface TransactionProfiler::$logger
private

Definition at line 70 of file TransactionProfiler.php.

Referenced by setLogger().


The documentation for this class was generated from the following file: