11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT license.
33
4+ using System ;
45using System . Collections . Generic ;
56using CtfPlayback ;
67using CtfPlayback . FieldValues ;
@@ -11,12 +12,44 @@ namespace LTTngDataExtensions.DataOutputTypes
1112{
1213 public class EventKind
1314 {
14- public static readonly Dictionary < uint , EventKind > RegisteredKinds = new Dictionary < uint , EventKind > ( ) ;
15+ private class Key
16+ {
17+ private string domain ;
18+ private uint id ;
19+
20+ public Key ( string domain , uint id )
21+ {
22+ this . domain = domain ?? string . Empty ;
23+ this . id = id ;
24+ }
25+
26+ public override bool Equals ( object obj )
27+ {
28+ if ( obj is Key key )
29+ {
30+ return domain . Equals ( key . domain ) && id . Equals ( key . id ) ;
31+ }
32+ else
33+ {
34+ return false ;
35+ }
36+ }
37+
38+ public override int GetHashCode ( )
39+ {
40+ int h1 = domain . GetHashCode ( ) ;
41+ int h2 = id . GetHashCode ( ) ;
42+ return ( ( h1 << 5 ) + h1 ) ^ h2 ;
43+ }
44+ }
45+
46+ public string Domain { get ; }
1547 public uint Id { get ; }
1648 public string EventName { get ; }
1749 public readonly List < string > FieldNames ;
18- public EventKind ( uint id , string name , IReadOnlyList < CtfFieldValue > fields )
50+ public EventKind ( string domain , uint id , string name , IReadOnlyList < CtfFieldValue > fields )
1951 {
52+ this . Domain = domain ;
2053 this . Id = id ;
2154 this . EventName = name ;
2255 this . FieldNames = new List < string > ( fields . Count ) ;
@@ -25,6 +58,20 @@ public EventKind(uint id, string name, IReadOnlyList<CtfFieldValue> fields)
2558 this . FieldNames . Add ( field . FieldName ) ;
2659 }
2760 }
61+
62+ private static readonly Dictionary < Key , EventKind > RegisteredKinds = new Dictionary < Key , EventKind > ( ) ;
63+
64+ public static bool TryGetRegisteredKind ( string domain , uint id , out EventKind kind )
65+ {
66+ return RegisteredKinds . TryGetValue ( new Key ( domain , id ) , out kind ) ;
67+ }
68+
69+ public static EventKind RegisterKind ( string domain , uint id , string name , IReadOnlyList < CtfFieldValue > fields )
70+ {
71+ EventKind kind = new EventKind ( domain , id , name , fields ) ;
72+ RegisteredKinds . Add ( new Key ( domain , id ) , kind ) ;
73+ return kind ;
74+ }
2875 }
2976
3077 public struct LTTngGenericEvent
@@ -43,10 +90,9 @@ public LTTngGenericEvent(LTTngEvent data, LTTngContext context)
4390 this . CpuId = context . CurrentCpu ;
4491 this . DiscardedEvents = data . DiscardedEvents ;
4592
46- if ( ! EventKind . RegisteredKinds . TryGetValue ( data . Id , out this . kind ) )
93+ if ( ! EventKind . TryGetRegisteredKind ( context . Domain , data . Id , out this . kind ) )
4794 {
48- this . kind = new EventKind ( data . Id , data . Name , payload . Fields ) ;
49- EventKind . RegisteredKinds . Add ( data . Id , this . kind ) ;
95+ this . kind = EventKind . RegisterKind ( context . Domain , data . Id , data . Name , payload . Fields ) ;
5096 }
5197
5298 // As this is being written, all columns are of type 'T', so all rows are the same. For generic events,
0 commit comments