Skip to content

Commit

Permalink
Share managed EventSource/EventPipe implementation between CoreCLR an…
Browse files Browse the repository at this point in the history
…d Mono.

First changes needed in order to start sharing managed EventSource/EventPipe
code between CoreCLR and Mono runtime. Sharable code has been moved into
S.P.C library project and split into runtime specific source files when
needed, kept within each runtime specific S.P.C project files.

Mono runtime has been extended with a set of icalls needed by
EventPipeInternal, just to make sure EventPipe can be initialized,
current Mono runtime implementation returns dummy values.

Current change also enables ETW provider support on Mono Windows runtime.

NOTE, this is just initial changes needed in order to share managed
EventSource/EventPipe code between runtimes. Future changes will incrementally
add EventPipe native code into Mono runtime.
  • Loading branch information
lateralusX committed Mar 12, 2020
1 parent 7f52377 commit 928542f
Show file tree
Hide file tree
Showing 22 changed files with 364 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@
<Compile Include="$(BclSourcesRoot)\System\Delegate.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Debugger.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\EditAndContinueHelper.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipe.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeEventDispatcher.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeEventProvider.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeMetadataGenerator.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipePayloadDecoder.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\NativeRuntimeEventSource.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\RuntimeEventSource.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\TraceLogging\TraceLoggingEventHandleTable.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipe.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\ICustomDebuggerNotification.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\StackFrame.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\StackFrameHelper.cs" />
Expand Down Expand Up @@ -300,9 +293,6 @@
<ItemGroup Condition="'$(FeatureUtf8String)' == 'true'">
<Compile Include="$(BclSourcesRoot)\System\Utf8String.CoreCLR.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\XplatEventLogger.cs" Condition="'$(FeatureXplatEventSource)' == 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(FeatureComWrappers)' == 'true'">
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComWrappers.cs" />
</ItemGroup>
Expand Down Expand Up @@ -389,7 +379,6 @@
<Compile Include="$(BclSourcesRoot)\System\DateTime.Unix.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\GlobalizationMode.Unix.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ClrThreadPoolBoundHandle.Unix.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\RuntimeEventSourceHelper.Unix.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\InteropServices\InMemoryAssemblyLoader.cs" />
Expand All @@ -400,7 +389,6 @@
<Compile Include="$(BclSourcesRoot)\System\ApplicationModel.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Globalization\GlobalizationMode.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ClrThreadPoolBoundHandle.Windows.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\RuntimeEventSourceHelper.Windows.cs" Condition="'$(FeaturePerfTracing)' == 'true'" />
</ItemGroup>
<ItemGroup Condition="'$(FeatureAppX)' == 'true'">
<Compile Include="$(BclSourcesRoot)\System\Threading\SynchronizationContext.Uap.cs" />
Expand Down Expand Up @@ -439,8 +427,8 @@
<ItemGroup>
<EventingGenerationScript Include="$(CoreClrProjectRoot)/src/scripts/genRuntimeEventSources.py" />
<EventManifestFile Include="$(CoreClrProjectRoot)/src/vm/ClrEtwAll.man" />
<EventingSourceFile Include="$(IntermediateOutputPath)..\..\..\Eventing\$(BuildArch)\$(Configuration)\NativeRuntimeEventSource.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
<Link>src\System\Diagnostics\Eventing\Generated\NativeRuntimeEventSource.cs</Link>
<EventingSourceFile Include="$(IntermediateOutputPath)..\..\..\Eventing\$(BuildArch)\$(Configuration)\NativeRuntimeEventSource.CoreCLR.cs" Condition="'$(FeaturePerfTracing)' == 'true' ">
<Link>src\System\Diagnostics\Eventing\Generated\NativeRuntimeEventSource.CoreCLR.cs</Link>
</EventingSourceFile>
<Compile Include="@(EventingSourceFile)" />
</ItemGroup>
Expand All @@ -451,7 +439,7 @@
DependsOnTargets="FindPython"
BeforeTargets="BeforeCompile">

