Bug 1730020 - part2 : add profiler markers to show additional information. r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D126148
This commit is contained in:
alwu 2021-10-04 22:30:10 +00:00
Родитель ef02e7ebc4
Коммит 929314f612
4 изменённых файлов: 87 добавлений и 9 удалений

Просмотреть файл

@ -160,6 +160,7 @@ const presets = {
"ModuleProcessThread", "ModuleProcessThread",
"NativeAudioCallback", "NativeAudioCallback",
"PacerThread", "PacerThread",
"RemVidChild",
"RenderBackend", "RenderBackend",
"Renderer", "Renderer",
"SwComposite", "SwComposite",

Просмотреть файл

@ -11,14 +11,17 @@
#include <queue> #include <queue>
#include "AllocationPolicy.h" #include "AllocationPolicy.h"
#include "AOMDecoder.h"
#include "DecoderBenchmark.h" #include "DecoderBenchmark.h"
#include "MediaData.h" #include "MediaData.h"
#include "MediaDataDecoderProxy.h" #include "MediaDataDecoderProxy.h"
#include "MediaInfo.h" #include "MediaInfo.h"
#include "MP4Decoder.h"
#include "PDMFactory.h" #include "PDMFactory.h"
#include "PerformanceRecorder.h" #include "PerformanceRecorder.h"
#include "VideoFrameContainer.h" #include "VideoFrameContainer.h"
#include "VideoUtils.h" #include "VideoUtils.h"
#include "VPXDecoder.h"
#include "mozilla/AbstractThread.h" #include "mozilla/AbstractThread.h"
#include "mozilla/CDMProxy.h" #include "mozilla/CDMProxy.h"
#include "mozilla/ClearOnShutdown.h" #include "mozilla/ClearOnShutdown.h"
@ -1887,8 +1890,25 @@ void MediaFormatReader::DecodeDemuxedSamples(TrackType aTrack,
aTrack == TrackInfo::kVideoTrack aTrack == TrackInfo::kVideoTrack
? decoder.GetCurrentInfo()->GetAsVideoInfo()->mImage.height ? decoder.GetCurrentInfo()->GetAsVideoInfo()->mImage.height
: 0; : 0;
MediaInfoFlag flag = MediaInfoFlag::None;
flag |=
aSample->mKeyframe ? MediaInfoFlag::KeyFrame : MediaInfoFlag::NonKeyFrame;
if (aTrack == TrackInfo::kVideoTrack) {
flag |= VideoIsHardwareAccelerated() ? MediaInfoFlag::HardwareDecoding
: MediaInfoFlag::SoftwareDecoding;
const nsCString& mimeType = decoder.GetCurrentInfo()->mMimeType;
if (MP4Decoder::IsH264(mimeType)) {
flag |= MediaInfoFlag::VIDEO_H264;
} else if (VPXDecoder::IsVPX(mimeType, VPXDecoder::VP8)) {
flag |= MediaInfoFlag::VIDEO_VP8;
} else if (VPXDecoder::IsVPX(mimeType, VPXDecoder::VP9)) {
flag |= MediaInfoFlag::VIDEO_VP9;
} else if (AOMDecoder::IsAV1(mimeType)) {
flag |= MediaInfoFlag::VIDEO_AV1;
}
}
PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::RequestDecode, PerformanceRecorder perfRecorder(PerformanceRecorder::Stage::RequestDecode,
height); height, flag);
perfRecorder.Start(); perfRecorder.Start();
decoder.mDecoder->Decode(aSample) decoder.mDecoder->Decode(aSample)
->Then( ->Then(

Просмотреть файл

@ -7,6 +7,7 @@
#include "PerformanceRecorder.h" #include "PerformanceRecorder.h"
#include "mozilla/Logging.h" #include "mozilla/Logging.h"
#include "mozilla/ProfilerMarkers.h"
#include "nsString.h" #include "nsString.h"
namespace mozilla { namespace mozilla {
@ -51,10 +52,17 @@ const char* FindMediaResolution(int32_t aHeight) {
return resolution; return resolution;
} }
static TimeStamp GetCurrentTimeForMeasurement() {
// The system call to get the clock is rather expensive on Windows. As we
// only report the measurement report via markers, if the marker isn't enabled
// then we won't do any measurement in order to save CPU time.
return profiler_can_accept_markers() ? TimeStamp::Now() : TimeStamp();
}
void PerformanceRecorder::Start() { void PerformanceRecorder::Start() {
MOZ_ASSERT(mStage != Stage::Invalid); MOZ_ASSERT(mStage != Stage::Invalid);
MOZ_ASSERT(!mStartTime); MOZ_ASSERT(!mStartTime);
mStartTime = Some(TimeStamp::Now()); mStartTime = Some(GetCurrentTimeForMeasurement());
} }
void PerformanceRecorder::Reset() { void PerformanceRecorder::Reset() {
@ -62,13 +70,44 @@ void PerformanceRecorder::Reset() {
mStage = Stage::Invalid; mStage = Stage::Invalid;
} }
void AppendMediaInfoFlagToName(nsCString& aName, MediaInfoFlag aFlag) {
if (aFlag & MediaInfoFlag::KeyFrame) {
aName.Append("kf,");
}
// Decoding
if (aFlag & MediaInfoFlag::SoftwareDecoding) {
aName.Append("sw,");
} else if (aFlag & MediaInfoFlag::HardwareDecoding) {
aName.Append("hw,");
}
// Codec type
if (aFlag & MediaInfoFlag::VIDEO_AV1) {
aName.Append("av1,");
} else if (aFlag & MediaInfoFlag::VIDEO_H264) {
aName.Append("h264,");
} else if (aFlag & MediaInfoFlag::VIDEO_VP8) {
aName.Append("vp8,");
} else if (aFlag & MediaInfoFlag::VIDEO_VP9) {
aName.Append("vp9,");
}
}
void PerformanceRecorder::End() { void PerformanceRecorder::End() {
if (mStartTime) { if (mStartTime && !mStartTime->IsNull()) {
MOZ_ASSERT(mStage != Stage::Invalid); MOZ_ASSERT(mStage != Stage::Invalid);
const double passedTimeUs = if (profiler_can_accept_markers()) {
(TimeStamp::Now() - *mStartTime).ToMicroseconds(); const auto now = TimeStamp::Now();
MOZ_ASSERT(passedTimeUs > 0, "Passed time can't be less than 0!"); const double passedTimeUs = (now - *mStartTime).ToMicroseconds();
// TODO : report the time in following patches. MOZ_ASSERT(passedTimeUs > 0, "Passed time can't be less than 0!");
nsAutoCString name(StageToStr(mStage));
name.Append(":");
name.Append(FindMediaResolution(mHeight));
name.Append(":");
AppendMediaInfoFlagToName(name, mFlag);
PROFILER_MARKER_UNTYPED(
name, MEDIA_PLAYBACK,
MarkerOptions(MarkerTiming::Interval(*mStartTime, now)));
}
Reset(); Reset();
} }
} }

Просмотреть файл

@ -10,10 +10,24 @@
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/Maybe.h" #include "mozilla/Maybe.h"
#include "mozilla/TimeStamp.h" #include "mozilla/TimeStamp.h"
#include "mozilla/TypedEnumBits.h"
#include "nsStringFwd.h" #include "nsStringFwd.h"
namespace mozilla { namespace mozilla {
enum class MediaInfoFlag : uint16_t {
None = (0 << 0),
NonKeyFrame = (1 << 0),
KeyFrame = (1 << 1),
SoftwareDecoding = (1 << 2),
HardwareDecoding = (1 << 3),
VIDEO_AV1 = (1 << 4),
VIDEO_H264 = (1 << 5),
VIDEO_VP8 = (1 << 6),
VIDEO_VP9 = (1 << 7),
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaInfoFlag)
/** /**
* This class is used to record the passed time on the different stages in the * This class is used to record the passed time on the different stages in the
* media playback pipeline. It needs to call `Start()` and `End()` explicitly * media playback pipeline. It needs to call `Start()` and `End()` explicitly
@ -65,14 +79,16 @@ class PerformanceRecorder {
CopyDecodedVideo, CopyDecodedVideo,
}; };
explicit PerformanceRecorder(Stage aStage, int32_t aHeight = 0) explicit PerformanceRecorder(Stage aStage, int32_t aHeight = 0,
: mStage(aStage), mHeight(aHeight) {} MediaInfoFlag aFlag = MediaInfoFlag::None)
: mStage(aStage), mHeight(aHeight), mFlag(aFlag) {}
~PerformanceRecorder() = default; ~PerformanceRecorder() = default;
PerformanceRecorder(PerformanceRecorder&& aRhs) noexcept { PerformanceRecorder(PerformanceRecorder&& aRhs) noexcept {
mStage = aRhs.mStage; mStage = aRhs.mStage;
mHeight = aRhs.mHeight; mHeight = aRhs.mHeight;
mStartTime = std::move(aRhs.mStartTime); mStartTime = std::move(aRhs.mStartTime);
mFlag = aRhs.mFlag;
aRhs.mStage = Stage::Invalid; aRhs.mStage = Stage::Invalid;
} }
@ -81,6 +97,7 @@ class PerformanceRecorder {
mStage = aRhs.mStage; mStage = aRhs.mStage;
mHeight = aRhs.mHeight; mHeight = aRhs.mHeight;
mStartTime = std::move(aRhs.mStartTime); mStartTime = std::move(aRhs.mStartTime);
mFlag = aRhs.mFlag;
aRhs.mStage = Stage::Invalid; aRhs.mStage = Stage::Invalid;
return *this; return *this;
} }
@ -96,6 +113,7 @@ class PerformanceRecorder {
Stage mStage = Stage::Invalid; Stage mStage = Stage::Invalid;
int32_t mHeight; int32_t mHeight;
MediaInfoFlag mFlag = MediaInfoFlag::None;
Maybe<TimeStamp> mStartTime; Maybe<TimeStamp> mStartTime;
}; };