MediaWiki REL1_35
|
Detect high-contention DB queries via profiling calls. More...
Public Member Functions | |
__construct () | |
recordConnection ( $server, $db, $isMaster) | |
Mark a DB as having been connected to with a new handle. | |
recordQueryCompletion ( $query, $sTime, $isWrite=false, $n=0) | |
Register the name and time of a method for slow DB trx detection. | |
redefineExpectations (array $expects, $fname) | |
Clear all expectations and hit counters and set new performance expectations. | |
resetExpectations () | |
Reset all performance expectations and hit counters. | |
setExpectation ( $event, $value, $fname) | |
Set performance expectations. | |
setExpectations (array $expects, $fname) | |
Set one or multiple performance expectations. | |
setLogger (LoggerInterface $logger) | |
setSilenced ( $value) | |
transactionWritingIn ( $server, $db, $id) | |
Mark a DB as in a transaction with one or more writes pending. | |
transactionWritingOut ( $server, $db, $id, $writeTime=0.0, $affected=0) | |
Mark a DB as no longer in a transaction. | |
Protected Member Functions | |
reportExpectationViolated ( $expect, $query, $actual) | |
Protected Attributes | |
float | $dbLockThreshold = 3.0 |
Seconds. | |
array | $dbTrxHoldingLocks = [] |
transaction ID => (write start time, list of DBs involved) | |
array[][] | $dbTrxMethodTimes = [] |
transaction ID => list of (query name, start time, end time) -var array<string,array<int,array{0:string,1:int,2:int}>> | |
float | $eventThreshold = 0.25 |
Seconds. | |
array | $expect |
array | $expectBy = [] |
array | $hits |
bool | $silenced = false |
Static Private Member Functions | |
static | queryString ( $query) |
Private Attributes | |
LoggerInterface | $logger |
Detect high-contention DB queries via profiling calls.
This class is meant to work with an IDatabase object, which manages queries.
Definition at line 38 of file TransactionProfiler.php.
Wikimedia\Rdbms\TransactionProfiler::__construct | ( | ) |
Definition at line 80 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\setLogger().
|
staticprivate |
GeneralizedSql | string | $query |
Definition at line 386 of file TransactionProfiler.php.
References Wikimedia\Rdbms\GeneralizedSql\stringify().
Wikimedia\Rdbms\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.
string | $server | DB server |
string | $db | DB name |
bool | $isMaster |
Definition at line 181 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().
Wikimedia\Rdbms\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)
string | GeneralizedSql | $query | Function name or generalized SQL |
float | $sTime | Starting UNIX wall time |
bool | $isWrite | Whether this is a write query |
int | $n | Number of affected/read rows |
Definition at line 229 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().
Wikimedia\Rdbms\TransactionProfiler::redefineExpectations | ( | array | $expects, |
$fname | |||
) |
Clear all expectations and hit counters and set new performance expectations.
Use this to apply a totally different set of expectations for a different part of the request, such as during "post-send" (execution after HTTP response completion)
array | $expects | Map of (event => limit) |
string | $fname |
Definition at line 167 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\resetExpectations(), and Wikimedia\Rdbms\TransactionProfiler\setExpectations().
|
protected |
string | $expect | |
string | GeneralizedSql | $query | |
string | float | int | $actual |
Definition at line 364 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\$expect.
Referenced by Wikimedia\Rdbms\TransactionProfiler\recordConnection(), Wikimedia\Rdbms\TransactionProfiler\recordQueryCompletion(), and Wikimedia\Rdbms\TransactionProfiler\transactionWritingOut().
Wikimedia\Rdbms\TransactionProfiler::resetExpectations | ( | ) |
Reset all performance expectations and hit counters.
Use this for unit testing or before applying a totally different set of expectations for a different part of the request, such as during "post-send" (execution after HTTP response completion)
Definition at line 145 of file TransactionProfiler.php.
Referenced by Wikimedia\Rdbms\TransactionProfiler\redefineExpectations().
Wikimedia\Rdbms\TransactionProfiler::setExpectation | ( | $event, | |
$value, | |||
$fname | |||
) |
Set performance expectations.
With conflicting expectations, the most narrow ones will be used
string | $event | (writes,queries,conns,mConns) |
int | $value | Maximum count of the event |
string | $fname | Caller |
Definition at line 110 of file TransactionProfiler.php.
Referenced by Wikimedia\Rdbms\TransactionProfiler\setExpectations().
Wikimedia\Rdbms\TransactionProfiler::setExpectations | ( | array | $expects, |
$fname | |||
) |
Set one or multiple performance expectations.
With conflicting expectations, the most narrow ones will be used
Use this to initialize expectations or make them stricter mid-request
array | $expects | Map of (event => limit) |
string | $fname |
Definition at line 130 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\setExpectation().
Referenced by Wikimedia\Rdbms\TransactionProfiler\redefineExpectations().
Wikimedia\Rdbms\TransactionProfiler::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 84 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\$logger.
Referenced by Wikimedia\Rdbms\TransactionProfiler\__construct().
Wikimedia\Rdbms\TransactionProfiler::setSilenced | ( | $value | ) |
bool | $value |
Definition at line 93 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\$silenced.
Wikimedia\Rdbms\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.
string | $server | DB server |
string | $db | DB name |
string | $id | ID string of transaction |
Definition at line 202 of file TransactionProfiler.php.
Wikimedia\Rdbms\TransactionProfiler::transactionWritingOut | ( | $server, | |
$db, | |||
$id, | |||
$writeTime = 0.0 , |
|||
$affected = 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.
string | $server | DB server |
string | $db | DB name |
string | $id | ID string of transaction |
float | $writeTime | Time spent in write queries |
int | $affected | Number of rows affected by writes |
Definition at line 300 of file TransactionProfiler.php.
References Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().
|
protected |
Seconds.
Definition at line 40 of file TransactionProfiler.php.
|
protected |
transaction ID => (write start time, list of DBs involved)
Definition at line 47 of file TransactionProfiler.php.
|
protected |
transaction ID => list of (query name, start time, end time) -var array<string,array<int,array{0:string,1:int,2:int}>>
Definition at line 52 of file TransactionProfiler.php.
|
protected |
Seconds.
Definition at line 42 of file TransactionProfiler.php.
|
protected |
Definition at line 62 of file TransactionProfiler.php.
Referenced by Wikimedia\Rdbms\TransactionProfiler\reportExpectationViolated().
|
protected |
Definition at line 73 of file TransactionProfiler.php.
|
protected |
Definition at line 55 of file TransactionProfiler.php.
|
private |
Definition at line 78 of file TransactionProfiler.php.
Referenced by Wikimedia\Rdbms\TransactionProfiler\setLogger().
|
protected |
Definition at line 44 of file TransactionProfiler.php.
Referenced by Wikimedia\Rdbms\TransactionProfiler\setSilenced().