Skip to content

Commit

Permalink
File: handle stats for recursive transformation calls
Browse files Browse the repository at this point in the history
TimingMetric->start() and stop() cannot handle recursion due to statefulness.

To fix, we'll measure the metric manually so that the sample will be
captured in a single operation.

Bug: T367110
Bug: T367928
Change-Id: I663d32e0211df35d5295bf2a09175e6fdcb4c5ed
  • Loading branch information
shdubsh committed Jun 20, 2024
1 parent 57b4204 commit 1d22bf1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions includes/filerepo/file/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1320,15 +1320,20 @@ public function generateAndSaveThumb( $tmpFile, $transformParams, $flags ) {
$this->generateBucketsIfNeeded( $normalisedParams, $flags );
}

$timer = $statsFactory->getTiming( 'media_thumbnail_generate_transform_seconds' )
->copyToStatsdAt( 'media.thumbnail.generate.transform' );
$timer->start();
# T367110
# Calls to doTransform() can recur back on $this->transform()
# depending on implementation. One such example is PagedTiffHandler.
# TimingMetric->start() and stop() cannot be used in this situation
# so we will track the time manually.
$starttime = microtime( true );

// Actually render the thumbnail...
$thumb = $handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $transformParams );
$tmpFile->bind( $thumb ); // keep alive with $thumb

$timer->stop();
$statsFactory->getTiming( 'media_thumbnail_generate_transform_seconds' )
->copyToStatsdAt( 'media.thumbnail.generate.transform' )
->observe( ( microtime( true ) - $starttime ) * 1000 );

if ( !$thumb ) { // bad params?
$thumb = false;
Expand Down

0 comments on commit 1d22bf1

Please sign in to comment.