44using System ;
55using System . Collections . Generic ;
66using System . Diagnostics ;
7+ using System . Linq ;
78using CtfPlayback ;
89using CtfPlayback . EventStreams . Interfaces ;
910using CtfPlayback . FieldValues ;
@@ -45,6 +46,7 @@ public virtual ICtfMetadataParser CreateMetadataParser(
4546
4647 public bool GetTimestampsFromPacketContext (
4748 ICtfPacket ctfPacket ,
49+ ICtfMetadata metadata ,
4850 out CtfTimestamp start ,
4951 out CtfTimestamp end )
5052 {
@@ -76,8 +78,8 @@ public bool GetTimestampsFromPacketContext(
7678 return false ;
7779 }
7880
79- start = new CtfTimestamp ( this . MetadataCustomization , startFieldInteger ) ;
80- end = new CtfTimestamp ( this . MetadataCustomization , endFieldInteger ) ;
81+ start = new CtfTimestamp ( this . MetadataCustomization , metadata , startFieldInteger ) ;
82+ end = new CtfTimestamp ( this . MetadataCustomization , metadata , endFieldInteger ) ;
8183 return true ;
8284 }
8385
@@ -86,7 +88,7 @@ public void RegisterEventCallback(Action<LTTngEvent, LTTngContext> eventCallback
8688 this . eventCallbacks . Add ( eventCallback ) ;
8789 }
8890
89- public virtual CtfTimestamp GetTimestampFromEventHeader ( ICtfEvent ctfEvent , CtfTimestamp previousTimestamp )
91+ public virtual CtfTimestamp GetTimestampFromEventHeader ( ICtfEvent ctfEvent , ICtfMetadata metadata , CtfTimestamp previousTimestamp )
9092 {
9193 var variantStruct = GetStreamEventHeaderStructure ( ctfEvent ) ;
9294 Debug . Assert ( variantStruct != null ) ;
@@ -107,7 +109,7 @@ public virtual CtfTimestamp GetTimestampFromEventHeader(ICtfEvent ctfEvent, CtfT
107109 // todo:I think we need to do something else for this case, especially if the integer size is < 64
108110 // not sure what yet. maybe base it on the clock's offset?
109111
110- return new CtfTimestamp ( this . MetadataCustomization , timestampInteger ) ;
112+ return new CtfTimestamp ( this . MetadataCustomization , metadata , timestampInteger ) ;
111113 }
112114
113115 // Timestamps aren't actually absolute values. To quote from CTF spec 1.8.2 section 8:
@@ -139,10 +141,10 @@ public virtual CtfTimestamp GetTimestampFromEventHeader(ICtfEvent ctfEvent, CtfT
139141 Debug . Assert ( newTimestamp > previous ) ;
140142 }
141143
142- return new CtfTimestamp ( this . MetadataCustomization , timestampInteger , newTimestamp ) ;
144+ return new CtfTimestamp ( this . MetadataCustomization , metadata , timestampInteger , newTimestamp ) ;
143145 }
144146
145- return new CtfTimestamp ( this . MetadataCustomization , timestampInteger ) ;
147+ return new CtfTimestamp ( this . MetadataCustomization , metadata , timestampInteger ) ;
146148 }
147149
148150 /// <inheritdoc />
@@ -218,20 +220,31 @@ public ulong GetPacketContentBitCount(ICtfPacket ctfPacket)
218220 }
219221
220222 /// <inheritdoc />
221- public ICtfEventDescriptor GetEventDescriptor (
222- ICtfEvent ctfEvent )
223+ public ICtfEventDescriptor GetEventDescriptor ( ICtfEvent ctfEvent , ICtfMetadata metadata )
223224 {
224225 uint id = this . GetEventId ( ctfEvent ) ;
225226
226- if ( ! this . metadataCustomization . LTTngMetadata . EventByEventId . TryGetValue ( id , out var eventDescriptor ) )
227+ ICtfEventDescriptor eventDescriptor ;
228+ if ( metadata is LTTngMetadata typedMetadata )
229+ {
230+ // optimization if we got our own typed metadata back
231+ // we check for success below
232+ typedMetadata . EventByEventId . TryGetValue ( id , out eventDescriptor ) ;
233+ }
234+ else
235+ {
236+ eventDescriptor = metadata . Events . FirstOrDefault ( x => x . Id == id ) ;
237+ }
238+
239+ if ( eventDescriptor == null )
227240 {
228241 throw new LTTngPlaybackException ( $ "Unable to find event descriptor for event id={ id } .") ;
229242 }
230243
231244 return eventDescriptor ;
232245 }
233246
234- public void ProcessEvent ( ICtfEvent ctfEvent , ICtfPacket eventPacket , ICtfTraceInput traceInput , ICtfInputStream ctfEventStream )
247+ public void ProcessEvent ( ICtfEvent ctfEvent , ICtfPacket eventPacket , ICtfTraceInput traceInput , ICtfInputStream ctfEventStream , ICtfMetadata metadata )
235248 {
236249 var eventDescriptor = ctfEvent . EventDescriptor as EventDescriptor ;
237250 Debug . Assert ( eventDescriptor != null ) ;
@@ -255,7 +268,7 @@ public void ProcessEvent(ICtfEvent ctfEvent, ICtfPacket eventPacket, ICtfTraceIn
255268
256269 if ( ! this . traceContexts . TryGetValue ( traceInput , out var traceContext ) )
257270 {
258- traceContext = new TraceContext ( this . metadataCustomization . LTTngMetadata ) ;
271+ traceContext = new TraceContext ( metadata ) ;
259272 this . traceContexts . Add ( traceInput , traceContext ) ;
260273 }
261274
0 commit comments