Skip to content

Commit 81af315

Browse files
[release/9.0] Add NativeRuntimeEventSource metadata to NativeAot CoreLib (#106713)
* Add NativeRuntimeEventSource metadata to NativeAot CoreLib This is necessary to allow consumers to parse the payload. Delete unnecessary runtimeflavor argument of genRuntimeEventSources.py script. Fixes #105556 * Exclude unused keywords and events
1 parent 2f15b15 commit 81af315

File tree

6 files changed

+104
-52
lines changed

6 files changed

+104
-52
lines changed

src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,6 @@
302302
<ProjectReference Include="$(LibrariesProjectRoot)\System.Private.CoreLib\gen\System.Private.CoreLib.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
303303
</ItemGroup>
304304

305-
<ItemGroup>
306-
<!-- This is the T4 template service and is added by VS anytime you modify a T4 template. Required for .tt files. -->
307-
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
308-
</ItemGroup>
309-
310305
<Import Project="CreateRuntimeRootILLinkDescriptorFile.targets" />
311306

312307
<Target Name="CreateRuntimeRootIlLinkDescFile" BeforeTargets="CoreCompile" DependsOnTargets="_CreateILLinkRuntimeRootDescriptorFile" />
@@ -317,15 +312,15 @@
317312
<ItemGroup>
318313
<EventingGenerationScript Include="$(CoreClrProjectRoot)scripts/genRuntimeEventSources.py" />
319314
<EventManifestFile Include="$(CoreClrProjectRoot)vm/ClrEtwAll.man" />
320-
<EventingSourceFile Include="$(IntermediateOutputPath)..\..\..\Eventing\$(TargetArchitecture)\$(Configuration)\NativeRuntimeEventSource.CoreCLR.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
321-
<Link>src\System\Diagnostics\Eventing\Generated\NativeRuntimeEventSource.CoreCLR.cs</Link>
315+
<EventingSourceFile Include="$(IntermediateOutputPath)NativeRuntimeEventSource.Generated.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
316+
<Link>src\System\Diagnostics\Eventing\NativeRuntimeEventSource.Generated.cs</Link>
322317
</EventingSourceFile>
323318
<Compile Include="@(EventingSourceFile)" />
324319
</ItemGroup>
325320

326321
<Target Name="GenerateEventingFiles" Inputs="@(EventingGenerationScript);@(EventManifestFile)" Outputs="@(EventingSourceFile)" DependsOnTargets="FindPython" BeforeTargets="BeforeCompile">
327322

328-
<Error Condition="'$(PYTHON)' == ''" Text="Unable to locate Python. NativeRuntimeEventSource.CoreCLR.cs cannot be generated without Python installed on the machine. Either install Python in your path or point to it with the PYTHON environment variable." />
323+
<Error Condition="'$(PYTHON)' == ''" Text="Unable to locate Python. NativeRuntimeEventSource.Generated.cs cannot be generated without Python installed on the machine. Either install Python in your path or point to it with the PYTHON environment variable." />
329324
<PropertyGroup>
330325
<_PythonWarningParameter>-Wall</_PythonWarningParameter>
331326
<_PythonWarningParameter Condition="'$(MSBuildTreatWarningsAsErrors)' == 'true'">$(_PythonWarningParameter) -Werror</_PythonWarningParameter>

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,35 @@
571571
<ProjectReference Include="$(LibrariesProjectRoot)\System.Private.CoreLib\gen\System.Private.CoreLib.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
572572
</ItemGroup>
573573

574+
<!-- Setup eventing file generation -->
574575
<ItemGroup>
575-
<!-- This is the T4 template service and is added by VS anytime you modify a T4 template. Required for .tt files. -->
576-
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
576+
<EventingGenerationScript Include="$(CoreClrProjectRoot)scripts/genRuntimeEventSources.py" />
577+
<EventManifestFile Include="$(CoreClrProjectRoot)vm/ClrEtwAll.man" />
578+
<EventingInclusionList Include="$(CoreClrProjectRoot)nativeaot/Runtime/eventpipe/gen-eventing-event-inc.lst" />
579+
<EventingSourceFile Include="$(IntermediateOutputPath)NativeRuntimeEventSource.Generated.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
580+
<Link>src\System\Diagnostics\Eventing\NativeRuntimeEventSource.Generated.cs</Link>
581+
</EventingSourceFile>
582+
<Compile Include="@(EventingSourceFile)" />
577583
</ItemGroup>
584+
585+
<Target Name="GenerateEventingFiles"
586+
Inputs="@(EventingGenerationScript);@(EventManifestFile);@(EventingInclusionList)"
587+
Outputs="@(EventingSourceFile)"
588+
DependsOnTargets="FindPython"
589+
BeforeTargets="BeforeCompile">
590+
591+
<Error Condition="'$(PYTHON)' == ''" Text="Unable to locate Python. NativeRuntimeEventSource.Generared.cs cannot be generated without Python installed on the machine. Either install Python in your path or point to it with the PYTHON environment variable." />
592+
<PropertyGroup>
593+
<_PythonWarningParameter>-Wall</_PythonWarningParameter>
594+
<_PythonWarningParameter Condition="'$(MSBuildTreatWarningsAsErrors)' == 'true'">$(_PythonWarningParameter) -Werror</_PythonWarningParameter>
595+
<_EventingSourceFileDirectory>%(EventingSourceFile.RootDir)%(EventingSourceFile.Directory)</_EventingSourceFileDirectory>
596+
<_EventingSourceFileDirectory Condition="HasTrailingSlash('$(_EventingSourceFileDirectory)')">$(_EventingSourceFileDirectory.TrimEnd('\'))</_EventingSourceFileDirectory>
597+
</PropertyGroup>
598+
599+
<Exec Command="&quot;$(PYTHON)&quot; -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot; --inc &quot;@(EventingInclusionList)&quot;" />
600+
601+
<ItemGroup>
602+
<FileWrites Include="@(EventingSourceFile)" />
603+
</ItemGroup>
604+
</Target>
578605
</Project>

src/coreclr/scripts/genRuntimeEventSources.py

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
import os
77
import xml.dom.minidom as DOM
8-
from utilities import open_for_update
9-
from genEventing import RuntimeFlavor
8+
from utilities import open_for_update, parseInclusionList
109
import argparse
1110
import sys
1211

@@ -24,12 +23,8 @@
2423
########################################################################
2524
# START CONFIGURATION
2625
########################################################################
27-
coreCLRManifestsToGenerate = {
28-
"Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.CoreCLR.cs"
29-
}
30-
31-
monoManifestsToGenerate = {
32-
"Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.Mono.cs"
26+
manifestsToGenerate = {
27+
"Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.Generated.cs"
3328
}
3429

3530
providerNameToClassNameMap = {
@@ -77,11 +72,22 @@ def writeOutput(outputFile, str):
7772
def getCSharpTypeFromManifestType(manifestType):
7873
return manifestTypeToCSharpTypeMap[manifestType]
7974

80-
def getManifestsToGenerate(runtimeFlavor):
81-
if runtimeFlavor.coreclr:
82-
return coreCLRManifestsToGenerate
83-
elif runtimeFlavor.mono:
84-
return monoManifestsToGenerate
75+
def getManifestsToGenerate():
76+
return manifestsToGenerate
77+
78+
def includeEvent(inclusionList, providerName, eventName):
79+
if len(inclusionList) == 0:
80+
return True
81+
if providerName in inclusionList and eventName in inclusionList[providerName]:
82+
return True
83+
elif providerName in inclusionList and "*" in inclusionList[providerName]:
84+
return True
85+
elif "*" in inclusionList and eventName in inclusionList["*"]:
86+
return True
87+
elif "*" in inclusionList and "*" in inclusionList["*"]:
88+
return True
89+
else:
90+
return False
8591

8692
def generateEvent(eventNode, providerNode, outputFile, stringTable):
8793

@@ -174,7 +180,9 @@ def generateEvent(eventNode, providerNode, outputFile, stringTable):
174180
writeOutput(outputFile, "}\n\n")
175181

176182

177-
def generateEvents(providerNode, outputFile, stringTable):
183+
def generateEvents(providerNode, outputFile, stringTable, inclusion_list):
184+
185+
providerName = providerNode.getAttribute("name")
178186

179187
# Get the events element.
180188
for node in providerNode.getElementsByTagName("events"):
@@ -188,13 +196,21 @@ def generateEvents(providerNode, outputFile, stringTable):
188196
# key = eventID, value = version
189197
eventList = dict()
190198
for eventNode in eventNodes:
199+
eventName = eventNode.getAttribute('symbol')
200+
if not includeEvent(inclusion_list, providerName, eventName):
201+
continue
202+
191203
eventID = eventNode.getAttribute("value")
192204
eventVersion = eventNode.getAttribute("version")
193205
eventList[eventID] = eventVersion
194206

195207
# Iterate over each event node and process it.
196208
# Only emit events for the latest version of the event, otherwise EventSource initialization will fail.
197209
for eventNode in eventNodes:
210+
eventName = eventNode.getAttribute('symbol')
211+
if not includeEvent(inclusion_list, providerName, eventName):
212+
continue
213+
198214
eventID = eventNode.getAttribute("value")
199215
eventVersion = eventNode.getAttribute("version")
200216
if eventID in eventList and eventList[eventID] == eventVersion:
@@ -305,7 +321,29 @@ def generateEnumTypeMap(providerNode):
305321

306322
return typeMap
307323

308-
def generateKeywordsClass(providerNode, outputFile):
324+
def generateKeywordsClass(providerNode, outputFile, inclusion_list):
325+
326+
providerName = providerNode.getAttribute("name")
327+
328+
# Get the events element.
329+
for node in providerNode.getElementsByTagName("events"):
330+
eventsNode = node
331+
break
332+
333+
# Get the list of event nodes.
334+
eventNodes = eventsNode.getElementsByTagName("event")
335+
336+
# Build the list of used keywords
337+
keywordSet = set()
338+
for eventNode in eventNodes:
339+
eventName = eventNode.getAttribute('symbol')
340+
if not includeEvent(inclusion_list, providerName, eventName):
341+
continue
342+
343+
# Not all events have keywords specified, and some have multiple keywords specified.
344+
keywords = eventNode.getAttribute("keywords")
345+
if keywords:
346+
keywordSet = keywordSet.union(keywords.split())
309347

310348
# Find the keywords element.
311349
for node in providerNode.getElementsByTagName("keywords"):
@@ -317,7 +355,11 @@ def generateKeywordsClass(providerNode, outputFile):
317355
increaseTabLevel()
318356

319357
for keywordNode in keywordsNode.getElementsByTagName("keyword"):
320-
writeOutput(outputFile, "public const EventKeywords " + keywordNode.getAttribute("name") + " = (EventKeywords)" + keywordNode.getAttribute("mask") + ";\n")
358+
keywordName = keywordNode.getAttribute("name")
359+
if keywordName not in keywordSet:
360+
continue;
361+
362+
writeOutput(outputFile, "public const EventKeywords " + keywordName + " = (EventKeywords)" + keywordNode.getAttribute("mask") + ";\n")
321363

322364
decreaseTabLevel()
323365
writeOutput(outputFile, "}\n\n")
@@ -338,7 +380,7 @@ def loadStringTable(manifest):
338380

339381
return stringTable
340382

341-
def generateEventSources(manifestFullPath, intermediatesDirFullPath, runtimeFlavor):
383+
def generateEventSources(manifestFullPath, intermediatesDirFullPath, inclusion_list):
342384

343385
# Open the manifest for reading.
344386
manifest = DOM.parse(manifestFullPath)
@@ -347,7 +389,7 @@ def generateEventSources(manifestFullPath, intermediatesDirFullPath, runtimeFlav
347389
stringTable = loadStringTable(manifest)
348390

349391
# Iterate over each provider that we want to generate an EventSource for.
350-
for providerName, outputFileName in getManifestsToGenerate(runtimeFlavor).items():
392+
for providerName, outputFileName in getManifestsToGenerate().items():
351393
for node in manifest.getElementsByTagName("provider"):
352394
if node.getAttribute("name") == providerName:
353395
providerNode = node
@@ -379,7 +421,7 @@ def generateEventSources(manifestFullPath, intermediatesDirFullPath, runtimeFlav
379421
increaseTabLevel()
380422

381423
# Write the keywords class.
382-
generateKeywordsClass(providerNode, outputFile)
424+
generateKeywordsClass(providerNode, outputFile, inclusion_list)
383425

384426
#### Disable enums until they are needed ####
385427
# Generate the enum type map.
@@ -394,7 +436,7 @@ def generateEventSources(manifestFullPath, intermediatesDirFullPath, runtimeFlav
394436
#### Disable enums until they are needed ####
395437

396438
# Generate events.
397-
generateEvents(providerNode, outputFile, stringTable)
439+
generateEvents(providerNode, outputFile, stringTable, inclusion_list)
398440

399441
# Write the class footer.
400442
decreaseTabLevel()
@@ -413,16 +455,16 @@ def main(argv):
413455
help='full path to manifest containing the description of events')
414456
required.add_argument('--intermediate', type=str, required=True,
415457
help='full path to eventprovider intermediate directory')
416-
required.add_argument('--runtimeflavor', type=str,default="CoreCLR",
417-
help='runtime flavor')
458+
required.add_argument('--inc', type=str,default="",
459+
help='full path to inclusion list')
418460
args, unknown = parser.parse_known_args(argv)
419461
if unknown:
420462
print('Unknown argument(s): ', ', '.join(unknown))
421463
return 1
422464

423465
manifestFullPath = args.man
424466
intermediatesDirFullPath = args.intermediate
425-
runtimeFlavor = RuntimeFlavor(args.runtimeflavor)
467+
inclusion_filename = args.inc
426468

427469
# Ensure the intermediates directory exists.
428470
try:
@@ -431,8 +473,10 @@ def main(argv):
431473
if not os.path.isdir(intermediatesDirFullPath):
432474
raise
433475

476+
inclusion_list = parseInclusionList(inclusion_filename)
477+
434478
# Generate event sources.
435-
generateEventSources(manifestFullPath, intermediatesDirFullPath, runtimeFlavor)
479+
generateEventSources(manifestFullPath, intermediatesDirFullPath, inclusion_list)
436480
return 0
437481

438482
if __name__ == '__main__':

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.Threading.NativeSinks.Internal.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ namespace System.Diagnostics.Tracing
1010
// It contains the runtime specific interop to native event sinks.
1111
internal sealed partial class NativeRuntimeEventSource : EventSource
1212
{
13-
#if NATIVEAOT
14-
// We don't have these keywords defined from the genRuntimeEventSources.py, so we need to manually define them here.
15-
public static partial class Keywords
16-
{
17-
public const EventKeywords ContentionKeyword = (EventKeywords)0x4000;
18-
public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000;
19-
public const EventKeywords ThreadTransferKeyword = (EventKeywords)0x80000000;
20-
public const EventKeywords WaitHandleKeyword = (EventKeywords)0x40000000000;
21-
}
22-
#endif
23-
2413
[NonEvent]
2514
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "NativeRuntimeEventSource_LogContentionLockCreated")]
2615
private static partial void LogContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID);

src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@
315315
<ItemGroup>
316316
<EventingGenerationScript Include="$(CoreClrProjectRoot)scripts/genRuntimeEventSources.py" />
317317
<EventManifestFile Include="$(CoreClrProjectRoot)vm/ClrEtwAll.man" />
318-
<EventingSourceFile Include="$(IntermediateOutputPath)..\..\..\Eventing\$(TargetArchitecture)\$(Configuration)\NativeRuntimeEventSource.Mono.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
319-
<Link>src\System\Diagnostics\Eventing\Generated\NativeRuntimeEventSource.Mono.cs</Link>
318+
<EventingSourceFile Include="$(IntermediateOutputPath)NativeRuntimeEventSource.Generated.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
319+
<Link>src\System\Diagnostics\Eventing\NativeRuntimeEventSource.Generated.cs</Link>
320320
</EventingSourceFile>
321321
<Compile Include="@(EventingSourceFile)" />
322322
</ItemGroup>
@@ -327,15 +327,15 @@
327327
DependsOnTargets="FindPython"
328328
BeforeTargets="BeforeCompile">
329329

330-
<Error Condition="'$(PYTHON)' == ''" Text="Unable to locate Python. NativeRuntimeEventSource.Mono.cs cannot be generated without Python installed on the machine. Either install Python in your path or point to it with the PYTHON environment variable." />
330+
<Error Condition="'$(PYTHON)' == ''" Text="Unable to locate Python. NativeRuntimeEventSource.Generated.cs cannot be generated without Python installed on the machine. Either install Python in your path or point to it with the PYTHON environment variable." />
331331
<PropertyGroup>
332332
<_PythonWarningParameter>-Wall</_PythonWarningParameter>
333333
<_PythonWarningParameter Condition="'$(MSBuildTreatWarningsAsErrors)' == 'true'">$(_PythonWarningParameter) -Werror</_PythonWarningParameter>
334334
<_EventingSourceFileDirectory>%(EventingSourceFile.RootDir)%(EventingSourceFile.Directory)</_EventingSourceFileDirectory>
335335
<_EventingSourceFileDirectory Condition="HasTrailingSlash('$(_EventingSourceFileDirectory)')">$(_EventingSourceFileDirectory.TrimEnd('\'))</_EventingSourceFileDirectory>
336336
</PropertyGroup>
337337

338-
<Exec Command="&quot;$(PYTHON)&quot; -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot; --runtimeflavor mono" />
338+
<Exec Command="&quot;$(PYTHON)&quot; -B $(_PythonWarningParameter) &quot;@(EventingGenerationScript)&quot; --man &quot;@(EventManifestFile)&quot; --intermediate &quot;$(_EventingSourceFileDirectory)&quot;" />
339339

340340
<ItemGroup>
341341
<FileWrites Include="@(EventingSourceFile)" />

src/tests/issues.targets

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,6 @@
686686

687687
<!-- NativeAOT specific -->
688688
<ItemGroup Condition="'$(XunitTestBinBase)' != '' and '$(TestBuildMode)' == 'nativeaot' and '$(RuntimeFlavor)' == 'coreclr'">
689-
<ExcludeList Include="$(XunitTestBinBase)/tracing/eventlistener/EventListenerThreadPool/**">
690-
<Issue>https://github.com/dotnet/runtime/issues/105556</Issue>
691-
</ExcludeList>
692689
<ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/regressions/beta2/437017/**">
693690
<Issue>https://github.com/dotnet/runtime/issues/102544</Issue>
694691
</ExcludeList>

0 commit comments

Comments
 (0)