Merge "Fix CLI installer when --dbname is not specified on command line."
[lhc/web/wiklou.git] / includes / jobqueue / JobRunner.php
index a6d088f..4ab9f5a 100644 (file)
@@ -251,6 +251,7 @@ class JobRunner implements LoggerAwareInterface {
                $this->debugCallback( $msg );
 
                // Run the job...
+               $rssStart = $this->getMaxRssKb();
                $jobStartTime = microtime( true );
                try {
                        $status = $job->run();
@@ -272,6 +273,7 @@ class JobRunner implements LoggerAwareInterface {
                // Clear out title cache data from prior snapshots
                LinkCache::singleton()->clear();
                $timeMs = intval( ( microtime( true ) - $jobStartTime ) * 1000 );
+               $rssEnd = $this->getMaxRssKb();
 
                // Record how long jobs wait before getting popped
                $readyTs = $job->getReadyTimestamp();
@@ -288,6 +290,10 @@ class JobRunner implements LoggerAwareInterface {
                }
                // Track the execution time for jobs
                $stats->timing( "jobqueue.run.$jType", $timeMs );
+               // Track RSS increases for jobs (in case of memory leaks)
+               if ( $rssStart && $rssEnd ) {
+                       $stats->increment( "jobqueue.rss_delta.$jType", $rssEnd - $rssStart );
+               }
 
                if ( $status === false ) {
                        $msg = $job->toString() . " t=$timeMs error={$error}";
@@ -302,6 +308,15 @@ class JobRunner implements LoggerAwareInterface {
                return array( 'status' => $status, 'error' => $error, 'timeMs' => $timeMs );
        }
 
+       /**
+        * @return int|null Max memory RSS in kilobytes
+        */
+       private function getMaxRssKb() {
+               $info = wfGetRusage() ?: array();
+               // see http://linux.die.net/man/2/getrusage
+               return isset( $info['ru_maxrss'] ) ? (int)$info['ru_maxrss'] : null;
+       }
+
        /**
         * @param Job $job
         * @return int Seconds for this runner to avoid doing more jobs of this type