resourceloader: Add timing metrics for key operations
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 26 Jun 2015 05:57:17 +0000 (06:57 +0100)
committerKrinkle <krinklemail@gmail.com>
Mon, 29 Jun 2015 20:21:58 +0000 (20:21 +0000)
* Minification of css and js.

* Total generation of module content.
  Includes:
  - Fetching/generating of content (files, wikipage, dynamic).
  - Pre/post processing (concat, less>css, cssjanus, ..)

Change-Id: Id60e665dfb6280aa254116f0867b909afc6f878a

includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderModule.php

index 92b0156..3d49d94 100644 (file)
@@ -215,7 +215,6 @@ class ResourceLoader implements LoggerAwareInterface {
                        }
                        $result = '';
                        try {
-                               wfIncrStats( "resourceloader_cache.$filter.miss" );
                                $result = $this->applyFilter( $filter, $data );
                                if ( $options['cacheReport'] ) {
                                        $result .= "\n/* cache key: $key */";
@@ -234,16 +233,23 @@ class ResourceLoader implements LoggerAwareInterface {
        }
 
        private function applyFilter( $filter, $data ) {
-                       switch ( $filter ) {
-                               case 'minify-js':
-                                       return JavaScriptMinifier::minify( $data,
-                                               $this->config->get( 'ResourceLoaderMinifierStatementsOnOwnLine' ),
-                                               $this->config->get( 'ResourceLoaderMinifierMaxLineLength' )
-                                       );
-                               case 'minify-css':
-                                       return CSSMin::minify( $data );
-                       }
-                       return $data;
+               $stats = RequestContext::getMain()->getStats();
+               $statStart = microtime( true );
+
+               switch ( $filter ) {
+                       case 'minify-js':
+                               $data = JavaScriptMinifier::minify( $data,
+                                       $this->config->get( 'ResourceLoaderMinifierStatementsOnOwnLine' ),
+                                       $this->config->get( 'ResourceLoaderMinifierMaxLineLength' )
+                               );
+                               break;
+                       case 'minify-css':
+                               $data = CSSMin::minify( $data );
+                               break;
+               }
+
+               $stats->timing( "resourceloader_cache.$filter.miss", microtime( true ) - $statStart );
+               return $data;
        }
 
        /* Methods */
index 5e7067f..94edb36 100644 (file)
@@ -480,6 +480,8 @@ abstract class ResourceLoaderModule {
         */
        final protected function buildContent( ResourceLoaderContext $context ) {
                $rl = $context->getResourceLoader();
+               $stats = RequestContext::getMain()->getStats();
+               $statStart = microtime( true );
 
                // Only include properties that are relevant to this context (e.g. only=scripts)
                // and that are non-empty (e.g. don't include "templates" for modules without
@@ -568,6 +570,11 @@ abstract class ResourceLoaderModule {
                        $content['templates'] = $templates;
                }
 
+               $statTiming = microtime( true ) - $statStart;
+               $statName = str_replace( '.', '_', $this->getName() );
+               $stats->timing( "resourceloader_build.all", $statTiming );
+               $stats->timing( "resourceloader_build.$statName", $statTiming );
+
                return $content;
        }