Skip to content

Commit 252ebaa

Browse files
cshungmrsharm
andauthored
Truly Dynamic Event (dotnet#4274)
Changes - Upgrade TraceEvent dependencies from 3.1.7 to 3.1.9 - Allow using custom TraceEvent library, built some support for using it - Parse DynamicEvent and allow them to be accessed in the Notebooks. Cleanup - Run dotnet-format on the source code - Ignore xlf files - Deleted unwanted (and failing) outputs from Notebook examples. --------- Co-authored-by: Mukund Raghav Sharma (Moko) <[email protected]>
1 parent d8f4165 commit 252ebaa

File tree

67 files changed

+1481
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1481
-712
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ ClientBin/
258258
*.jfm
259259
*.publishsettings
260260
orleans.codegen.cs
261+
*.xlf
261262

262263
# Including strong name files can present a security risk
263264
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
using FluentAssertions;
2+
using Microsoft.Diagnostics.Tracing.Analysis.GC;
3+
using Microsoft.Diagnostics.Tracing.Parsers.GCDynamic;
4+
using GC.Analysis.API.DynamicEvents;
5+
using System.Reflection;
6+
7+
namespace GC.Analysis.API.UnitTests
8+
{
9+
[TestClass]
10+
public class DynamicEventTests
11+
{
12+
[TestMethod]
13+
public void TestDuplicatedSchema()
14+
{
15+
Action test = () =>
16+
{
17+
DynamicEventSchema.Set(
18+
new List<DynamicEventSchema>
19+
{
20+
new DynamicEventSchema
21+
{
22+
DynamicEventName = "SampleEventName",
23+
Fields = new List<KeyValuePair<string, Type>>
24+
{
25+
new KeyValuePair<string, Type>("version", typeof(ushort)),
26+
new KeyValuePair<string, Type>("Number", typeof(ulong)),
27+
}
28+
},
29+
new DynamicEventSchema
30+
{
31+
DynamicEventName = "SampleEventName",
32+
Fields = new List<KeyValuePair<string, Type>>
33+
{
34+
new KeyValuePair<string, Type>("version", typeof(ushort)),
35+
new KeyValuePair<string, Type>("Number", typeof(ulong)),
36+
}
37+
}
38+
}
39+
);
40+
};
41+
test.Should().Throw<Exception>();
42+
}
43+
44+
[TestMethod]
45+
public void TestDuplicatedFields()
46+
{
47+
Action test = () =>
48+
{
49+
DynamicEventSchema.Set(
50+
new List<DynamicEventSchema>
51+
{
52+
new DynamicEventSchema
53+
{
54+
DynamicEventName = "SampleEventName",
55+
Fields = new List<KeyValuePair<string, Type>>
56+
{
57+
new KeyValuePair<string, Type>("version", typeof(ushort)),
58+
new KeyValuePair<string, Type>("version", typeof(ulong)),
59+
}
60+
},
61+
}
62+
);
63+
};
64+
test.Should().Throw<Exception>();
65+
}
66+
67+
[TestMethod]
68+
public void TestUnsupportedType()
69+
{
70+
Action test = () =>
71+
{
72+
DynamicEventSchema.Set(
73+
new List<DynamicEventSchema>
74+
{
75+
new DynamicEventSchema
76+
{
77+
DynamicEventName = "SampleEventName",
78+
Fields = new List<KeyValuePair<string, Type>>
79+
{
80+
new KeyValuePair<string, Type>("version", typeof(DateTime)),
81+
}
82+
},
83+
}
84+
);
85+
};
86+
test.Should().Throw<Exception>();
87+
}
88+
89+
[TestMethod]
90+
public void TestNegativeMinOccurrence()
91+
{
92+
Action test = () =>
93+
{
94+
DynamicEventSchema.Set(
95+
new List<DynamicEventSchema>
96+
{
97+
new DynamicEventSchema
98+
{
99+
DynamicEventName = "SampleEventName",
100+
MinOccurrence = -1,
101+
Fields = new List<KeyValuePair<string, Type>>
102+
{
103+
new KeyValuePair<string, Type>("version", typeof(ushort)),
104+
}
105+
},
106+
}
107+
);
108+
};
109+
test.Should().Throw<Exception>();
110+
}
111+
112+
[TestMethod]
113+
public void TestSmallerMaxOccurrence()
114+
{
115+
Action test = () =>
116+
{
117+
DynamicEventSchema.Set(
118+
new List<DynamicEventSchema>
119+
{
120+
new DynamicEventSchema
121+
{
122+
DynamicEventName = "SampleEventName",
123+
MinOccurrence = 1,
124+
MaxOccurrence = 0,
125+
Fields = new List<KeyValuePair<string, Type>>
126+
{
127+
new KeyValuePair<string, Type>("version", typeof(ushort)),
128+
}
129+
},
130+
}
131+
);
132+
};
133+
test.Should().Throw<Exception>();
134+
}
135+
136+
private List<DynamicEventSchema> correctSingleSchema = new List<DynamicEventSchema>
137+
{
138+
new DynamicEventSchema
139+
{
140+
DynamicEventName = "SampleEventName",
141+
MinOccurrence = 1,
142+
Fields = new List<KeyValuePair<string, Type>>
143+
{
144+
new KeyValuePair<string, Type>("version", typeof(ushort)),
145+
new KeyValuePair<string, Type>("Number", typeof(ulong)),
146+
}
147+
},
148+
};
149+
150+
private DynamicEvent sampleEvent = new DynamicEvent(
151+
"SampleEventName",
152+
DateTime.Now,
153+
new byte[] { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0 }
154+
);
155+
156+
private DynamicEvent unknownEvent = new DynamicEvent(
157+
"UnknownEventName",
158+
DateTime.Now,
159+
new byte[] { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0 }
160+
);
161+
162+
[TestMethod]
163+
public void TestMissedSingleEvent()
164+
{
165+
DynamicEventSchema.Set(correctSingleSchema);
166+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>();
167+
Action test = () =>
168+
{
169+
dynamic index = new DynamicIndex(dynamicEvents);
170+
};
171+
test.Should().Throw<Exception>();
172+
}
173+
174+
[TestMethod]
175+
public void TestDuplicatedSingleEvent()
176+
{
177+
DynamicEventSchema.Set(correctSingleSchema);
178+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>
179+
{
180+
sampleEvent,
181+
sampleEvent
182+
};
183+
Action test = () =>
184+
{
185+
dynamic index = new DynamicIndex(dynamicEvents);
186+
};
187+
test.Should().Throw<Exception>();
188+
}
189+
190+
[TestMethod]
191+
public void TestSingleEvent()
192+
{
193+
DynamicEventSchema.Set(correctSingleSchema);
194+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>
195+
{
196+
sampleEvent
197+
};
198+
dynamic index = new DynamicIndex(dynamicEvents);
199+
200+
((int)index.SampleEventName.version).Should().Be(1);
201+
((int)index.SampleEventName.Number).Should().Be(2);
202+
string pattern = @"
203+
SampleEventName
204+
version : 1
205+
Number : 2
206+
TimeStamp : *
207+
".Trim();
208+
((string)index.SampleEventName.ToString()).Should().Match(pattern);
209+
}
210+
211+
private List<DynamicEventSchema> correctMultipleSchema = new List<DynamicEventSchema>
212+
{
213+
new DynamicEventSchema
214+
{
215+
DynamicEventName = "SampleEventName",
216+
MinOccurrence = 1,
217+
MaxOccurrence = 2,
218+
Fields = new List<KeyValuePair<string, Type>>
219+
{
220+
new KeyValuePair<string, Type>("version", typeof(ushort)),
221+
new KeyValuePair<string, Type>("Number", typeof(ulong)),
222+
}
223+
},
224+
};
225+
226+
[TestMethod]
227+
public void TestMissedMultipleEvent()
228+
{
229+
DynamicEventSchema.Set(correctMultipleSchema);
230+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>();
231+
Action test = () =>
232+
{
233+
dynamic index = new DynamicIndex(dynamicEvents);
234+
};
235+
test.Should().Throw<Exception>();
236+
}
237+
238+
[TestMethod]
239+
public void TestTooManyMultipleEvents()
240+
{
241+
DynamicEventSchema.Set(correctMultipleSchema);
242+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>
243+
{
244+
sampleEvent,
245+
sampleEvent,
246+
sampleEvent,
247+
};
248+
Action test = () =>
249+
{
250+
dynamic index = new DynamicIndex(dynamicEvents);
251+
};
252+
test.Should().Throw<Exception>();
253+
}
254+
255+
[TestMethod]
256+
public void TestMultipleEvents()
257+
{
258+
DynamicEventSchema.Set(correctMultipleSchema);
259+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>
260+
{
261+
sampleEvent,
262+
sampleEvent,
263+
};
264+
dynamic index = new DynamicIndex(dynamicEvents);
265+
266+
((int)index.SampleEventName[0].version).Should().Be(1);
267+
((int)index.SampleEventName[0].Number).Should().Be(2);
268+
((int)index.SampleEventName[1].version).Should().Be(1);
269+
((int)index.SampleEventName[1].Number).Should().Be(2);
270+
}
271+
272+
[TestMethod]
273+
public void TestOptionalEvent()
274+
{
275+
DynamicEventSchema.Set(
276+
new List<DynamicEventSchema>
277+
{
278+
new DynamicEventSchema
279+
{
280+
DynamicEventName = "SampleEventName",
281+
Fields = new List<KeyValuePair<string, Type>>
282+
{
283+
new KeyValuePair<string, Type>("version", typeof(ushort)),
284+
new KeyValuePair<string, Type>("Number", typeof(ulong)),
285+
}
286+
},
287+
}
288+
);
289+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>();
290+
dynamic index = new DynamicIndex(dynamicEvents);
291+
((bool)(index.SampleEventName == null)).Should().Be(true);
292+
}
293+
294+
[TestMethod]
295+
public void TestForgivingUnknownEvent()
296+
{
297+
DynamicEventSchema.Set(correctSingleSchema);
298+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>
299+
{
300+
sampleEvent,
301+
unknownEvent
302+
};
303+
dynamic index = new DynamicIndex(dynamicEvents);
304+
// As long as we don't throw exception, this is forgiving.
305+
}
306+
307+
[TestMethod]
308+
public void TestReportingUnknownEvent()
309+
{
310+
DynamicEventSchema.Set(correctSingleSchema, false);
311+
List<DynamicEvent> dynamicEvents = new List<DynamicEvent>
312+
{
313+
sampleEvent,
314+
unknownEvent
315+
};
316+
Action test = () =>
317+
{
318+
dynamic index = new DynamicIndex(dynamicEvents);
319+
};
320+
test.Should().Throw<Exception>();
321+
}
322+
}
323+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
8+
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
9+
<IsPackable>false</IsPackable>
10+
</PropertyGroup>
11+
12+
<Import Project="../Versions.props" />
13+
14+
<ItemGroup>
15+
<PackageReference Include="FluentAssertions" Version="6.0.0-beta0003" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
17+
<PackageReference Condition="'$(CustomTraceEvent)' != 'true'" Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.9" />
18+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
19+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
20+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
21+
</ItemGroup>
22+
23+
<ItemGroup Condition="'$(CustomTraceEvent)' == 'true'">
24+
<Reference Include="Microsoft.Diagnostics.FastSerialization.dll">
25+
<HintPath>$(PerfViewPath)\src\FastSerialization\bin\Release\netstandard2.0\Microsoft.Diagnostics.FastSerialization.dll</HintPath>
26+
</Reference>
27+
<Reference Include="Microsoft.Diagnostics.Tracing.TraceEvent">
28+
<HintPath>$(PerfViewPath)\src\TraceEvent\bin\Release\netstandard2.0\Microsoft.Diagnostics.Tracing.TraceEvent.dll</HintPath>
29+
</Reference>
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<ProjectReference Include="..\GC.Analysis.API\GC.Analysis.API.csproj" />
34+
</ItemGroup>
35+
36+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Microsoft.VisualStudio.TestTools.UnitTesting;

src/benchmarks/gc/GC.Infrastructure/GC.Analysis.API.sln

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GC.Infrastructure.Core", "G
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GC.Infrastructure.Core.UnitTests", "GC.Infrastructure.Core.UnitTests\GC.Infrastructure.Core.UnitTests.csproj", "{61F3DF76-A933-44AE-B5FF-B7909ED21999}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GC.Infrastructure", "GC.Infrastructure\GC.Infrastructure.csproj", "{7B2B6934-0DBD-45E0-9563-AE9DC8EBD538}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GC.Infrastructure", "GC.Infrastructure\GC.Infrastructure.csproj", "{7B2B6934-0DBD-45E0-9563-AE9DC8EBD538}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GC.Analysis.API.UnitTests", "GC.Analysis.API.UnitTests\GC.Analysis.API.UnitTests.csproj", "{A7D40245-CF5C-437E-B7E7-278AEA02954D}"
1315
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,6 +35,10 @@ Global
3335
{7B2B6934-0DBD-45E0-9563-AE9DC8EBD538}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{7B2B6934-0DBD-45E0-9563-AE9DC8EBD538}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{7B2B6934-0DBD-45E0-9563-AE9DC8EBD538}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{A7D40245-CF5C-437E-B7E7-278AEA02954D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{A7D40245-CF5C-437E-B7E7-278AEA02954D}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{A7D40245-CF5C-437E-B7E7-278AEA02954D}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{A7D40245-CF5C-437E-B7E7-278AEA02954D}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)