Merge "Revision: Handle all return values of Title::newFromId"
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index ad16420..63a495a 100644 (file)
@@ -236,8 +236,6 @@ class ResourceLoader implements LoggerAwareInterface {
                return $data;
        }
 
-       /* Methods */
-
        /**
         * Register core modules and runs registration hooks.
         * @param Config $config [optional]
@@ -655,7 +653,7 @@ class ResourceLoader implements LoggerAwareInterface {
         *
         * @since 1.26
         * @param ResourceLoaderContext $context
-        * @param string[] $modules List of known module names
+        * @param string[] $moduleNames List of known module names
         * @return string Hash
         */
        public function getCombinedVersion( ResourceLoaderContext $context, array $moduleNames ) {
@@ -728,6 +726,8 @@ class ResourceLoader implements LoggerAwareInterface {
                // See https://bugs.php.net/bug.php?id=36514
                ob_start();
 
+               $this->measureResponseTime( RequestContext::getMain()->getTiming() );
+
                // Find out which modules are missing and instantiate the others
                $modules = [];
                $missing = [];
@@ -828,6 +828,16 @@ class ResourceLoader implements LoggerAwareInterface {
                echo $response;
        }
 
+       protected function measureResponseTime( Timing $timing ) {
+               DeferredUpdates::addCallableUpdate( function () use ( $timing ) {
+                       $measure = $timing->measure( 'responseTime', 'requestStart', 'requestShutdown' );
+                       if ( $measure !== false ) {
+                               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+                               $stats->timing( 'resourceloader.responseTime', $measure['duration'] * 1000 );
+                       }
+               } );
+       }
+
        /**
         * Send main response headers to the client.
         *
@@ -1198,8 +1208,6 @@ MESSAGE;
                return $moduleNames;
        }
 
-       /* Static Methods */
-
        /**
         * Return JS code that calls mw.loader.implement with given module properties.
         *