From b88e88b67d2c31a5b0f130cf00f18e0e7549c503 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 26 Jun 2015 06:57:17 +0100 Subject: [PATCH] resourceloader: Add timing metrics for key operations * 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 | 28 +++++++++++-------- .../resourceloader/ResourceLoaderModule.php | 7 +++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 92b0156fb1..3d49d9497e 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -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 */ diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 5e7067f171..94edb36b16 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -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; } -- 2.20.1