Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b286cab

Browse files
authored
[Release/2.2 Port] Dispatch Native Runtime Events to EventListener (#19310)
1 parent 94e0383 commit b286cab

Some content is hidden

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

50 files changed

+2580
-296
lines changed

build.cmd

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,12 @@ REM Find python and set it to the variable PYTHON
359359
echo import sys; sys.stdout.write(sys.executable) | (py -3 || py -2 || python3 || python2 || python) > %TEMP%\pythonlocation.txt 2> NUL
360360
set /p PYTHON=<%TEMP%\pythonlocation.txt
361361

362+
if NOT DEFINED PYTHON (
363+
echo %__MsgPrefix%Error: Could not find a python installation
364+
exit /b 1
365+
)
366+
362367
if /i "%__BuildNative%"=="1" (
363-
if NOT DEFINED PYTHON (
364-
echo %__MsgPrefix%Error: Could not find a python installation
365-
exit /b 1
366-
)
367368

368369
echo %__MsgPrefix%Laying out dynamically generated files consumed by the native build system
369370
echo %__MsgPrefix%Laying out dynamically generated Event test files and etmdummy stub functions
@@ -376,6 +377,12 @@ if /i "%__BuildNative%"=="1" (
376377
"!PYTHON!" -B -Wall %__SourceDir%\scripts\genEtwProvider.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate %__IntermediatesIncDir% --exc %__SourceDir%\vm\ClrEtwAllMeta.lst || exit /b 1
377378
)
378379

380+
if /i "%__BuildCoreLib%"=="1" (
381+
382+
echo %__MsgPrefix%Laying out dynamically generated EventSource classes
383+
"!PYTHON!" -B -Wall %__SourceDir%\scripts\genRuntimeEventSources.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate %__IntermediatesEventingDir% || exit /b 1
384+
)
385+
379386
if /i "%__DoCrossArchBuild%"=="1" (
380387
if NOT DEFINED PYTHON (
381388
echo %__MsgPrefix%Error: Could not find a python installation
@@ -392,6 +399,9 @@ if /i "%__DoCrossArchBuild%"=="1" (
392399
echo %__MsgPrefix%Laying out dynamically generated EventPipe Implementation
393400
"!PYTHON!" -B -Wall %__SourceDir%\scripts\genEventPipe.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate !__CrossCompIntermediatesEventingDir!\eventpipe --nonextern || exit /b 1
394401

402+
echo %__MsgPrefix%Laying out dynamically generated EventSource classes
403+
"!PYTHON!" -B -Wall %__SourceDir%\scripts\genRuntimeEventSources.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate !__CrossCompIntermediatesEventingDir! || exit /b 1
404+
395405
echo %__MsgPrefix%Laying out ETW event logging interface
396406
"!PYTHON!" -B -Wall %__SourceDir%\scripts\genEtwProvider.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate !__CrossCompIntermediatesIncDir! --exc %__SourceDir%\vm\ClrEtwAllMeta.lst || exit /b 1
397407
)

build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ generate_event_logging_sources()
220220
echo "Laying out dynamically generated EventPipe Implementation"
221221
$PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genEventPipe.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir/eventpipe"
222222

223+
echo "Laying out dynamically generated EventSource classes"
224+
$PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir"
225+
223226
# determine the logging system
224227
case $__BuildOS in
225228
Linux|FreeBSD)
@@ -242,7 +245,7 @@ generate_event_logging_sources()
242245
generate_event_logging()
243246
{
244247
# Event Logging Infrastructure
245-
if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
248+
if [[ $__SkipCoreCLR == 0 || $__SkipMSCorLib == 0 || $__ConfigureOnly == 1 ]]; then
246249
generate_event_logging_sources "$__IntermediatesDir" "the native build system"
247250
fi
248251

clr.coreclr.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<FeatureICastable>true</FeatureICastable>
55
<FeatureManagedEtwChannels>true</FeatureManagedEtwChannels>
66
<FeatureManagedEtw>true</FeatureManagedEtw>
7-
7+
<FeaturePerfTracing>true</FeaturePerfTracing>
88
<ProfilingSupportedBuild>true</ProfilingSupportedBuild>
99
</PropertyGroup>
1010

@@ -17,7 +17,6 @@
1717
<FeatureStubsAsIL>true</FeatureStubsAsIL>
1818

1919
<FeatureCoreFxGlobalization>true</FeatureCoreFxGlobalization>
20-
<FeaturePerfTracing>true</FeaturePerfTracing>
2120
</PropertyGroup>
2221

2322
<PropertyGroup Condition="'$(TargetsWindows)' == 'true'">

src/mscorlib/ILLinkTrim.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@
3535
</type>
3636
<!-- Accessed via private reflection by tracing controller. -->
3737
<type fullname="System.Diagnostics.Tracing.EventPipe*" />
38+
<!-- Accessed via private reflection and by native code. -->
39+
<type fullname="System.Diagnostics.Tracing.RuntimeEventSource" />
3840
</assembly>
3941
</linker>

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,13 @@
523523
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventSource_CoreCLR.cs" />
524524
<Compile Condition="'$(FeatureXplatEventSource)' == 'true'" Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\XplatEventLogger.cs" />
525525
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\FrameworkEventSource.cs" />
526+
<Compile Include="$(IntermediateOutputPath)..\eventing\DotNETRuntimeEventSource.cs" />
527+
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\DotNETRuntimeEventSource.cs" />
526528
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipe.cs" />
529+
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeEventDispatcher.cs" />
527530
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeEventProvider.cs" />
528531
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeMetadataGenerator.cs" />
532+
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipePayloadDecoder.cs" />
529533
</ItemGroup>
530534
<ItemGroup>
531535
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Contracts\Contracts.cs" />
@@ -670,4 +674,4 @@
670674
</ItemGroup>
671675
<Import Project="ILLink.targets" />
672676
<Import Project="GenerateCompilerResponseFile.targets" />
673-
</Project>
677+
</Project>

src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ namespace Microsoft.Diagnostics.Tracing
3030
namespace System.Diagnostics.Tracing
3131
#endif
3232
{
33+
internal enum EventProviderType
34+
{
35+
None = 0,
36+
ETW,
37+
EventPipe
38+
};
39+
3340
// New in CLR4.0
3441
internal enum ControllerCommand
3542
{
@@ -120,15 +127,28 @@ public enum WriteEventErrorCode : int
120127
// it registers a callback from native code you MUST dispose it BEFORE shutdown, otherwise
121128
// you may get native callbacks during shutdown when we have destroyed the delegate.
122129
// EventSource has special logic to do this, no one else should be calling EventProvider.
123-
internal EventProvider()
130+
internal EventProvider(EventProviderType providerType)
124131
{
132+
switch (providerType)
133+
{
134+
case EventProviderType.ETW:
125135
#if PLATFORM_WINDOWS
126-
m_eventProvider = new EtwEventProvider();
127-
#elif FEATURE_PERFTRACING
128-
m_eventProvider = new EventPipeEventProvider();
136+
m_eventProvider = new EtwEventProvider();
129137
#else
130-
m_eventProvider = new NoOpEventProvider();
138+
m_eventProvider = new NoOpEventProvider();
131139
#endif
140+
break;
141+
case EventProviderType.EventPipe:
142+
#if FEATURE_PERFTRACING
143+
m_eventProvider = new EventPipeEventProvider();
144+
#else
145+
m_eventProvider = new NoOpEventProvider();
146+
#endif
147+
break;
148+
default:
149+
m_eventProvider = new NoOpEventProvider();
150+
break;
151+
};
132152
}
133153

134154
/// <summary>
@@ -475,7 +495,7 @@ private unsafe void GetSessionInfo(SessionInfoCallback action, ref List<SessionI
475495
var structBase = (byte*)providerInstance;
476496
providerInstance = (UnsafeNativeMethods.ManifestEtw.TRACE_PROVIDER_INSTANCE_INFO*)&structBase[providerInstance->NextOffset];
477497
}
478-
#else
498+
#else
479499
#if !ES_BUILD_PCL && PLATFORM_WINDOWS // TODO command arguments don't work on PCL builds...
480500
// This code is only used in the Nuget Package Version of EventSource. because
481501
// the code above is using APIs baned from UWP apps.
@@ -1276,8 +1296,7 @@ unsafe IntPtr IEventProvider.DefineEventHandle(uint eventID, string eventName, I
12761296
}
12771297
}
12781298

1279-
#elif !FEATURE_PERFTRACING
1280-
1299+
#endif
12811300
internal sealed class NoOpEventProvider : IEventProvider
12821301
{
12831302
unsafe uint IEventProvider.EventRegister(
@@ -1314,10 +1333,8 @@ int IEventProvider.EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.Activi
13141333
// Define an EventPipeEvent handle.
13151334
unsafe IntPtr IEventProvider.DefineEventHandle(uint eventID, string eventName, Int64 keywords, uint eventVersion, uint level, byte *pMetadata, uint metadataLength)
13161335
{
1317-
throw new System.NotSupportedException();
1336+
return IntPtr.Zero;
13181337
}
13191338
}
1320-
1321-
#endif
13221339
}
13231340

0 commit comments

Comments
 (0)