diff --git a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj index 7e215d1ad72a8..c60cf81af01e6 100644 --- a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -151,14 +151,7 @@ - - - - - - - - + @@ -300,9 +293,6 @@ - - - @@ -389,7 +379,6 @@ - @@ -400,7 +389,6 @@ - @@ -439,8 +427,8 @@ - - src\System\Diagnostics\Eventing\Generated\NativeRuntimeEventSource.cs + + src\System\Diagnostics\Eventing\Generated\NativeRuntimeEventSource.CoreCLR.cs @@ -451,7 +439,7 @@ DependsOnTargets="FindPython" BeforeTargets="BeforeCompile"> - + <_PythonWarningParameter>-Wall <_PythonWarningParameter Condition="'$(MSBuildTreatWarningsAsErrors)' == 'true'">$(_PythonWarningParameter) -Werror diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs new file mode 100644 index 0000000000000..bd1ad774bea18 --- /dev/null +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs @@ -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 diff --git a/src/coreclr/src/scripts/genRuntimeEventSources.py b/src/coreclr/src/scripts/genRuntimeEventSources.py index 3f00742ceae9d..027c3eccafbd4 100644 --- a/src/coreclr/src/scripts/genRuntimeEventSources.py +++ b/src/coreclr/src/scripts/genRuntimeEventSources.py @@ -26,7 +26,7 @@ # START CONFIGURATION ######################################################################## manifestsToGenerate = { - "Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.cs" + "Microsoft-Windows-DotNETRuntime" : "NativeRuntimeEventSource.CoreCLR.cs" } providerNameToClassNameMap = { @@ -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) diff --git a/src/libraries/Microsoft.Diagnostics.Tracing.EventSource.Redist/src/Microsoft.Diagnostics.Tracing.EventSource.Redist.csproj b/src/libraries/Microsoft.Diagnostics.Tracing.EventSource.Redist/src/Microsoft.Diagnostics.Tracing.EventSource.Redist.csproj index 0a543cc4d1894..ae5cb393505d3 100644 --- a/src/libraries/Microsoft.Diagnostics.Tracing.EventSource.Redist/src/Microsoft.Diagnostics.Tracing.EventSource.Redist.csproj +++ b/src/libraries/Microsoft.Diagnostics.Tracing.EventSource.Redist/src/Microsoft.Diagnostics.Tracing.EventSource.Redist.csproj @@ -24,9 +24,52 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index c3290944c03c1..38232a3fb581c 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1020,6 +1020,11 @@ + + + + + @@ -1027,7 +1032,9 @@ + + @@ -1054,12 +1061,14 @@ + + @@ -1457,6 +1466,7 @@ + @@ -1710,6 +1720,7 @@ + diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs similarity index 78% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs index 18ea8b9ebdb95..88c1434b0cce3 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.cs @@ -206,7 +206,7 @@ internal static void Disable() } } - internal static class EventPipeInternal + internal static partial class EventPipeInternal { private unsafe struct EventPipeProviderConfigurationNative { @@ -236,17 +236,6 @@ internal void Release() } } - // - // 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); - internal static unsafe ulong Enable( string? outputFile, EventPipeSerializationFormat format, @@ -282,43 +271,6 @@ internal static unsafe ulong Enable( } } } - - [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); } } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventDispatcher.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs similarity index 99% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventDispatcher.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs index 2307f642cd827..f2d9b30bf85a5 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventDispatcher.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs @@ -158,7 +158,7 @@ private void StopDispatchTask() { m_stopDispatchTask = true; Debug.Assert(!m_dispatchTaskWaitHandle.SafeWaitHandle.IsInvalid); - Interop.Kernel32.SetEvent(m_dispatchTaskWaitHandle.SafeWaitHandle); + EventWaitHandle.Set(m_dispatchTaskWaitHandle.SafeWaitHandle); m_dispatchTask.Wait(); m_dispatchTask = null; } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventProvider.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventProvider.cs diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeMetadataGenerator.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipePayloadDecoder.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipePayloadDecoder.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipePayloadDecoder.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipePayloadDecoder.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs index 2617400d639ac..a757555200c6c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs @@ -13,7 +13,7 @@ using System.Globalization; using System.Numerics; using System.Runtime.InteropServices; -#if CORECLR && TARGET_WINDOWS +#if (CORECLR || MONO) && TARGET_WINDOWS using Internal.Win32; #endif #if ES_BUILD_AGAINST_DOTNET_V35 diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs similarity index 92% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs index 2634fb4a507f9..5272f5077ef60 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs @@ -11,8 +11,11 @@ namespace System.Diagnostics.Tracing [EventSource(Guid = "5E5BB766-BBFC-5662-0548-1D44FAD9BB56", Name = "Microsoft-Windows-DotNETRuntime")] internal sealed partial class NativeRuntimeEventSource : EventSource { + internal const string EventSourceName = "Microsoft-Windows-DotNETRuntime"; + internal static NativeRuntimeEventSource Log = new NativeRuntimeEventSource(); + // The NativeRuntimeEventSource GUID is {5e5bb766-bbfc-5662-0548-1d44fad9bb56} - private NativeRuntimeEventSource() : base(new Guid(0x5e5bb766, 0xbbfc, 0x5662, 0x05, 0x48, 0x1d, 0x44, 0xfa, 0xd9, 0xbb, 0x56), "Microsoft-Windows-DotNETRuntime") { } + private NativeRuntimeEventSource() : base(new Guid(0x5e5bb766, 0xbbfc, 0x5662, 0x05, 0x48, 0x1d, 0x44, 0xfa, 0xd9, 0xbb, 0x56), EventSourceName) { } /// /// Dispatch a single event with the specified event ID and payload. diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs similarity index 97% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs index e7edc85d1917b..336e981bd622a 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs @@ -12,33 +12,38 @@ namespace System.Diagnostics.Tracing [EventSource(Guid = "49592C0F-5A05-516D-AA4B-A64E02026C89", Name = "System.Runtime")] internal sealed class RuntimeEventSource : EventSource { + internal const string EventSourceName = "System.Runtime"; + private static RuntimeEventSource? s_RuntimeEventSource; private PollingCounter? _gcHeapSizeCounter; private IncrementingPollingCounter? _gen0GCCounter; private IncrementingPollingCounter? _gen1GCCounter; private IncrementingPollingCounter? _gen2GCCounter; - private IncrementingPollingCounter? _exceptionCounter; private PollingCounter? _cpuTimeCounter; private PollingCounter? _workingSetCounter; private PollingCounter? _threadPoolThreadCounter; private IncrementingPollingCounter? _monitorContentionCounter; private PollingCounter? _threadPoolQueueCounter; private IncrementingPollingCounter? _completedItemsCounter; + private IncrementingPollingCounter? _allocRateCounter; + private PollingCounter? _timerCounter; + +#if !MONO + private IncrementingPollingCounter? _exceptionCounter; private PollingCounter? _gcTimeCounter; private PollingCounter? _gen0SizeCounter; private PollingCounter? _gen1SizeCounter; private PollingCounter? _gen2SizeCounter; private PollingCounter? _lohSizeCounter; - private IncrementingPollingCounter? _allocRateCounter; private PollingCounter? _assemblyCounter; - private PollingCounter? _timerCounter; +#endif public static void Initialize() { s_RuntimeEventSource = new RuntimeEventSource(); } - private RuntimeEventSource() : base(new Guid(0x49592C0F, 0x5A05, 0x516D, 0xAA, 0x4B, 0xA6, 0x4E, 0x02, 0x02, 0x6C, 0x89), "System.Runtime", EventSourceSettings.EtwSelfDescribingEventFormat) + private RuntimeEventSource() : base(new Guid(0x49592C0F, 0x5A05, 0x516D, 0xAA, 0x4B, 0xA6, 0x4E, 0x02, 0x02, 0x6C, 0x89), EventSourceName, EventSourceSettings.EtwSelfDescribingEventFormat) { } @@ -57,20 +62,24 @@ protected override void OnEventCommand(EventCommandEventArgs command) _gen0GCCounter ??= new IncrementingPollingCounter("gen-0-gc-count", this, () => GC.CollectionCount(0)) { DisplayName = "Gen 0 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0) }; _gen1GCCounter ??= new IncrementingPollingCounter("gen-1-gc-count", this, () => GC.CollectionCount(1)) { DisplayName = "Gen 1 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0) }; _gen2GCCounter ??= new IncrementingPollingCounter("gen-2-gc-count", this, () => GC.CollectionCount(2)) { DisplayName = "Gen 2 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0) }; - _exceptionCounter ??= new IncrementingPollingCounter("exception-count", this, () => Exception.GetExceptionCount()) { DisplayName = "Exception Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; _threadPoolThreadCounter ??= new PollingCounter("threadpool-thread-count", this, () => ThreadPool.ThreadCount) { DisplayName = "ThreadPool Thread Count" }; _monitorContentionCounter ??= new IncrementingPollingCounter("monitor-lock-contention-count", this, () => Monitor.LockContentionCount) { DisplayName = "Monitor Lock Contention Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; _threadPoolQueueCounter ??= new PollingCounter("threadpool-queue-length", this, () => ThreadPool.PendingWorkItemCount) { DisplayName = "ThreadPool Queue Length" }; _completedItemsCounter ??= new IncrementingPollingCounter("threadpool-completed-items-count", this, () => ThreadPool.CompletedWorkItemCount) { DisplayName = "ThreadPool Completed Work Item Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; + _allocRateCounter ??= new IncrementingPollingCounter("alloc-rate", this, () => GC.GetTotalAllocatedBytes()) { DisplayName = "Allocation Rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; + _timerCounter ??= new PollingCounter("active-timer-count", this, () => Timer.ActiveCount) { DisplayName = "Number of Active Timers" }; + +#if !MONO + _exceptionCounter ??= new IncrementingPollingCounter("exception-count", this, () => Exception.GetExceptionCount()) { DisplayName = "Exception Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; _gcTimeCounter ??= new PollingCounter("time-in-gc", this, () => GC.GetLastGCPercentTimeInGC()) { DisplayName = "% Time in GC since last GC", DisplayUnits = "%" }; _gen0SizeCounter ??= new PollingCounter("gen-0-size", this, () => GC.GetGenerationSize(0)) { DisplayName = "Gen 0 Size", DisplayUnits = "B" }; _gen1SizeCounter ??= new PollingCounter("gen-1-size", this, () => GC.GetGenerationSize(1)) { DisplayName = "Gen 1 Size", DisplayUnits = "B" }; _gen2SizeCounter ??= new PollingCounter("gen-2-size", this, () => GC.GetGenerationSize(2)) { DisplayName = "Gen 2 Size", DisplayUnits = "B" }; _lohSizeCounter ??= new PollingCounter("loh-size", this, () => GC.GetGenerationSize(3)) { DisplayName = "LOH Size", DisplayUnits = "B" }; - _allocRateCounter ??= new IncrementingPollingCounter("alloc-rate", this, () => GC.GetTotalAllocatedBytes()) { DisplayName = "Allocation Rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; _assemblyCounter ??= new PollingCounter("assembly-count", this, () => System.Reflection.Assembly.GetAssemblyCount()) { DisplayName = "Number of Assemblies Loaded" }; - _timerCounter ??= new PollingCounter("active-timer-count", this, () => Timer.ActiveCount) { DisplayName = "Number of Active Timers" }; +#endif } + } } } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSourceHelper.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Unix.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSourceHelper.Unix.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Unix.cs diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSourceHelper.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Windows.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSourceHelper.Windows.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSourceHelper.Windows.cs diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventHandleTable.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventHandleTable.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventHandleTable.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventHandleTable.cs diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/XplatEventLogger.cs similarity index 100% rename from src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/XplatEventLogger.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/XplatEventLogger.cs diff --git a/src/mono/mono/metadata/icall-decl.h b/src/mono/mono/metadata/icall-decl.h index 29f49194de268..dd86ccdc5db2a 100644 --- a/src/mono/mono/metadata/icall-decl.h +++ b/src/mono/mono/metadata/icall-decl.h @@ -235,6 +235,19 @@ ICALL_EXPORT MonoBoolean ves_icall_System_Diagnostics_Debugger_IsAttached_intern ICALL_EXPORT MonoBoolean ves_icall_System_Diagnostics_Debugger_IsLogging (void); ICALL_EXPORT void ves_icall_System_Diagnostics_Debugger_Log (int level, MonoString *volatile* category, MonoString *volatile* message); +#ifdef ENABLE_NETCORE +ICALL_EXPORT intptr_t ves_icall_System_Diagnostics_Tracing_EventPipeInternal_DefineEvent (intptr_t prov_handle, uint32_t event_id, int64_t keywords, uint32_t event_version, uint32_t level, const uint8_t *metadata, uint32_t metadata_len); +ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_EventPipeInternal_DeleteProvider (intptr_t prov_handle); +ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_EventPipeInternal_Disable (uint64_t session_id); +ICALL_EXPORT uint64_t ves_icall_System_Diagnostics_Tracing_EventPipeInternal_Enable (const_gunichar2_ptr output_file, int32_t format, uint32_t circular_buffer_size_mb, const void *providers, uint32_t num_providers); +ICALL_EXPORT int32_t ves_icall_System_Diagnostics_Tracing_EventPipeInternal_EventActivityIdControl (uint32_t control_code, uint8_t *activity_id); +ICALL_EXPORT MonoBoolean ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetNextEvent (uint64_t session_id, void *instance); +ICALL_EXPORT intptr_t ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetProvider (const_gunichar2_ptr provider_name); +ICALL_EXPORT MonoBoolean ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetSessionInfo (uint64_t session_id, void *session_info); +ICALL_EXPORT intptr_t ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetWaitHandle (uint64_t session_id); +ICALL_EXPORT void ves_icall_System_Diagnostics_Tracing_EventPipeInternal_WriteEventData (intptr_t event_handle, const void *event_data, uint32_t data_count, const uint8_t *activity_id, const uint8_t *related_activity_id); +#endif + ICALL_EXPORT void ves_icall_Mono_RuntimeGPtrArrayHandle_GPtrArrayFree (GPtrArray *ptr_array); ICALL_EXPORT void ves_icall_Mono_RuntimeMarshal_FreeAssemblyName (MonoAssemblyName *aname, MonoBoolean free_struct); ICALL_EXPORT void ves_icall_Mono_SafeStringMarshal_GFree (void *c_str); diff --git a/src/mono/mono/metadata/icall-def-netcore.h b/src/mono/mono/metadata/icall-def-netcore.h index 22fecdd8ae01e..d2b647a7b68d7 100644 --- a/src/mono/mono/metadata/icall-def-netcore.h +++ b/src/mono/mono/metadata/icall-def-netcore.h @@ -67,6 +67,19 @@ NOHANDLES(ICALL(DEBUGR_1, "IsAttached_internal", ves_icall_System_Diagnostics_De NOHANDLES(ICALL(DEBUGR_2, "IsLogging", ves_icall_System_Diagnostics_Debugger_IsLogging)) NOHANDLES(ICALL(DEBUGR_3, "Log_icall", ves_icall_System_Diagnostics_Debugger_Log)) +ICALL_TYPE(EVENTPIPE, "System.Diagnostics.Tracing.EventPipeInternal", EVENTPIPE_1) +HANDLES(EVENTPIPE_1, "CreateProvider", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_CreateProvider, gconstpointer, 2, (MonoString, MonoDelegate)) +NOHANDLES(ICALL(EVENTPIPE_2, "DefineEvent", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_DefineEvent)) +NOHANDLES(ICALL(EVENTPIPE_3, "DeleteProvider", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_DeleteProvider)) +NOHANDLES(ICALL(EVENTPIPE_4, "Disable", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_Disable)) +NOHANDLES(ICALL(EVENTPIPE_5, "Enable", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_Enable)) +NOHANDLES(ICALL(EVENTPIPE_6, "EventActivityIdControl", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_EventActivityIdControl)) +NOHANDLES(ICALL(EVENTPIPE_7, "GetNextEvent", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetNextEvent)) +NOHANDLES(ICALL(EVENTPIPE_8, "GetProvider", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetProvider)) +NOHANDLES(ICALL(EVENTPIPE_9, "GetSessionInfo", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetSessionInfo)) +NOHANDLES(ICALL(EVENTPIPE_10, "GetWaitHandle", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetWaitHandle)) +NOHANDLES(ICALL(EVENTPIPE_11, "WriteEventData", ves_icall_System_Diagnostics_Tracing_EventPipeInternal_WriteEventData)) + ICALL_TYPE(ENUM, "System.Enum", ENUM_1) HANDLES(ENUM_1, "GetEnumValuesAndNames", ves_icall_System_Enum_GetEnumValuesAndNames, MonoBoolean, 3, (MonoReflectionType, MonoArrayOut, MonoArrayOut)) HANDLES(ENUM_2, "InternalBoxEnum", ves_icall_System_Enum_ToObject, MonoObject, 2, (MonoReflectionType, guint64)) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 9e20e8a1cc4bc..5c0dfcb7018a0 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -8377,6 +8377,115 @@ ves_icall_System_Diagnostics_Debugger_Log (int level, MonoString *volatile* cate mono_get_runtime_callbacks ()->debug_log (level, *category, *message); } +#ifdef ENABLE_NETCORE +#define EVENT_PIPE_DUMMY_PROVIDER_ID 1 +#define EVENT_PIPE_DUMMY_SESSION_ID 1 +#define EVENT_PIPE_DUMMY_EVENT_ID 1 +#define EVENT_PIPE_ERROR_SUCCESS 0 +#define EVENT_PIPE_INVALID_WAIT_HANDLE 0 + +typedef enum _EventPipeSerializationFormat{ + NetPerf, + NetTrace +} EventPipeSerializationFormat; + +typedef struct _EventPipeProviderConfigurationNative { + gunichar2 *provider_name; + uint64_t keywords; + uint32_t logging_level; + gunichar2 *filter_data; +} EventPipeProviderConfigurationNative; + +typedef struct _EventProviderEventData { + uint64_t ptr; + uint32_t size; + uint32_t reserved; +} EventProviderEventData; + +typedef struct _EventPipeSessionInfo { + int64_t starttime_as_utc_filetime; + int64_t start_timestamp; + int64_t timestamp_frequency; +} EventPipeSessionInfo; + +typedef struct _EventPipeEventInstanceData { + intptr_t provider_id; + uint32_t event_id; + uint32_t thread_id; + int64_t timestamp; + uint8_t activity_id[16]; + uint8_t related_activity_id[16]; + const uint8_t *payload; + uint32_t payload_length; +} EventPipeEventInstanceData; + +gconstpointer +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_CreateProvider (MonoStringHandle provider_name, MonoDelegateHandle callback_func, MonoError *error) +{ + return EVENT_PIPE_DUMMY_PROVIDER_ID; +} + +intptr_t +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_DefineEvent (intptr_t prov_handle, uint32_t event_id, int64_t keywords, uint32_t event_version, uint32_t level, const uint8_t *metadata, uint32_t metadata_len) +{ + return EVENT_PIPE_DUMMY_EVENT_ID; +} + +void +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_DeleteProvider (intptr_t prov_handle) +{ + ; +} + +void +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_Disable (uint64_t session_id) +{ + ; +} + +uint64_t +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_Enable (const_gunichar2_ptr output_file, /* EventPipeSerializationFormat */int32_t format, uint32_t circular_buffer_size_mb, /* EventPipeProviderConfigurationNative[] */const void *providers, uint32_t num_providers) +{ + return EVENT_PIPE_DUMMY_SESSION_ID; +} + +int32_t +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_EventActivityIdControl (uint32_t control_code, /* GUID * */uint8_t *activity_id) +{ + return EVENT_PIPE_ERROR_SUCCESS; +} + +MonoBoolean +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetNextEvent (uint64_t session_id, /* EventPipeEventInstanceData * */void *instance) +{ + return FALSE; +} + +intptr_t +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetProvider (const_gunichar2_ptr provider_name) +{ + return EVENT_PIPE_DUMMY_PROVIDER_ID; +} + +MonoBoolean +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetSessionInfo (uint64_t session_id, /* EventPipeSessionInfo * */void *session_info) +{ + return FALSE; +} + +intptr_t +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetWaitHandle (uint64_t session_id) +{ + return EVENT_PIPE_INVALID_WAIT_HANDLE; +} + +void +ves_icall_System_Diagnostics_Tracing_EventPipeInternal_WriteEventData (intptr_t event_handle, /* EventProviderEventData[] */const void *event_data, uint32_t data_count, /* GUID * */const uint8_t *activity_id, /* GUID * */const uint8_t *related_activity_id) +{ + ; +} +#endif /* ENABLE_NETCORE */ + #ifndef HOST_WIN32 static inline void mono_icall_write_windows_debug_string (const gunichar2 *message) diff --git a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj index af3f6c0613404..b9cf138e934ae 100644 --- a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -96,12 +96,6 @@ true - - TARGET_OSX;$(DefineConstants) - - - TARGET_IOS;$(DefineConstants) - @@ -136,13 +130,26 @@ $(NoWarn),CS8597,CS8600,CS8601,CS8602,CS8603,CS8604,CS8609,CS8611,CS8618,CS8620,CS8625,CS8631,CS8632,CS8634 $(NoWarn),618,67 - FEATURE_DEFAULT_INTERFACES;FEATURE_MANAGED_ETW_CHANNELS;$(DefineConstants) NETCORE;DISABLE_REMOTING;MONO_FEATURE_SRE;$(DefineConstants) + true + true true true true true + true + + + + $(DefineConstants);FEATURE_MANAGED_ETW + $(DefineConstants);FEATURE_MANAGED_ETW_CHANNELS + $(DefineConstants);FEATURE_PERFTRACING + $(DefineConstants);FEATURE_DEFAULT_INTERFACES + $(DefineConstants);TARGET_UNIX + $(DefineConstants);TARGET_WINDOWS + $(DefineConstants);TARGET_OSX + $(DefineConstants);TARGET_IOS @@ -193,6 +200,7 @@ + diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs new file mode 100644 index 0000000000000..de832fa5d0447 --- /dev/null +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipe.Mono.cs @@ -0,0 +1,65 @@ +// 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.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +#if FEATURE_PERFTRACING + +namespace System.Diagnostics.Tracing +{ + internal static partial class EventPipeInternal + { + // These ICalls are used by the configuration APIs to interact with EventPipe. + // + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static unsafe extern ulong Enable(char* outputFile, EventPipeSerializationFormat format, uint circularBufferSizeInMB, EventPipeProviderConfigurationNative* providers, uint numProviders); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern void Disable(ulong sessionID); + + // + // These ICalls are used by EventSource to interact with the EventPipe. + // + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern IntPtr CreateProvider(string providerName, Interop.Advapi32.EtwEnableCallback callbackFunc); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern unsafe IntPtr DefineEvent(IntPtr provHandle, uint eventID, long keywords, uint eventVersion, uint level, byte* pMetadata, uint metadataLength); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern unsafe IntPtr GetProvider(char* providerName); + + internal static unsafe IntPtr GetProvider(string providerName) + { + fixed (char* p = providerName) + { + return GetProvider(p); + } + } + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern void DeleteProvider(IntPtr provHandle); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern int EventActivityIdControl(uint controlCode, ref Guid activityId); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern unsafe void WriteEventData(IntPtr eventHandle, EventProvider.EventData* pEventData, uint dataCount, Guid* activityId, Guid* relatedActivityId); + + + // + // These ICalls are used as part of the EventPipeEventDispatcher. + // + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern unsafe bool GetSessionInfo(ulong sessionID, EventPipeSessionInfo* pSessionInfo); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern unsafe bool GetNextEvent(ulong sessionID, EventPipeEventInstanceData* pInstance); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + internal static extern unsafe IntPtr GetWaitHandle(ulong sessionID); + } +} + +#endif // FEATURE_PERFTRACING