Bug 1285865 (Part 2) - Add a RAII class to record decoder telemetry. r=edwin

This commit is contained in:
Seth Fowler 2016-07-11 00:03:42 -07:00
parent a50b8d5f3e
commit b9c1cec011
2 changed files with 30 additions and 9 deletions

View File

@ -22,6 +22,34 @@ using mozilla::gfx::SurfaceFormat;
namespace mozilla {
namespace image {
class MOZ_STACK_CLASS AutoRecordDecoderTelemetry final
{
public:
AutoRecordDecoderTelemetry(Decoder* aDecoder, uint32_t aByteCount)
: mDecoder(aDecoder)
{
MOZ_ASSERT(mDecoder);
// Begin recording telemetry data.
mStartTime = TimeStamp::Now();
mDecoder->mChunkCount++;
// Keep track of the total number of bytes written.
mDecoder->mBytesDecoded += aByteCount;
}
~AutoRecordDecoderTelemetry()
{
// Finish telemetry.
mDecoder->mDecodeTime += (TimeStamp::Now() - mStartTime);
}
private:
Decoder* mDecoder;
TimeStamp mStartTime;
};
Decoder::Decoder(RasterImage* aImage)
: mImageData(nullptr)
, mImageDataLength(0)
@ -142,18 +170,10 @@ Decoder::Write(const char* aBuffer, uint32_t aCount)
MOZ_ASSERT(aBuffer);
MOZ_ASSERT(aCount > 0);
// Begin recording telemetry data.
TimeStamp start = TimeStamp::Now();
mChunkCount++;
// Keep track of the total number of bytes written.
mBytesDecoded += aCount;
AutoRecordDecoderTelemetry telemetry(this, aCount);
// Pass the data along to the implementation.
WriteInternal(aBuffer, aCount);
// Finish telemetry.
mDecodeTime += (TimeStamp::Now() - start);
}
void

View File

@ -272,6 +272,7 @@ public:
protected:
friend class AutoRecordDecoderTelemetry;
friend class nsICODecoder;
friend class PalettedSurfaceSink;
friend class SurfaceSink;