<Error Condition="'$(PYTHON)' == ''" Text="Unable to locate Python. NativeRuntimeEventSource.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." />
<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." />
<PropertyGroup>
<_PythonWarningParameter>-Wall</_PythonWarningParameter>
<_PythonWarningParameter Condition="'$(MSBuildTreatWarningsAsErrors)' == 'true'">$(_PythonWarningParameter) -Werror</_PythonWarningParameter>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;

#if FEATURE_PERFTRACING

namespace System.Diagnostics.Tracing
{
internal static partial class EventPipeInternal
{
//
// These PInvokes are used by the configuration APIs to interact with EventPipe.
//
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static unsafe extern ulong Enable(
char* outputFile,
EventPipeSerializationFormat format,
uint circularBufferSizeInMB,
EventPipeProviderConfigurationNative* providers,
uint numProviders);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern void Disable(ulong sessionID);

//
// These PInvokes are used by EventSource to interact with the EventPipe.
//
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern IntPtr CreateProvider(string providerName, Interop.Advapi32.EtwEnableCallback callbackFunc);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern unsafe IntPtr DefineEvent(IntPtr provHandle, uint eventID, long keywords, uint eventVersion, uint level, void* pMetadata, uint metadataLength);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern IntPtr GetProvider(string providerName);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern void DeleteProvider(IntPtr provHandle);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern int EventActivityIdControl(uint controlCode, ref Guid activityId);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern unsafe void WriteEventData(IntPtr eventHandle, EventProvider.EventData* pEventData, uint dataCount, Guid* activityId, Guid* relatedActivityId);

//
// These PInvokes are used as part of the EventPipeEventDispatcher.
//
[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern unsafe bool GetSessionInfo(ulong sessionID, EventPipeSessionInfo* pSessionInfo);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern unsafe bool GetNextEvent(ulong sessionID, EventPipeEventInstanceData* pInstance);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern unsafe IntPtr GetWaitHandle(ulong sessionID);
}
}

#endif // FEATURE_PERFTRACING
8 changes: 1 addition & 7 deletions src/coreclr/src/scripts/genRuntimeEventSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# START CONFIGURATION
########################################################################
manifestsToGenerate = {
"Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.cs"
"Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.CoreCLR.cs"
}

providerNameToClassNameMap = {
Expand Down Expand Up @@ -378,12 +378,6 @@ def generateEventSources(manifestFullPath, intermediatesDirFullPath):
writeOutput(outputFile, "{\n")
increaseTabLevel()

# Create a static property for the EventSource name so that we don't have to initialize the EventSource to get its name.
writeOutput(outputFile, "internal const string EventSourceName = \"" + providerName + "\";\n")

# Write the static Log property.
writeOutput(outputFile, "internal static " + className + " Log = new " + className + "();\n\n")

# Write the keywords class.
generateKeywordsClass(providerNode, outputFile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,52 @@
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.EventUnregister.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.EventWriteString.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.EventWriteTransfer.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\*.cs" />
<Compile Remove="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\FrameworkEventSource.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\*.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\ActivityTracker.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\CounterGroup.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\CounterPayload.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\DiagnosticCounter.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventActivityOptions.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventCounter.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventDescriptor.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSource.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventSourceException.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\IEventProvider.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\IncrementingEventCounter.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\IncrementingPollingCounter.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\PollingCounter.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\StubEnvironment.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\Winmeta.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\ArrayTypeInfo.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\ConcurrentSet.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\ConcurrentSetItem.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\DataCollector.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EmptyStruct.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EnumerableTypeInfo.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EnumHelper.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventDataAttribute.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventFieldAttribute.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventFieldFormat.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventIgnoreAttribute.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventPayload.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventSourceActivity.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\EventSourceOptions.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\FieldMetadata.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\InvokeTypeInfo.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\NameInfo.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\PropertyAnalysis.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\PropertyValue.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\SimpleEventTypes.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\SimpleTypeInfos.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\Statics.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingDataCollector.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingDataType.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventSource.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventTraits.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventTypes.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingMetadataCollector.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingTypeInfo.cs" />
<Compile Include="..\..\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TypeAnalysis.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
Expand Down
Loading

0 comments on commit 928542f

Please sign in to comment.