Handle edge case in WikiPage::lock()
[lhc/web/wiklou.git] / includes / profiler / TransactionProfiler.php
index 5f2a57a..46d6119 100644 (file)
@@ -59,7 +59,7 @@ class TransactionProfiler implements LoggerAwareInterface {
                'masterConns'    => INF,
                'maxAffected'    => INF,
                'readQueryTime'  => INF,
-               'writeQueryTime' => INF,
+               'writeQueryTime' => INF
        );
        /** @var array */
        protected $expectBy = array();
@@ -246,13 +246,23 @@ class TransactionProfiler implements LoggerAwareInterface {
         * @param string $server DB server
         * @param string $db DB name
         * @param string $id ID string of transaction
+        * @param float $writeTime Time spent in write queries
         */
-       public function transactionWritingOut( $server, $db, $id ) {
+       public function transactionWritingOut( $server, $db, $id, $writeTime = 0.0 ) {
                $name = "{$server} ({$db}) (TRX#$id)";
                if ( !isset( $this->dbTrxMethodTimes[$name] ) ) {
                        $this->logger->info( "Detected no transaction for '$name' - out of sync." );
                        return;
                }
+
+               $slow = false;
+
+               // Warn if too much time was spend writing...
+               if ( $writeTime > $this->expect['writeQueryTime'] ) {
+                       $this->reportExpectationViolated( 'writeQueryTime',
+                               "[transaction $id writes to {$server} ({$db})]" );
+                       $slow = true;
+               }
                // Fill in the last non-query period...
                $lastQuery = end( $this->dbTrxMethodTimes[$name] );
                if ( $lastQuery ) {
@@ -263,7 +273,6 @@ class TransactionProfiler implements LoggerAwareInterface {
                        }
                }
                // Check for any slow queries or non-query periods...
-               $slow = false;
                foreach ( $this->dbTrxMethodTimes[$name] as $info ) {
                        $elapsed = ( $info[2] - $info[1] );
                        if ( $elapsed >= $this->dbLockThreshold ) {