From ec60612b6f5f684c76d73fbe93d4244499700c04 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Fri, 17 Jul 2015 13:48:56 +0200 Subject: [PATCH] Refine thumbnailing metrics Bug: T105681 Change-Id: Icf576a1718eb2e588af4c48c05362bbef3bb7942 --- includes/filerepo/file/File.php | 27 +++++++++++++++++++++++++++ thumb.php | 10 ++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 76ed27b337..7ea658da8a 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -421,7 +421,10 @@ abstract class File implements IDBAccessObject { public function getLocalRefPath() { $this->assertRepoDefined(); if ( !isset( $this->fsFile ) ) { + $starttime = microtime( true ); $this->fsFile = $this->repo->getLocalReference( $this->getPath() ); + RequestContext::getMain()->getStats()->timing( 'media.thumbnail.generate.fetchoriginal', microtime( true ) - $starttime ); + if ( !$this->fsFile ) { $this->fsFile = false; // null => false; cache negative hits } @@ -1094,6 +1097,8 @@ abstract class File implements IDBAccessObject { public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) { global $wgUseSquid, $wgIgnoreImageErrors; + $stats = RequestContext::getMain()->getStats(); + $handler = $this->getHandler(); $normalisedParams = $transformParams; @@ -1109,10 +1114,14 @@ abstract class File implements IDBAccessObject { $this->generateBucketsIfNeeded( $normalisedParams, $flags ); } + $starttime = microtime( true ); + // Actually render the thumbnail... $thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams ); $tmpFile->bind( $thumb ); // keep alive with $thumb + $stats->timing( 'media.thumbnail.generate.transform', microtime( true ) - $starttime ); + if ( !$thumb ) { // bad params? $thumb = false; } elseif ( $thumb->isError() ) { // transform error @@ -1123,6 +1132,9 @@ abstract class File implements IDBAccessObject { } } elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) { // Copy the thumbnail from the file system into storage... + + $starttime = microtime( true ); + $disposition = $this->getThumbDisposition( $thumbName ); $status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition ); if ( $status->isOK() ) { @@ -1130,6 +1142,9 @@ abstract class File implements IDBAccessObject { } else { $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $transformParams, $flags ); } + + $stats->timing( 'media.thumbnail.generate.store', microtime( true ) - $starttime ); + // Give extensions a chance to do something with this thumbnail... Hooks::run( 'FileTransformed', array( $this, $thumb, $tmpThumbPath, $thumbPath ) ); } @@ -1139,10 +1154,16 @@ abstract class File implements IDBAccessObject { // "thumbs" which have the main image URL though (bug 13776) if ( $wgUseSquid ) { if ( !$thumb || $thumb->isError() || $thumb->getUrl() != $this->getURL() ) { + $starttime = microtime( true ); + SquidUpdate::purge( array( $thumbUrl ) ); + + $stats->timing( 'media.thumbnail.generate.purge', microtime( true ) - $starttime ); } } + + return $thumb; } @@ -1167,6 +1188,8 @@ abstract class File implements IDBAccessObject { return false; } + $starttime = microtime( true ); + $params['physicalWidth'] = $bucket; $params['width'] = $bucket; @@ -1182,6 +1205,8 @@ abstract class File implements IDBAccessObject { $thumb = $this->generateAndSaveThumb( $tmpFile, $params, $flags ); + $buckettime = microtime( true ) - $starttime; + if ( !$thumb || $thumb->isError() ) { return false; } @@ -1191,6 +1216,8 @@ abstract class File implements IDBAccessObject { // this object exists $tmpFile->bind( $this ); + RequestContext::getMain()->getStats()->timing( 'media.thumbnail.generate.bucket', $buckettime ); + return true; } diff --git a/thumb.php b/thumb.php index 0d0a15ebcf..5c4eea7449 100644 --- a/thumb.php +++ b/thumb.php @@ -298,8 +298,6 @@ function wfStreamThumb( array $params ) { $headers[] = 'Vary: ' . implode( ', ', $varyHeader ); } - $stats = RequestContext::getMain()->getStats(); - // Stream the file if it exists already... $thumbPath = $img->getThumbPath( $thumbName ); if ( $img->getRepo()->fileExists( $thumbPath ) ) { @@ -310,7 +308,7 @@ function wfStreamThumb( array $params ) { if ( !$success ) { wfThumbError( 500, 'Could not stream the file' ); } else { - $stats->timing( 'media.thumbnail.stream', $streamtime ); + RequestContext::getMain()->getStats()->timing( 'media.thumbnail.stream', $streamtime ); } return; } @@ -324,10 +322,8 @@ function wfStreamThumb( array $params ) { return; } - // Actually generate a new thumbnail - $starttime = microtime( true ); list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); - $generatetime = microtime( true ) - $starttime; + /** @var MediaTransformOutput|bool $thumb */ // Check for thumbnail generation errors... @@ -348,8 +344,6 @@ function wfStreamThumb( array $params ) { if ( $errorMsg !== false ) { wfThumbError( $errorCode, $errorMsg ); } else { - $stats->timing( 'media.thumbnail.generate', $generatetime ); - // Stream the file if there were no errors $success = $thumb->streamFile( $headers ); if ( !$success ) { -- 2.20.1