Merge "Refine thumbnailing metrics"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 17 Jul 2015 19:03:52 +0000 (19:03 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 17 Jul 2015 19:03:52 +0000 (19:03 +0000)
includes/filerepo/file/File.php
thumb.php

index 76ed27b..7ea658d 100644 (file)
@@ -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;
        }
 
index 0d0a15e..5c4eea7 100644 (file)
--- 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 ) {