Skip to content

Commit

Permalink
Bug 1291071 (Part 4) - Clean up Decoder::SpeedHistogram() and related…
Browse files Browse the repository at this point in the history
… code. r=edwin
  • Loading branch information
sethfowler committed Aug 6, 2016
1 parent cff83c6 commit 6a9ab9b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
9 changes: 1 addition & 8 deletions image/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Decoder::TakeCompleteFrameCount()
}

DecoderTelemetry
Decoder::Telemetry()
Decoder::Telemetry() const
{
MOZ_ASSERT(mIterator);
return DecoderTelemetry(SpeedHistogram(),
Expand Down Expand Up @@ -543,12 +543,5 @@ Decoder::PostError()
}
}

Telemetry::ID
Decoder::SpeedHistogram()
{
// Use HistogramCount as an invalid Histogram ID.
return Telemetry::HistogramCount;
}

} // namespace image
} // namespace mozilla
19 changes: 13 additions & 6 deletions image/Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace image {

struct DecoderTelemetry final
{
DecoderTelemetry(Telemetry::ID aSpeedHistogram,
DecoderTelemetry(Maybe<Telemetry::ID> aSpeedHistogram,
size_t aBytesDecoded,
uint32_t aChunkCount,
TimeDuration aDecodeTime)
Expand All @@ -49,8 +49,9 @@ struct DecoderTelemetry final
/// @return our decoder's decode time, in microseconds.
int32_t DecodeTimeMicros() { return mDecodeTime.ToMicroseconds(); }

/// The per-image-format telemetry ID for recording our decoder's speed.
const Telemetry::ID mSpeedHistogram;
/// The per-image-format telemetry ID for recording our decoder's speed, or
/// Nothing() if we don't record speed telemetry for this kind of decoder.
const Maybe<Telemetry::ID> mSpeedHistogram;

/// The number of bytes of input our decoder processed.
const size_t mBytesDecoded;
Expand Down Expand Up @@ -336,13 +337,11 @@ class Decoder
return gfx::IntRect(gfx::IntPoint(), OutputSize());
}

virtual Telemetry::ID SpeedHistogram();

/// @return the metadata we collected about this image while decoding.
const ImageMetadata& GetImageMetadata() { return mImageMetadata; }

/// @return performance telemetry we collected while decoding.
DecoderTelemetry Telemetry();
DecoderTelemetry Telemetry() const;

/**
* @return a weak pointer to the image associated with this decoder. Illegal
Expand Down Expand Up @@ -387,6 +386,14 @@ class Decoder
virtual nsresult FinishInternal();
virtual nsresult FinishWithErrorInternal();

/**
* @return the per-image-format telemetry ID for recording this decoder's
* speed, or Nothing() if we don't record speed telemetry for this kind of
* decoder.
*/
virtual Maybe<Telemetry::ID> SpeedHistogram() const { return Nothing(); }


/*
* Progress notifications.
*/
Expand Down
7 changes: 2 additions & 5 deletions image/RasterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,8 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder,
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_TIME,
int32_t(aTelemetry.mDecodeTime.ToMicroseconds()));

// We record the speed for only some decoders. The rest have
// SpeedHistogram return HistogramCount.
Telemetry::ID id = aTelemetry.mSpeedHistogram;
if (id < Telemetry::HistogramCount) {
Telemetry::Accumulate(id, aTelemetry.Speed());
if (aTelemetry.mSpeedHistogram) {
Telemetry::Accumulate(*aTelemetry.mSpeedHistogram, aTelemetry.Speed());
}
}

Expand Down
6 changes: 3 additions & 3 deletions image/decoders/nsGIFDecoder2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,10 @@ nsGIFDecoder2::SkipSubBlocks(const char* aData)
nextSubBlockLength);
}

Telemetry::ID
nsGIFDecoder2::SpeedHistogram()
Maybe<Telemetry::ID>
nsGIFDecoder2::SpeedHistogram() const
{
return Telemetry::IMAGE_DECODE_SPEED_GIF;
return Some(Telemetry::IMAGE_DECODE_SPEED_GIF);
}

} // namespace image
Expand Down
4 changes: 3 additions & 1 deletion image/decoders/nsGIFDecoder2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ class nsGIFDecoder2 : public Decoder
public:
~nsGIFDecoder2();

protected:
LexerResult DoDecode(SourceBufferIterator& aIterator,
IResumable* aOnResume) override;
nsresult FinishInternal() override;
virtual Telemetry::ID SpeedHistogram() override;

Maybe<Telemetry::ID> SpeedHistogram() const override;

private:
friend class DecoderFactory;
Expand Down
6 changes: 3 additions & 3 deletions image/decoders/nsJPEGDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ nsJPEGDecoder::~nsJPEGDecoder()
this));
}

Telemetry::ID
nsJPEGDecoder::SpeedHistogram()
Maybe<Telemetry::ID>
nsJPEGDecoder::SpeedHistogram() const
{
return Telemetry::IMAGE_DECODE_SPEED_JPEG;
return Some(Telemetry::IMAGE_DECODE_SPEED_JPEG);
}

nsresult
Expand Down
6 changes: 4 additions & 2 deletions image/decoders/nsJPEGDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ class nsJPEGDecoder : public Decoder
mSampleSize = aSampleSize;
}

void NotifyDone();

protected:
nsresult InitInternal() override;
LexerResult DoDecode(SourceBufferIterator& aIterator,
IResumable* aOnResume) override;
nsresult FinishInternal() override;

virtual Telemetry::ID SpeedHistogram() override;
void NotifyDone();
Maybe<Telemetry::ID> SpeedHistogram() const override;

protected:
Orientation ReadOrientationFromEXIF();
Expand Down
6 changes: 3 additions & 3 deletions image/decoders/nsPNGDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,10 @@ nsPNGDecoder::warning_callback(png_structp png_ptr, png_const_charp warning_msg)
MOZ_LOG(sPNGLog, LogLevel::Warning, ("libpng warning: %s\n", warning_msg));
}

Telemetry::ID
nsPNGDecoder::SpeedHistogram()
Maybe<Telemetry::ID>
nsPNGDecoder::SpeedHistogram() const
{
return Telemetry::IMAGE_DECODE_SPEED_PNG;
return Some(Telemetry::IMAGE_DECODE_SPEED_PNG);
}

bool
Expand Down
8 changes: 5 additions & 3 deletions image/decoders/nsPNGDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ class nsPNGDecoder : public Decoder
public:
virtual ~nsPNGDecoder();

/// @return true if this PNG is a valid ICO resource.
bool IsValidICO() const;

protected:
nsresult InitInternal() override;
LexerResult DoDecode(SourceBufferIterator& aIterator,
IResumable* aOnResume) override;
virtual Telemetry::ID SpeedHistogram() override;

/// @return true if this PNG is a valid ICO resource.
bool IsValidICO() const;
Maybe<Telemetry::ID> SpeedHistogram() const override;

private:
friend class DecoderFactory;
Expand Down

0 comments on commit 6a9ab9b

Please sign in to comment.