jenkins-bot has submitted this change and it was merged.
Change subject: Made TransactionProfiler log regardless of Profiler
......................................................................
Made TransactionProfiler log regardless of Profiler
* Also avoid the use of slow closures for profiling
Change-Id: Id437e39038fd9ba80b899329a61e9f14229481f2
---
M includes/db/Database.php
1 file changed, 21 insertions(+), 29 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/db/Database.php b/includes/db/Database.php
index 8fa10a6..8ce7f3f 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -1121,24 +1121,21 @@
$this->mServer, $this->mDBname,
$this->mTrxShortId );
}
- $queryProf = '';
- $totalProf = '';
$isMaster = !is_null( $this->getLBInfo( 'master' ) );
+ # generalizeSQL will probably cut down the query to reasonable
+ # logging size most of the time. The substr is really just a
sanity check.
+ if ( $isMaster ) {
+ $queryProf = 'query-m: ' . substr(
DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+ $totalProf = 'DatabaseBase::query-master';
+ } else {
+ $queryProf = 'query: ' . substr(
DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+ $totalProf = 'DatabaseBase::query';
+ }
+ # Include query transaction state
+ $queryProf .= $this->mTrxShortId ? "
[TRX#{$this->mTrxShortId}]" : "";
$profiler = Profiler::instance();
if ( !$profiler instanceof ProfilerStub ) {
- # generalizeSQL will probably cut down the query to
reasonable
- # logging size most of the time. The substr is really
just a sanity check.
- if ( $isMaster ) {
- $queryProf = 'query-m: ' . substr(
DatabaseBase::generalizeSQL( $sql ), 0, 255 );
- $totalProf = 'DatabaseBase::query-master';
- } else {
- $queryProf = 'query: ' . substr(
DatabaseBase::generalizeSQL( $sql ), 0, 255 );
- $totalProf = 'DatabaseBase::query';
- }
- # Include query transaction state
- $queryProf .= $this->mTrxShortId ? "
[TRX#{$this->mTrxShortId}]" : "";
-
$totalProfSection = $profiler->scopedProfileIn(
$totalProf );
$queryProfSection = $profiler->scopedProfileIn(
$queryProf );
}
@@ -1162,22 +1159,12 @@
throw new DBUnexpectedError( $this, "DB connection was
already closed." );
}
- # Log the query time and feed it into the DB trx profiler
- if ( $queryProf != '' ) {
- $that = $this;
- $queryStartTime = microtime( true );
- $queryProfile = new ScopedCallback(
- function () use ( $that, $queryStartTime,
$queryProf, $isWriteQuery ) {
- $n = $that->affectedRows();
- $trxProf =
Profiler::instance()->getTransactionProfiler();
- $trxProf->recordQueryCompletion(
- $queryProf, $queryStartTime,
$isWriteQuery, $n );
- }
- );
- }
-
# Do the query and handle errors
+ $startTime = microtime( true );
$ret = $this->doQuery( $commentedSql );
+ # Log the query time and feed it into the DB trx profiler
+ $profiler->getTransactionProfiler()->recordQueryCompletion(
+ $queryProf, $startTime, $isWriteQuery,
$this->affectedRows() );
MWDebug::queryTime( $queryId );
@@ -1204,7 +1191,11 @@
$this->reportQueryError( $lastError,
$lastErrno, $sql, $fname, $tempIgnore );
} else {
# Should be safe to silently retry (no
trx and thus no callbacks)
+ $startTime = microtime( true );
$ret = $this->doQuery( $commentedSql );
+ # Log the query time and feed it into
the DB trx profiler
+
$profiler->getTransactionProfiler()->recordQueryCompletion(
+ $queryProf, $startTime,
$isWriteQuery, $this->affectedRows() );
}
} else {
wfDebug( "Failed\n" );
@@ -1212,7 +1203,8 @@
}
if ( false === $ret ) {
- $this->reportQueryError( $this->lastError(),
$this->lastErrno(), $sql, $fname, $tempIgnore );
+ $this->reportQueryError(
+ $this->lastError(), $this->lastErrno(), $sql,
$fname, $tempIgnore );
}
$res = $this->resultObject( $ret );
--
To view, visit https://gerrit.wikimedia.org/r/191830
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id437e39038fd9ba80b899329a61e9f14229481f2
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits