MediaProfilerMarkers.h (11481B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "mozilla/BaseProfilerMarkersPrerequisites.h" 6 #include "mozilla/Flow.h" 7 #include "mozilla/ProfilerMarkers.h" 8 9 namespace mozilla { 10 11 // Following markers are used for HTMLMediaElement 12 13 struct TimeUpdateMarker : public BaseMarkerType<TimeUpdateMarker> { 14 static constexpr const char* Name = "HTMLMediaElement:Timeupdate"; 15 static constexpr const char* Description = 16 "A marker shows the current playback position"; 17 18 using MS = MarkerSchema; 19 static constexpr MS::PayloadField PayloadFields[] = { 20 {"currentTimeMs", MS::InputType::Uint64, "Current Time (Ms)", 21 MS::Format::Milliseconds}, 22 {"mediaDurationMs", MS::InputType::Uint64, "Media Duration (Ms)", 23 MS::Format::Milliseconds}, 24 {"paintedFrames", MS::InputType::Uint32, "Painted Frames", 25 MS::Format::Integer}, // optional, zero for audio 26 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 27 MS::PayloadFlags::Searchable}, 28 }; 29 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 30 MS::Location::MarkerTable}; 31 static constexpr const char* ChartLabel = "{marker.data.name}"; 32 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 33 uint64_t aCurrentTime, uint64_t aDuration, 34 uint32_t aPaintedFrames, Flow aFlow) { 35 aWriter.IntProperty("currentTimeMs", aCurrentTime); 36 aWriter.IntProperty("mediaDurationMs", aDuration); 37 if (aPaintedFrames != 0) { 38 aWriter.IntProperty("paintedFrames", aPaintedFrames); 39 } 40 aWriter.FlowProperty("element", aFlow); 41 } 42 }; 43 44 struct BufferedUpdateMarker : public BaseMarkerType<BufferedUpdateMarker> { 45 static constexpr const char* Name = "HTMLMediaElement:BufferedUpdate"; 46 static constexpr const char* Description = 47 "A marker shows the current buffered ranges"; 48 49 using MS = MarkerSchema; 50 static constexpr MS::PayloadField PayloadFields[] = { 51 {"bufferStartMs", MS::InputType::Uint64, "Buffer Start (Ms)", 52 MS::Format::Milliseconds}, 53 {"bufferEndMs", MS::InputType::Uint64, "Buffer End (Ms)", 54 MS::Format::Milliseconds}, 55 {"mediaDurationMs", MS::InputType::Uint64, "Media Duration (Ms)", 56 MS::Format::Milliseconds}, 57 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 58 MS::PayloadFlags::Searchable}, 59 }; 60 61 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 62 MS::Location::MarkerTable}; 63 static constexpr const char* ChartLabel = "{marker.data.name}"; 64 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 65 uint64_t aBufferStart, uint64_t aBufferEnd, 66 uint64_t aDuration, Flow aFlow) { 67 aWriter.IntProperty("bufferStartMs", aBufferStart); 68 aWriter.IntProperty("bufferEndMs", aBufferEnd); 69 aWriter.IntProperty("mediaDurationMs", aDuration); 70 aWriter.FlowProperty("element", aFlow); 71 } 72 }; 73 74 struct VideoResizeMarker : public BaseMarkerType<VideoResizeMarker> { 75 static constexpr const char* Name = "HTMLMediaElement:VideoResize"; 76 static constexpr const char* Description = 77 "A marker shows the current displayed size of the video element"; 78 79 using MS = MarkerSchema; 80 static constexpr MS::PayloadField PayloadFields[] = { 81 {"width", MS::InputType::Uint64, "Width", MS::Format::Integer}, 82 {"height", MS::InputType::Uint64, "Height", MS::Format::Integer}, 83 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 84 MS::PayloadFlags::Searchable}, 85 }; 86 87 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 88 MS::Location::MarkerTable}; 89 static constexpr const char* ChartLabel = "{marker.data.name}"; 90 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 91 uint64_t aWidth, uint64_t aHeight, 92 Flow aFlow) { 93 aWriter.IntProperty("width", aWidth); 94 aWriter.IntProperty("height", aHeight); 95 aWriter.FlowProperty("element", aFlow); 96 } 97 }; 98 99 struct MetadataMarker : public BaseMarkerType<MetadataMarker> { 100 static constexpr const char* Name = "HTMLMediaElement:MetadataLoaded"; 101 static constexpr const char* Description = 102 "A marker shows the current metadata of the video element"; 103 104 using MS = MarkerSchema; 105 static constexpr MS::PayloadField PayloadFields[] = { 106 {"src", MS::InputType::String, "Source URL", MS::Format::String}, 107 {"audioMimeType", MS::InputType::CString, "Audio Mimetype", 108 MS::Format::String}, 109 {"videoMimeType", MS::InputType::CString, "Video Mimetype", 110 MS::Format::String}, 111 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 112 MS::PayloadFlags::Searchable}, 113 }; 114 115 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 116 MS::Location::MarkerTable}; 117 static constexpr const char* ChartLabel = "{marker.data.name}"; 118 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 119 const ProfilerString16View& aSrc, 120 const ProfilerString8View& aAudioMimeType, 121 const ProfilerString8View& aVideoMimeType, 122 Flow aFlow) { 123 StreamJSONMarkerDataImpl(aWriter, aSrc, aAudioMimeType, aVideoMimeType, 124 aFlow); 125 } 126 }; 127 128 struct CDMResolvedMarker : public BaseMarkerType<CDMResolvedMarker> { 129 static constexpr const char* Name = "HTMLMediaElement:CDMResolved"; 130 static constexpr const char* Description = 131 "A marker shows the supported config for a resolved CDM"; 132 133 using MS = MarkerSchema; 134 static constexpr MS::PayloadField PayloadFields[] = { 135 {"keySystem", MS::InputType::String, "Key System", MS::Format::String}, 136 {"configuration", MS::InputType::CString, "Configuration", 137 MS::Format::String}, 138 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 139 MS::PayloadFlags::Searchable}, 140 }; 141 142 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 143 MS::Location::MarkerTable}; 144 static constexpr const char* ChartLabel = "{marker.data.name}"; 145 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 146 const ProfilerString16View& aKeySystem, 147 const ProfilerString8View& aConfiguration, 148 Flow aFlow) { 149 StreamJSONMarkerDataImpl(aWriter, aKeySystem, aConfiguration, aFlow); 150 } 151 }; 152 153 struct LoadErrorMarker : public BaseMarkerType<LoadErrorMarker> { 154 static constexpr const char* Name = "HTMLMediaElement:Error"; 155 static constexpr const char* Description = 156 "A marker shows the detail of the load error"; 157 158 using MS = MarkerSchema; 159 static constexpr MS::PayloadField PayloadFields[] = { 160 {"errorMessage", MS::InputType::CString, "Error Message", 161 MS::Format::String}, 162 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 163 MS::PayloadFlags::Searchable}, 164 }; 165 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 166 MS::Location::MarkerTable}; 167 static constexpr const char* ChartLabel = "{marker.data.name}"; 168 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 169 const ProfilerString8View& aErrorMsg, 170 Flow aFlow) { 171 StreamJSONMarkerDataImpl(aWriter, aErrorMsg, aFlow); 172 } 173 }; 174 175 struct ErrorMarker : public BaseMarkerType<ErrorMarker> { 176 static constexpr const char* Name = "HTMLMediaElement:Error"; 177 static constexpr const char* Description = 178 "A marker shows the detail of the error"; 179 180 using MS = MarkerSchema; 181 static constexpr MS::PayloadField PayloadFields[] = { 182 {"errorMessage", MS::InputType::String, "Error Message", 183 MS::Format::String}, 184 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 185 MS::PayloadFlags::Searchable}, 186 }; 187 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 188 MS::Location::MarkerTable}; 189 static constexpr const char* ChartLabel = "{marker.data.name}"; 190 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 191 const ProfilerString16View& aErrorMsg, 192 Flow aFlow) { 193 StreamJSONMarkerDataImpl(aWriter, aErrorMsg, aFlow); 194 } 195 }; 196 197 struct LoadSourceMarker : public BaseMarkerType<LoadSourceMarker> { 198 static constexpr const char* Name = "HTMLMediaElement:LoadSource"; 199 static constexpr const char* Description = 200 "A marker shows the detail of the source a media element trying to load"; 201 202 using MS = MarkerSchema; 203 static constexpr MS::PayloadField PayloadFields[] = { 204 {"src", MS::InputType::String, "Source URL", MS::Format::String}, 205 // Below attributes would only be set if the source if a source element 206 {"contentType", MS::InputType::String, "Content Type", 207 MS::Format::String}, 208 {"media", MS::InputType::String, "Media", MS::Format::String}, 209 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 210 MS::PayloadFlags::Searchable}, 211 }; 212 213 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 214 MS::Location::MarkerTable}; 215 static constexpr const char* ChartLabel = "{marker.data.name}"; 216 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 217 const ProfilerString16View& aSrc, 218 const ProfilerString16View& aType, 219 const ProfilerString16View& aMedia, 220 Flow aFlow) { 221 StreamJSONMarkerDataImpl(aWriter, aSrc, aType, aMedia, aFlow); 222 } 223 }; 224 225 // This marker is for HTMLVideoElement 226 struct RenderVideoMarker : public BaseMarkerType<RenderVideoMarker> { 227 static constexpr const char* Name = "HTMLMediaElement:RenderVideo"; 228 static constexpr const char* Description = 229 "A marker shows how many video frames has been painted"; 230 231 using MS = MarkerSchema; 232 static constexpr MS::PayloadField PayloadFields[] = { 233 {"paintedFrames", MS::InputType::Uint64, "Painted Frames", 234 MS::Format::Integer}, 235 {"element", MS::InputType::Uint64, "Element", MS::Format::Flow, 236 MS::PayloadFlags::Searchable}, 237 }; 238 static constexpr MS::Location Locations[] = {MS::Location::MarkerChart, 239 MS::Location::MarkerTable}; 240 static constexpr const char* ChartLabel = "{marker.data.name}"; 241 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, 242 uint64_t aPaintedFrames, Flow aFlow) { 243 aWriter.IntProperty("paintedFrames", aPaintedFrames); 244 aWriter.FlowProperty("element", aFlow); 245 } 246 }; 247 248 } // namespace mozilla