1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT license.
3
3
4
+ using System ;
4
5
using System . Collections . Generic ;
5
6
using CtfPlayback ;
6
7
using CtfPlayback . FieldValues ;
@@ -11,12 +12,44 @@ namespace LTTngDataExtensions.DataOutputTypes
11
12
{
12
13
public class EventKind
13
14
{
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 ; }
15
47
public uint Id { get ; }
16
48
public string EventName { get ; }
17
49
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 )
19
51
{
52
+ this . Domain = domain ;
20
53
this . Id = id ;
21
54
this . EventName = name ;
22
55
this . FieldNames = new List < string > ( fields . Count ) ;
@@ -25,6 +58,20 @@ public EventKind(uint id, string name, IReadOnlyList<CtfFieldValue> fields)
25
58
this . FieldNames . Add ( field . FieldName ) ;
26
59
}
27
60
}
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
+ }
28
75
}
29
76
30
77
public struct LTTngGenericEvent
@@ -43,10 +90,9 @@ public LTTngGenericEvent(LTTngEvent data, LTTngContext context)
43
90
this . CpuId = context . CurrentCpu ;
44
91
this . DiscardedEvents = data . DiscardedEvents ;
45
92
46
- if ( ! EventKind . RegisteredKinds . TryGetValue ( data . Id , out this . kind ) )
93
+ if ( ! EventKind . TryGetRegisteredKind ( context . Domain , data . Id , out this . kind ) )
47
94
{
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 ) ;
50
96
}
51
97
52
98
// As this is being written, all columns are of type 'T', so all rows are the same. For generic events,
0 commit comments