From 0b82d34726cd9c2d4c85c2c3c6f520ffc98900fb Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 1 Jun 2023 08:55:46 -0700 Subject: [PATCH 01/22] preliminery managed runtime event support --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 19 +- .../Runtime/clreventpipewriteevents.h | 8 + .../Runtime/disabledeventpipeinternal.cpp | 4 + .../Runtime/eventpipe/CMakeLists.txt | 1 + .../Runtime/eventpipe/dotnetruntime.cpp | 45 ++++ .../nativeaot/Runtime/eventpipeadapter.h | 231 +++++++++++++++++- .../nativeaot/Runtime/eventpipeinternal.cpp | 68 +++++- .../nativeaot/Runtime/nativeeventsource.cpp | 82 +++++++ .../src/System.Private.CoreLib.csproj | 1 + ...ortableThreadPool.NativeSinks.NativeAot.cs | 100 ++++++++ .../src/System/Runtime/RuntimeImports.cs | 5 + .../EventListenerThreadPool.csproj | 1 + 12 files changed, 549 insertions(+), 16 deletions(-) create mode 100644 src/coreclr/nativeaot/Runtime/nativeeventsource.cpp create mode 100644 src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index 01d4bcd7da09e..218dff3fc6977 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -1,10 +1,11 @@ - // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // Work In Progress to add native events to EventPipe // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase // @TODO: Audit native events in NativeAOT Runtime +#ifndef __CLR_ETW_ALL_MAIN_H__ +#define __CLR_ETW_ALL_MAIN_H__ #include "clreventpipewriteevents.h" #include "etwevents.h" @@ -702,3 +703,19 @@ inline ULONG FireEtwGCSuspendEEBegin_V1( #endif return status; } + +inline BOOL EventEnabledThreadPoolWorkerThreadStart(void) {return EventPipeEventEnabledThreadPoolWorkerThreadStart();}// || EventXplatEnabledThreadPoolWorkerThreadStart();} + +inline ULONG FireEtwThreadPoolWorkerThreadStart( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); + // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); + return status; +} + #endif // __CLR_ETW_ALL_MAIN_H__ \ No newline at end of file diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index 4c762359f25e8..93dca46051fed 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -366,3 +366,11 @@ ULONG EventPipeWriteEventGCSuspendEEBegin_V1( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); +BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void); +ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); diff --git a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp index b1464bdb22570..40d0745407a22 100644 --- a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp @@ -101,4 +101,8 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return FALSE; } +EXTERN_C NATIVEAOT_API void __cdecl RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +{ + PalDebugBreak(); +} #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index d0b918e3aabc3..01819cbe52bfd 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -92,6 +92,7 @@ list(APPEND GEN_EVENTPIPE_SOURCES list(APPEND AOT_EVENTPIPE_MANAGED_TO_NATIVE_SOURCES ${RUNTIME_DIR}/eventpipeinternal.cpp + ${RUNTIME_DIR}/nativeeventsource.cpp ${RUNTIME_DIR}/eventpipeadapter.h ${RUNTIME_DIR}/diagnosticserveradapter.h ${RUNTIME_DIR}/EnabledEventPipeInterface.cpp diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index d5f78761b7670..ae1c362ea20c8 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -130,6 +130,7 @@ EventPipeEvent *EventPipeEventGCRestartEEEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCRestartEEBegin_V1 = nullptr; EventPipeEvent *EventPipeEventGCSuspendEEEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCSuspendEEBegin_V1 = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStart = nullptr; BOOL EventPipeEventEnabledDestroyGCHandle(void) { @@ -1812,6 +1813,49 @@ ULONG EventPipeWriteEventGCSuspendEEBegin_V1( return ERROR_SUCCESS; } +BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStart); +} + +ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkerThreadStart()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ActiveWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(RetiredWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkerThreadStart, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + + typedef struct _MCGEN_TRACE_CONTEXT { TRACEHANDLE RegistrationHandle; @@ -1989,4 +2033,5 @@ void InitDotNETRuntime(void) EventPipeEventGCRestartEEBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,7,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCSuspendEEEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,8,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCSuspendEEBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,9,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventThreadPoolWorkerThreadStart = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,50,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); } diff --git a/src/coreclr/nativeaot/Runtime/eventpipeadapter.h b/src/coreclr/nativeaot/Runtime/eventpipeadapter.h index 343c4628c6a92..5fd85c342a81f 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeadapter.h +++ b/src/coreclr/nativeaot/Runtime/eventpipeadapter.h @@ -24,6 +24,77 @@ #include "holder.h" #include "SpinLock.h" +typedef /* [public][public][public] */ struct __MIDL___MIDL_itf_corprof_0000_0000_0015 +{ +const WCHAR *providerName; +uint64_t keywords; +uint32_t loggingLevel; +const WCHAR *filterData; +} COR_PRF_EVENTPIPE_PROVIDER_CONFIG; + + +class EventPipeProviderConfigurationAdapter final +{ +public: + EventPipeProviderConfigurationAdapter(const COR_PRF_EVENTPIPE_PROVIDER_CONFIG *providerConfigs, uint32_t providerConfigsLen) + { + STATIC_CONTRACT_NOTHROW; + + // This static_assert will fail because EventPipeProviderConfiguration uses char8_t strings rather than char16_t strings. + // This method takes the COR_PRF variant and converts to char8_t strings, so it should be fine. + // Leaving the assert commented out here for posterity. + // + // static_assert(offsetof(EventPipeProviderConfiguration, provider_name) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, providerName) + // && offsetof(EventPipeProviderConfiguration, keywords) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, keywords) + // && offsetof(EventPipeProviderConfiguration, logging_level) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, loggingLevel) + // && offsetof(EventPipeProviderConfiguration, filter_data) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, filterData) + // && sizeof(EventPipeProviderConfiguration) == sizeof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG), + // "Layouts of EventPipeProviderConfiguration type and COR_PRF_EVENTPIPE_PROVIDER_CONFIG type do not match!"); + + m_providerConfigs = new (nothrow) EventPipeProviderConfiguration[providerConfigsLen]; + m_providerConfigsLen = providerConfigsLen; + if (m_providerConfigs) { + for (uint32_t i = 0; i < providerConfigsLen; ++i) { + ep_provider_config_init ( + &m_providerConfigs[i], + ep_rt_utf16_to_utf8_string (reinterpret_cast(providerConfigs[i].providerName), -1), + providerConfigs[i].keywords, + static_cast(providerConfigs[i].loggingLevel), + ep_rt_utf16_to_utf8_string (reinterpret_cast(providerConfigs[i].filterData), -1)); + } + } + } + + ~EventPipeProviderConfigurationAdapter() + { + STATIC_CONTRACT_NOTHROW; + if (m_providerConfigs) { + for (uint32_t i = 0; i < m_providerConfigsLen; ++i) { + ep_rt_utf8_string_free ((ep_char8_t *)ep_provider_config_get_provider_name (&m_providerConfigs[i])); + ep_rt_utf8_string_free ((ep_char8_t *)ep_provider_config_get_filter_data (&m_providerConfigs[i])); + } + delete [] m_providerConfigs; + } + } + + inline const EventPipeProviderConfiguration * GetProviderConfigs() const + { + STATIC_CONTRACT_NOTHROW; + return m_providerConfigs; + } + + inline uint32_t GetProviderConfigsLen() const + { + STATIC_CONTRACT_NOTHROW; + return m_providerConfigsLen; + } + +private: + EventPipeProviderConfiguration *m_providerConfigs; + uint32_t m_providerConfigsLen; +}; + + class EventPipeAdapter final { public: @@ -74,6 +145,37 @@ class EventPipeAdapter final return ep_enabled(); } + static inline EventPipeSessionID Enable( + LPCWSTR outputPath, + uint32_t circularBufferSizeInMB, + const EventPipeProviderConfigurationAdapter &providerConfigs, + EventPipeSessionType sessionType, + EventPipeSerializationFormat format, + const bool rundownRequested, + IpcStream *const stream, + EventPipeSessionSynchronousCallback callback, + void *callbackAdditionalData) + { + STATIC_CONTRACT_NOTHROW; + + ep_char8_t *outputPathUTF8 = NULL; + if (outputPath) + outputPathUTF8 = ep_rt_utf16_to_utf8_string (reinterpret_cast(outputPath), -1); + EventPipeSessionID result = ep_enable ( + outputPathUTF8, + circularBufferSizeInMB, + providerConfigs.GetProviderConfigs(), + providerConfigs.GetProviderConfigsLen(), + sessionType, + format, + rundownRequested, + stream, + callback, + callbackAdditionalData); + ep_rt_utf8_string_free (outputPathUTF8); + return result; + } + static inline void Disable(EventPipeSessionID id) { CONTRACTL @@ -87,6 +189,69 @@ class EventPipeAdapter final ep_disable(id); } + static inline void StartStreaming(EventPipeSessionID id) + { + CONTRACTL + { + NOTHROW; + GC_TRIGGERS; + MODE_ANY; + } + CONTRACTL_END; + + ep_start_streaming(id); + } + + static inline EventPipeSession * GetSession(EventPipeSessionID id) + { + STATIC_CONTRACT_NOTHROW; + return ep_get_session(id); + } + + static inline bool SignalSession(EventPipeSessionID id) + { + STATIC_CONTRACT_NOTHROW; + + EventPipeSession *const session = ep_get_session (id); + if (!session) + return false; + + return ep_rt_wait_event_set (ep_session_get_wait_event (session)); + } + + static inline bool WaitForSessionSignal(EventPipeSessionID id, int32_t timeoutMs) + { + STATIC_CONTRACT_NOTHROW; + + EventPipeSession *const session = ep_get_session (id); + if (!session) + return false; + + return !ep_rt_wait_event_wait (ep_session_get_wait_event (session), (uint32_t)timeoutMs, false) ? true : false; + } + + static inline FILETIME GetSessionStartTime(EventPipeSession *session) + { + STATIC_CONTRACT_NOTHROW; + + FILETIME fileTime; + LARGE_INTEGER largeValue; + + _ASSERTE(session != NULL); + largeValue.QuadPart = ep_session_get_session_start_time(session); + fileTime.dwLowDateTime = largeValue.u.LowPart; + fileTime.dwHighDateTime = largeValue.u.HighPart; + return fileTime; + } + + static inline LONGLONG GetSessionStartTimestamp(EventPipeSession *session) + { + STATIC_CONTRACT_NOTHROW; + + _ASSERTE(session != NULL); + return ep_session_get_session_start_timestamp(session); + } + static inline EventPipeProvider * GetProvider (LPCWSTR providerName) { CONTRACTL @@ -149,11 +314,67 @@ class EventPipeAdapter final reinterpret_cast(relatedActivityId)); } - static inline bool EventIsEnabled (const EventPipeEvent *epEvent) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_is_enabled(epEvent); - } + static inline bool EventIsEnabled (const EventPipeEvent *epEvent) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_is_enabled(epEvent); + } + + static inline EventPipeEventInstance * GetNextEvent (EventPipeSessionID id) + { + STATIC_CONTRACT_NOTHROW; + return ep_get_next_event(id); + } + + static inline EventPipeProvider * GetEventProvider (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_get_provider(ep_event_instance_get_ep_event(eventInstance)); + } + + static inline uint32_t GetEventID (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_get_event_id(ep_event_instance_get_ep_event(eventInstance)); + } + + static inline uint64_t GetEventThreadID (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_instance_get_thread_id(eventInstance); + } + + static inline int64_t GetEventTimestamp (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_instance_get_timestamp(eventInstance); + } + + static inline const GUID * GetEventActivityID (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + static_assert(sizeof(GUID) == EP_ACTIVITY_ID_SIZE, "Size mismatch, sizeof(GUID) should be equal to EP_ACTIVITY_ID_SIZE"); + return reinterpret_cast(ep_event_instance_get_activity_id_cref(eventInstance)); + } + + static inline const GUID * GetEventRelativeActivityID (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + static_assert(sizeof(GUID) == EP_ACTIVITY_ID_SIZE, "Size mismatch, sizeof(GUID) should be equal to EP_ACTIVITY_ID_SIZE"); + return reinterpret_cast(ep_event_instance_get_related_activity_id_cref(eventInstance)); + } + + static inline const BYTE * GetEventData (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_instance_get_data(eventInstance); + } + + static inline uint32_t GetEventDataLen (EventPipeEventInstance *eventInstance) + { + STATIC_CONTRACT_NOTHROW; + return ep_event_instance_get_data_len(eventInstance); + } }; #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 3615daaeeb249..009447ee0b181 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -38,8 +38,31 @@ EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( /* COR_PRF_EVENTPIPE_PROVIDER_CONFIG */ const void * pProviders, uint32_t numProviders) { - PalDebugBreak(); - return 0; + uint64_t sessionID = 0; + // Invalid input! + if (circularBufferSizeInMB == 0 || + format >= EP_SERIALIZATION_FORMAT_COUNT || + numProviders == 0 || + pProviders == nullptr) + { + return 0; + } + + EventPipeProviderConfigurationAdapter configAdapter(reinterpret_cast(pProviders), numProviders); + + sessionID = EventPipeAdapter::Enable( + outputFile, + circularBufferSizeInMB, + configAdapter, + outputFile != NULL ? EP_SESSION_TYPE_FILE : EP_SESSION_TYPE_LISTENER, + format, + true, + nullptr, + nullptr, + nullptr); + EventPipeAdapter::StartStreaming(sessionID); + + return sessionID; } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_Disable(uint64_t sessionID) @@ -110,26 +133,51 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_WriteEventData( EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetSessionInfo(uint64_t sessionID, EventPipeSessionInfo *pSessionInfo) { - PalDebugBreak(); - return FALSE; + bool retVal = false; + if (pSessionInfo != NULL) + { + EventPipeSession *pSession = EventPipeAdapter::GetSession(sessionID); + if (pSession != NULL) + { + pSessionInfo->StartTimeAsUTCFileTime = EventPipeAdapter::GetSessionStartTime(pSession); + pSessionInfo->StartTimeStamp.QuadPart = EventPipeAdapter::GetSessionStartTimestamp(pSession); + // @TODO + //pSessionInfo->TimeStampFrequency = reinterpret_cast(PalQueryPerformanceFrequency()); + retVal = true; + } + } + return retVal; } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetNextEvent(uint64_t sessionID, EventPipeEventInstanceData *pInstance) { - PalDebugBreak(); - return FALSE; + EventPipeEventInstance *pNextInstance = NULL; + _ASSERTE(pInstance != NULL); + + pNextInstance = EventPipeAdapter::GetNextEvent(sessionID); + if (pNextInstance) + { + pInstance->ProviderID = EventPipeAdapter::GetEventProvider(pNextInstance); + pInstance->EventID = EventPipeAdapter::GetEventID(pNextInstance); + pInstance->ThreadID = static_cast(EventPipeAdapter::GetEventThreadID(pNextInstance)); + pInstance->TimeStamp.QuadPart = EventPipeAdapter::GetEventTimestamp(pNextInstance); + pInstance->ActivityId = *EventPipeAdapter::GetEventActivityID(pNextInstance); + pInstance->RelatedActivityId = *EventPipeAdapter::GetEventRelativeActivityID(pNextInstance); + pInstance->Payload = EventPipeAdapter::GetEventData(pNextInstance); + pInstance->PayloadLength = EventPipeAdapter::GetEventDataLen(pNextInstance); + } + + return pNextInstance != NULL; } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_SignalSession(uint64_t sessionID) { - PalDebugBreak(); - return FALSE; + return EventPipeAdapter::SignalSession(sessionID); } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSignal(uint64_t sessionID, int32_t timeoutMs) { - PalDebugBreak(); - return FALSE; + return EventPipeAdapter::WaitForSessionSignal(sessionID, timeoutMs); } #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/nativeeventsource.cpp b/src/coreclr/nativeaot/Runtime/nativeeventsource.cpp new file mode 100644 index 0000000000000..96ab33f3fa7e8 --- /dev/null +++ b/src/coreclr/nativeaot/Runtime/nativeeventsource.cpp @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "common.h" +#include "gcenv.h" +#include "clretwallmain.h" + +#ifdef FEATURE_PERFTRACING + +// These are native call into corresponding FireEtw* events for events that want to be emitted from the managed +// side using NativeRuntimeEventSource. +// See https://github.com/dotnet/runtime/pull/47829 for an example of how to do this. +EXTERN_C NATIVEAOT_API void __cdecl RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +{ + FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); +} + +// extern "C" void __cdecl LogThreadPoolWorkerThreadStop(uint activeWorkerThreadCount, uint retiredWorkerThreadCount, short clrInstanceID) +// { +// FireEtwThreadPoolWorkerThreadStop(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolWorkerThreadWait(uint activeWorkerThreadCount, uint retiredWorkerThreadCount, short clrInstanceID) +// { +// FireEtwThreadPoolWorkerThreadWait(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolMinMaxThreads(short minWorkerThreads, short maxWorkerThreads, short minIOCompletionThreads, short maxIOCompletionThreads, short clrInstanceID) +// { +// FireEtwThreadPoolMinMaxThreads(minWorkerThreads, maxWorkerThreads, minIOCompletionThreads, maxIOCompletionThreads, clrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolWorkerThreadAdjustmentSample(double throughput, short clrInstanceID) +// { +// FireEtwThreadPoolWorkerThreadAdjustmentSample(throughput, clrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolWorkerThreadAdjustmentAdjustment(double averageThroughput, uint newWorkerThreadCount, uint reason, short clrInstanceID) +// { +// FireEtwThreadPoolWorkerThreadAdjustmentAdjustment(averageThroughput, newWorkerThreadCount, reason, clrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolWorkerThreadAdjustmentStats(double duration, double throughput, double threadWave, double throughputWave, double throughputErrorEstimate, double AverageThroughputErrorEstimate, double ThroughputRatio, double confidence, double newControlSetting, short newThreadWaveMagnitude, short ClrInstanceID) +// { +// FireEtwThreadPoolWorkerThreadAdjustmentStats(duration, throughput, threadWave, throughputWave, throughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, confidence, newControlSetting, newThreadWaveMagnitude, ClrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolIOEnqueue(void* nativeOverlapped, void* overlapped, bool multiDequeues, short ClrInstanceID) +// { +// FireEtwThreadPoolIOEnqueue(nativeOverlapped, overlapped, multiDequeues, ClrInstanceID); +// } + +// extern "C" void __cdecl LogThreadPoolIODequeue(void* nativeOverlapped, void* overlapped, short ClrInstanceID) +// { +// QCALL_CONTRACT; +// BEGIN_QCALL; + +// FireEtwThreadPoolIODequeue(nativeOverlapped, overlapped, ClrInstanceID); + +// END_QCALL; +// } + +// extern "C" void __cdecl LogThreadPoolWorkingThreadCount(uint count, short ClrInstanceID) +// { +// QCALL_CONTRACT; +// BEGIN_QCALL; + +// FireEtwThreadPoolWorkingThreadCount(count, ClrInstanceID); + +// END_QCALL; +// } + +// extern "C" void __cdecl LogThreadPoolIOPack(void* nativeOverlapped, void* overlapped, short ClrInstanceID) +// { +// QCALL_CONTRACT; +// BEGIN_QCALL; + +// FireEtwThreadPoolIOPack(nativeOverlapped, overlapped, ClrInstanceID); + +// END_QCALL; +// } +#endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 945077f8d7c5b..a3761c85cfc67 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -176,6 +176,7 @@ + diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs new file mode 100644 index 0000000000000..f996405f4b46d --- /dev/null +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs @@ -0,0 +1,100 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime; +using System.Runtime.InteropServices; +using System.Threading; +using System.Diagnostics.Tracing; +using System.Runtime.CompilerServices; + +using Internal.Runtime; +using Internal.Runtime.CompilerServices; + +namespace System.Diagnostics.Tracing +{ + // This is part of the NativeRuntimeEventsource, which is the managed version of the Microsoft-Windows-DotNETRuntime provider. + // It contains the runtime specific interop to native event sinks. + internal sealed partial class NativeRuntimeEventSource : EventSource + { +// private const string RuntimeLibrary = "*"; + [NonEvent] + internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) + { + RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + } + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, NativeRuntimeEventSource.ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadAdjustmentStats( + // double Duration, + // double Throughput, + // double ThreadPoolWorkerThreadWait, + // double ThroughputWave, + // double ThroughputErrorEstimate, + // double AverageThroughputErrorEstimate, + // double ThroughputRatio, + // double Confidence, + // double NewControlSetting, + // ushort NewThreadWaveMagnitude, + // ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolIOEnqueue( + // IntPtr NativeOverlapped, + // IntPtr Overlapped, + // [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, + // ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolIODequeue( + // IntPtr NativeOverlapped, + // IntPtr Overlapped, + // ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkingThreadCount( + // uint Count, + // ushort ClrInstanceID + // ); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolIOPack( + // IntPtr NativeOverlapped, + // IntPtr Overlapped, + // ushort ClrInstanceID); + } +} diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 61f8c38b6cb93..106b57c639fbf 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -770,6 +770,11 @@ internal static unsafe partial void RhEventPipeInternal_WriteEventData( [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] internal static partial uint RhEventPipeInternal_WaitForSessionSignal(ulong sessionID, int timeoutMs); + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + + #endif // FEATURE_PERFTRACING // diff --git a/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj b/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj index 203b64d1a3101..dc56ff89f8835 100644 --- a/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj +++ b/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj @@ -6,6 +6,7 @@ true true + true From c7807539651e3bda03b9b615e243f48b66bda5b1 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 1 Jun 2023 14:06:55 -0700 Subject: [PATCH 02/22] Linux fixes 1 --- .../Runtime/eventpipe/CMakeLists.txt | 1 - .../nativeaot/Runtime/eventpipeinternal.cpp | 4 + .../nativeaot/Runtime/nativeeventsource.cpp | 82 ------------------- ...ortableThreadPool.NativeSinks.NativeAot.cs | 19 +++-- .../src/System/Runtime/RuntimeImports.cs | 70 ++++++++++++++++ 5 files changed, 84 insertions(+), 92 deletions(-) delete mode 100644 src/coreclr/nativeaot/Runtime/nativeeventsource.cpp diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index 01819cbe52bfd..d0b918e3aabc3 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -92,7 +92,6 @@ list(APPEND GEN_EVENTPIPE_SOURCES list(APPEND AOT_EVENTPIPE_MANAGED_TO_NATIVE_SOURCES ${RUNTIME_DIR}/eventpipeinternal.cpp - ${RUNTIME_DIR}/nativeeventsource.cpp ${RUNTIME_DIR}/eventpipeadapter.h ${RUNTIME_DIR}/diagnosticserveradapter.h ${RUNTIME_DIR}/EnabledEventPipeInterface.cpp diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 009447ee0b181..57e86d3362431 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -180,4 +180,8 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return EventPipeAdapter::WaitForSessionSignal(sessionID, timeoutMs); } +EXTERN_C NATIVEAOT_API void __cdecl RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +{ + FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); +} #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/nativeeventsource.cpp b/src/coreclr/nativeaot/Runtime/nativeeventsource.cpp deleted file mode 100644 index 96ab33f3fa7e8..0000000000000 --- a/src/coreclr/nativeaot/Runtime/nativeeventsource.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include "common.h" -#include "gcenv.h" -#include "clretwallmain.h" - -#ifdef FEATURE_PERFTRACING - -// These are native call into corresponding FireEtw* events for events that want to be emitted from the managed -// side using NativeRuntimeEventSource. -// See https://github.com/dotnet/runtime/pull/47829 for an example of how to do this. -EXTERN_C NATIVEAOT_API void __cdecl RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) -{ - FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); -} - -// extern "C" void __cdecl LogThreadPoolWorkerThreadStop(uint activeWorkerThreadCount, uint retiredWorkerThreadCount, short clrInstanceID) -// { -// FireEtwThreadPoolWorkerThreadStop(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolWorkerThreadWait(uint activeWorkerThreadCount, uint retiredWorkerThreadCount, short clrInstanceID) -// { -// FireEtwThreadPoolWorkerThreadWait(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolMinMaxThreads(short minWorkerThreads, short maxWorkerThreads, short minIOCompletionThreads, short maxIOCompletionThreads, short clrInstanceID) -// { -// FireEtwThreadPoolMinMaxThreads(minWorkerThreads, maxWorkerThreads, minIOCompletionThreads, maxIOCompletionThreads, clrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolWorkerThreadAdjustmentSample(double throughput, short clrInstanceID) -// { -// FireEtwThreadPoolWorkerThreadAdjustmentSample(throughput, clrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolWorkerThreadAdjustmentAdjustment(double averageThroughput, uint newWorkerThreadCount, uint reason, short clrInstanceID) -// { -// FireEtwThreadPoolWorkerThreadAdjustmentAdjustment(averageThroughput, newWorkerThreadCount, reason, clrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolWorkerThreadAdjustmentStats(double duration, double throughput, double threadWave, double throughputWave, double throughputErrorEstimate, double AverageThroughputErrorEstimate, double ThroughputRatio, double confidence, double newControlSetting, short newThreadWaveMagnitude, short ClrInstanceID) -// { -// FireEtwThreadPoolWorkerThreadAdjustmentStats(duration, throughput, threadWave, throughputWave, throughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, confidence, newControlSetting, newThreadWaveMagnitude, ClrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolIOEnqueue(void* nativeOverlapped, void* overlapped, bool multiDequeues, short ClrInstanceID) -// { -// FireEtwThreadPoolIOEnqueue(nativeOverlapped, overlapped, multiDequeues, ClrInstanceID); -// } - -// extern "C" void __cdecl LogThreadPoolIODequeue(void* nativeOverlapped, void* overlapped, short ClrInstanceID) -// { -// QCALL_CONTRACT; -// BEGIN_QCALL; - -// FireEtwThreadPoolIODequeue(nativeOverlapped, overlapped, ClrInstanceID); - -// END_QCALL; -// } - -// extern "C" void __cdecl LogThreadPoolWorkingThreadCount(uint count, short ClrInstanceID) -// { -// QCALL_CONTRACT; -// BEGIN_QCALL; - -// FireEtwThreadPoolWorkingThreadCount(count, ClrInstanceID); - -// END_QCALL; -// } - -// extern "C" void __cdecl LogThreadPoolIOPack(void* nativeOverlapped, void* overlapped, short ClrInstanceID) -// { -// QCALL_CONTRACT; -// BEGIN_QCALL; - -// FireEtwThreadPoolIOPack(nativeOverlapped, overlapped, ClrInstanceID); - -// END_QCALL; -// } -#endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs index f996405f4b46d..2d251fcca3953 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs @@ -16,22 +16,23 @@ namespace System.Diagnostics.Tracing // It contains the runtime specific interop to native event sinks. internal sealed partial class NativeRuntimeEventSource : EventSource { -// private const string RuntimeLibrary = "*"; [NonEvent] internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) + { + RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) + { + RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + } // [NonEvent] // [LibraryImport(RuntimeLibrary)] diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 106b57c639fbf..03e0e8ce5392f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -774,7 +774,77 @@ internal static unsafe partial void RhEventPipeInternal_WriteEventData( [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, NativeRuntimeEventSource.ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkerThreadAdjustmentStats( + // double Duration, + // double Throughput, + // double ThreadPoolWorkerThreadWait, + // double ThroughputWave, + // double ThroughputErrorEstimate, + // double AverageThroughputErrorEstimate, + // double ThroughputRatio, + // double Confidence, + // double NewControlSetting, + // ushort NewThreadWaveMagnitude, + // ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolIOEnqueue( + // IntPtr NativeOverlapped, + // IntPtr Overlapped, + // [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, + // ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolIODequeue( + // IntPtr NativeOverlapped, + // IntPtr Overlapped, + // ushort ClrInstanceID); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolWorkingThreadCount( + // uint Count, + // ushort ClrInstanceID + // ); + + // [NonEvent] + // [LibraryImport(RuntimeLibrary)] + // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + // internal static partial void LogThreadPoolIOPack( + // IntPtr NativeOverlapped, + // IntPtr Overlapped, + // ushort ClrInstanceID); #endif // FEATURE_PERFTRACING // From 974159f60b8ba42ced5456eb0a6ba65c13422453 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 2 Jun 2023 10:55:59 -0700 Subject: [PATCH 03/22] full portable threadpool support --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 162 ++++++- .../Runtime/clreventpipewriteevents.h | 90 ++++ .../Runtime/disabledeventpipeinternal.cpp | 68 ++- .../Runtime/eventpipe/dotnetruntime.cpp | 448 ++++++++++++++++++ .../nativeaot/Runtime/eventpipeadapter.h | 4 +- .../nativeaot/Runtime/eventpipeinternal.cpp | 68 ++- ...ortableThreadPool.NativeSinks.NativeAot.cs | 128 ++--- .../src/System/Runtime/RuntimeImports.cs | 127 +++-- 8 files changed, 963 insertions(+), 132 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index 218dff3fc6977..99b4b29ddfd77 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -706,7 +706,7 @@ inline ULONG FireEtwGCSuspendEEBegin_V1( inline BOOL EventEnabledThreadPoolWorkerThreadStart(void) {return EventPipeEventEnabledThreadPoolWorkerThreadStart();}// || EventXplatEnabledThreadPoolWorkerThreadStart();} -inline ULONG FireEtwThreadPoolWorkerThreadStart( +inline uint32_t FireEtwThreadPoolWorkerThreadStart( const unsigned int ActiveWorkerThreadCount, const unsigned int RetiredWorkerThreadCount, const unsigned short ClrInstanceID, @@ -714,8 +714,166 @@ inline ULONG FireEtwThreadPoolWorkerThreadStart( const GUID * RelatedActivityId = nullptr ) { - ULONG status = EventPipeWriteEventThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); + uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); return status; } + +inline uint32_t FireEtwThreadPoolWorkerThreadStop( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadStop(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); + // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); + return status; +} + +inline uint32_t FireEtwThreadPoolWorkerThreadWait( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadWait(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); + // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolMinMaxThreads(void) {return EventPipeEventEnabledThreadPoolMinMaxThreads();} + +inline uint32_t FireEtwThreadPoolMinMaxThreads( + const unsigned short MinWorkerThreads, + const unsigned short MaxWorkerThreads, + const unsigned short MinIOCompletionThreads, + const unsigned short MaxIOCompletionThreads, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolMinMaxThreads(MinWorkerThreads,MaxWorkerThreads,MinIOCompletionThreads,MaxIOCompletionThreads,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolMinMaxThreads(MinWorkerThreads,MaxWorkerThreads,MinIOCompletionThreads,MaxIOCompletionThreads,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolWorkerThreadAdjustmentSample(void) {return EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentSample();} + +inline uint32_t FireEtwThreadPoolWorkerThreadAdjustmentSample( + const double Throughput, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadAdjustmentSample(Throughput,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolWorkerThreadAdjustmentSample(Throughput,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolWorkerThreadAdjustmentAdjustment(void) {return EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentAdjustment();} + +inline uint32_t FireEtwThreadPoolWorkerThreadAdjustmentAdjustment( + const double AverageThroughput, + const unsigned int NewWorkerThreadCount, + const unsigned int Reason, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput,NewWorkerThreadCount,Reason,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput,NewWorkerThreadCount,Reason,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolWorkerThreadAdjustmentStats(void) {return EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentStats();} + +inline uint32_t FireEtwThreadPoolWorkerThreadAdjustmentStats( + const double Duration, + const double Throughput, + const double ThreadWave, + const double ThroughputWave, + const double ThroughputErrorEstimate, + const double AverageThroughputErrorEstimate, + const double ThroughputRatio, + const double Confidence, + const double NewControlSetting, + const unsigned short NewThreadWaveMagnitude, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadAdjustmentStats(Duration,Throughput,ThreadWave,ThroughputWave,ThroughputErrorEstimate,AverageThroughputErrorEstimate,ThroughputRatio,Confidence,NewControlSetting,NewThreadWaveMagnitude,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolWorkerThreadAdjustmentStats(Duration,Throughput,ThreadWave,ThroughputWave,ThroughputErrorEstimate,AverageThroughputErrorEstimate,ThroughputRatio,Confidence,NewControlSetting,NewThreadWaveMagnitude,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolIOEnqueue(void) {return EventPipeEventEnabledThreadPoolIOEnqueue();} + +inline uint32_t FireEtwThreadPoolIOEnqueue( + const void* NativeOverlapped, + const void* Overlapped, + const BOOL MultiDequeues, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolIOEnqueue(NativeOverlapped,Overlapped,MultiDequeues,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolIOEnqueue(NativeOverlapped,Overlapped,MultiDequeues,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolIODequeue(void) {return EventPipeEventEnabledThreadPoolIODequeue();} + +inline uint32_t FireEtwThreadPoolIODequeue( + const void* NativeOverlapped, + const void* Overlapped, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolIODequeue(NativeOverlapped,Overlapped,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolIODequeue(NativeOverlapped,Overlapped,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolWorkingThreadCount(void) {return EventPipeEventEnabledThreadPoolWorkingThreadCount();} + +inline uint32_t FireEtwThreadPoolWorkingThreadCount( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolWorkingThreadCount(Count,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolWorkingThreadCount(Count,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledThreadPoolIOPack(void) {return EventPipeEventEnabledThreadPoolIOPack();} + +inline uint32_t FireEtwThreadPoolIOPack( + const void* NativeOverlapped, + const void* Overlapped, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + uint32_t status = EventPipeWriteEventThreadPoolIOPack(NativeOverlapped,Overlapped,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatThreadPoolIOPack(NativeOverlapped,Overlapped,ClrInstanceID); + return status; +} + + #endif // __CLR_ETW_ALL_MAIN_H__ \ No newline at end of file diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index 93dca46051fed..b1e29713b8a86 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -374,3 +374,93 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); +BOOL EventPipeEventEnabledThreadPoolWorkerThreadStop(void); +ULONG EventPipeWriteEventThreadPoolWorkerThreadStop( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolWorkerThreadWait(void); +ULONG EventPipeWriteEventThreadPoolWorkerThreadWait( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolMinMaxThreads(void); +ULONG EventPipeWriteEventThreadPoolMinMaxThreads( + const unsigned short MinWorkerThreads, + const unsigned short MaxWorkerThreads, + const unsigned short MinIOCompletionThreads, + const unsigned short MaxIOCompletionThreads, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentSample(void); +ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentSample( + const double Throughput, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentAdjustment(void); +ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentAdjustment( + const double AverageThroughput, + const unsigned int NewWorkerThreadCount, + const unsigned int Reason, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentStats(void); +ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentStats( + const double Duration, + const double Throughput, + const double ThreadWave, + const double ThroughputWave, + const double ThroughputErrorEstimate, + const double AverageThroughputErrorEstimate, + const double ThroughputRatio, + const double Confidence, + const double NewControlSetting, + const unsigned short NewThreadWaveMagnitude, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolIOEnqueue(void); +ULONG EventPipeWriteEventThreadPoolIOEnqueue( + const void* NativeOverlapped, + const void* Overlapped, + const BOOL MultiDequeues, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolIODequeue(void); +ULONG EventPipeWriteEventThreadPoolIODequeue( + const void* NativeOverlapped, + const void* Overlapped, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolWorkingThreadCount(void); +ULONG EventPipeWriteEventThreadPoolWorkingThreadCount( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledThreadPoolIOPack(void); +ULONG EventPipeWriteEventThreadPoolIOPack( + const void* NativeOverlapped, + const void* Overlapped, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); diff --git a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp index 40d0745407a22..05a6def648d05 100644 --- a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp @@ -101,8 +101,74 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return FALSE; } -EXTERN_C NATIVEAOT_API void __cdecl RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) { PalDebugBreak(); } + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( + double Duration, + double Throughput, + double ThreadPoolWorkerThreadWait, + double ThroughputWave, + double ThroughputErrorEstimate, + double AverageThroughputErrorEstimate, + double ThroughputRatio, + double Confidence, + double NewControlSetting, + uint16_t NewThreadWaveMagnitude, + uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOEnqueue( + uint32_t * NativeOverlapped, + uint32_t * Overlapped, + bool MultiDequeues, + uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index ae1c362ea20c8..3c714dba16b95 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -131,6 +131,16 @@ EventPipeEvent *EventPipeEventGCRestartEEBegin_V1 = nullptr; EventPipeEvent *EventPipeEventGCSuspendEEEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCSuspendEEBegin_V1 = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStart = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStop = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkerThreadWait = nullptr; +EventPipeEvent *EventPipeEventThreadPoolMinMaxThreads = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkerThreadAdjustmentSample = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkerThreadAdjustmentAdjustment = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkerThreadAdjustmentStats = nullptr; +EventPipeEvent *EventPipeEventThreadPoolIOEnqueue = nullptr; +EventPipeEvent *EventPipeEventThreadPoolIODequeue = nullptr; +EventPipeEvent *EventPipeEventThreadPoolWorkingThreadCount = nullptr; +EventPipeEvent *EventPipeEventThreadPoolIOPack = nullptr; BOOL EventPipeEventEnabledDestroyGCHandle(void) { @@ -1855,6 +1865,435 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( return ERROR_SUCCESS; } +BOOL EventPipeEventEnabledThreadPoolWorkerThreadStop(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStop); +} + +ULONG EventPipeWriteEventThreadPoolWorkerThreadStop( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkerThreadStop()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ActiveWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(RetiredWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkerThreadStop, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolWorkerThreadWait(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadWait); +} + +ULONG EventPipeWriteEventThreadPoolWorkerThreadWait( + const unsigned int ActiveWorkerThreadCount, + const unsigned int RetiredWorkerThreadCount, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkerThreadWait()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ActiveWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(RetiredWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkerThreadWait, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolMinMaxThreads(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolMinMaxThreads); +} + +ULONG EventPipeWriteEventThreadPoolMinMaxThreads( + const unsigned short MinWorkerThreads, + const unsigned short MaxWorkerThreads, + const unsigned short MinIOCompletionThreads, + const unsigned short MaxIOCompletionThreads, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolMinMaxThreads()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(MinWorkerThreads, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(MaxWorkerThreads, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(MinIOCompletionThreads, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(MaxIOCompletionThreads, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolMinMaxThreads, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentSample(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadAdjustmentSample); +} + +ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentSample( + const double Throughput, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentSample()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Throughput, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkerThreadAdjustmentSample, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentAdjustment(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadAdjustmentAdjustment); +} + +ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentAdjustment( + const double AverageThroughput, + const unsigned int NewWorkerThreadCount, + const unsigned int Reason, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentAdjustment()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(AverageThroughput, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(NewWorkerThreadCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Reason, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkerThreadAdjustmentAdjustment, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentStats(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadAdjustmentStats); +} + +ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentStats( + const double Duration, + const double Throughput, + const double ThreadWave, + const double ThroughputWave, + const double ThroughputErrorEstimate, + const double AverageThroughputErrorEstimate, + const double ThroughputRatio, + const double Confidence, + const double NewControlSetting, + const unsigned short NewThreadWaveMagnitude, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentStats()) + return ERROR_SUCCESS; + + size_t size = 76; + BYTE stackBuffer[76]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Duration, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Throughput, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ThreadWave, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ThroughputWave, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ThroughputErrorEstimate, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(AverageThroughputErrorEstimate, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ThroughputRatio, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Confidence, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(NewControlSetting, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(NewThreadWaveMagnitude, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkerThreadAdjustmentStats, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolIOEnqueue(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolIOEnqueue); +} + +ULONG EventPipeWriteEventThreadPoolIOEnqueue( + const void* NativeOverlapped, + const void* Overlapped, + const BOOL MultiDequeues, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolIOEnqueue()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(NativeOverlapped, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Overlapped, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(MultiDequeues, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolIOEnqueue, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolIODequeue(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolIODequeue); +} + +ULONG EventPipeWriteEventThreadPoolIODequeue( + const void* NativeOverlapped, + const void* Overlapped, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolIODequeue()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(NativeOverlapped, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Overlapped, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolIODequeue, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolWorkingThreadCount(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkingThreadCount); +} + +ULONG EventPipeWriteEventThreadPoolWorkingThreadCount( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolWorkingThreadCount()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolWorkingThreadCount, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledThreadPoolIOPack(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolIOPack); +} + +ULONG EventPipeWriteEventThreadPoolIOPack( + const void* NativeOverlapped, + const void* Overlapped, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledThreadPoolIOPack()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(NativeOverlapped, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Overlapped, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventThreadPoolIOPack, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} typedef struct _MCGEN_TRACE_CONTEXT { @@ -2034,4 +2473,13 @@ void InitDotNETRuntime(void) EventPipeEventGCSuspendEEEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,8,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCSuspendEEBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,9,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventThreadPoolWorkerThreadStart = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,50,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventThreadPoolWorkerThreadStop = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,51,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventThreadPoolWorkerThreadWait = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,57,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventThreadPoolMinMaxThreads = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,59,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventThreadPoolWorkerThreadAdjustmentSample = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,54,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventThreadPoolWorkerThreadAdjustmentAdjustment = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,55,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventThreadPoolWorkerThreadAdjustmentStats = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,56,65536,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventThreadPoolIOEnqueue = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,63,2147549184,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventThreadPoolIODequeue = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,64,2147549184,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventThreadPoolWorkingThreadCount = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,60,65536,0,EP_EVENT_LEVEL_VERBOSE,true); } diff --git a/src/coreclr/nativeaot/Runtime/eventpipeadapter.h b/src/coreclr/nativeaot/Runtime/eventpipeadapter.h index 5fd85c342a81f..c4e8ff4642d8b 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeadapter.h +++ b/src/coreclr/nativeaot/Runtime/eventpipeadapter.h @@ -244,7 +244,7 @@ class EventPipeAdapter final return fileTime; } - static inline LONGLONG GetSessionStartTimestamp(EventPipeSession *session) + static inline int64_t GetSessionStartTimestamp(EventPipeSession *session) { STATIC_CONTRACT_NOTHROW; @@ -364,7 +364,7 @@ class EventPipeAdapter final return reinterpret_cast(ep_event_instance_get_related_activity_id_cref(eventInstance)); } - static inline const BYTE * GetEventData (EventPipeEventInstance *eventInstance) + static inline const uint8_t * GetEventData (EventPipeEventInstance *eventInstance) { STATIC_CONTRACT_NOTHROW; return ep_event_instance_get_data(eventInstance); diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 57e86d3362431..805aa1db1c552 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -180,8 +180,74 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return EventPipeAdapter::WaitForSessionSignal(sessionID, timeoutMs); } -EXTERN_C NATIVEAOT_API void __cdecl RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) { FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); } + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, Reason, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( + double Duration, + double Throughput, + double ThreadPoolWorkerThreadWait, + double ThroughputWave, + double ThroughputErrorEstimate, + double AverageThroughputErrorEstimate, + double ThroughputRatio, + double Confidence, + double NewControlSetting, + uint16_t NewThreadWaveMagnitude, + uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadAdjustmentStats(Duration, Throughput, ThreadPoolWorkerThreadWait, ThroughputWave, ThroughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, Confidence, NewControlSetting, NewThreadWaveMagnitude, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOEnqueue( + uint32_t * NativeOverlapped, + uint32_t * Overlapped, + bool MultiDequeues, + uint16_t ClrInstanceID) +{ + FireEtwThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkingThreadCount(Count, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); +} + #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs index 2d251fcca3953..1dd9710c1fa18 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs @@ -19,83 +19,93 @@ internal sealed partial class NativeRuntimeEventSource : EventSource [NonEvent] internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { - RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadStart(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { - RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { - RuntimeImports.RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, NativeRuntimeEventSource.ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID); + [NonEvent] + // Reason parameter is an enum in NativeRuntimeEventSource but passed here as the underlying type + internal static void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, uint Reason, ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, Reason, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadAdjustmentStats( - // double Duration, - // double Throughput, - // double ThreadPoolWorkerThreadWait, - // double ThroughputWave, - // double ThroughputErrorEstimate, - // double AverageThroughputErrorEstimate, - // double ThroughputRatio, - // double Confidence, - // double NewControlSetting, - // ushort NewThreadWaveMagnitude, - // ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolWorkerThreadAdjustmentStats( + double Duration, + double Throughput, + double ThreadPoolWorkerThreadWait, + double ThroughputWave, + double ThroughputErrorEstimate, + double AverageThroughputErrorEstimate, + double ThroughputRatio, + double Confidence, + double NewControlSetting, + ushort NewThreadWaveMagnitude, + ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats(Duration, Throughput, ThreadPoolWorkerThreadWait, ThroughputWave, + ThroughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, Confidence, NewControlSetting, NewThreadWaveMagnitude, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolIOEnqueue( - // IntPtr NativeOverlapped, - // IntPtr Overlapped, - // [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, - // ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolIOEnqueue( + IntPtr NativeOverlapped, + IntPtr Overlapped, + [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, + ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolIODequeue( - // IntPtr NativeOverlapped, - // IntPtr Overlapped, - // ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolIODequeue( + IntPtr NativeOverlapped, + IntPtr Overlapped, + ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkingThreadCount( - // uint Count, - // ushort ClrInstanceID - // ); + [NonEvent] + internal static void LogThreadPoolWorkingThreadCount( + uint Count, + ushort ClrInstanceID + ) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkingThreadCount(Count, ClrInstanceID); + } - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolIOPack( - // IntPtr NativeOverlapped, - // IntPtr Overlapped, - // ushort ClrInstanceID); + [NonEvent] + internal static void LogThreadPoolIOPack( + IntPtr NativeOverlapped, + IntPtr Overlapped, + ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); + } } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 03e0e8ce5392f..8122ea88c304f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Tracing; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -772,79 +773,71 @@ internal static unsafe partial void RhEventPipeInternal_WriteEventData( [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhNativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, NativeRuntimeEventSource.ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkerThreadAdjustmentStats( - // double Duration, - // double Throughput, - // double ThreadPoolWorkerThreadWait, - // double ThroughputWave, - // double ThroughputErrorEstimate, - // double AverageThroughputErrorEstimate, - // double ThroughputRatio, - // double Confidence, - // double NewControlSetting, - // ushort NewThreadWaveMagnitude, - // ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolIOEnqueue( - // IntPtr NativeOverlapped, - // IntPtr Overlapped, - // [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, - // ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolIODequeue( - // IntPtr NativeOverlapped, - // IntPtr Overlapped, - // ushort ClrInstanceID); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolWorkingThreadCount( - // uint Count, - // ushort ClrInstanceID - // ); - - // [NonEvent] - // [LibraryImport(RuntimeLibrary)] - // [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - // internal static partial void LogThreadPoolIOPack( - // IntPtr NativeOverlapped, - // IntPtr Overlapped, - // ushort ClrInstanceID); + internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, uint Reason, ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( + double Duration, + double Throughput, + double ThreadPoolWorkerThreadWait, + double ThroughputWave, + double ThroughputErrorEstimate, + double AverageThroughputErrorEstimate, + double ThroughputRatio, + double Confidence, + double NewControlSetting, + ushort NewThreadWaveMagnitude, + ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolIOEnqueue( + IntPtr NativeOverlapped, + IntPtr Overlapped, + [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, + ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolIODequeue( + IntPtr NativeOverlapped, + IntPtr Overlapped, + ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolWorkingThreadCount( + uint Count, + ushort ClrInstanceID + ); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogThreadPoolIOPack( + IntPtr NativeOverlapped, + IntPtr Overlapped, + ushort ClrInstanceID); #endif // FEATURE_PERFTRACING // From 5e0cfffb5e2c8f3ea7f3a122a1edf37dfb542492 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 7 Jun 2023 05:02:01 -0700 Subject: [PATCH 04/22] checkpoint before python script --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 56 ++++++ .../Runtime/clreventpipewriteevents.h | 28 +++ .../eventpipe/disableddotnetruntime.cpp | 22 +++ .../Runtime/eventpipe/dotnetruntime.cpp | 166 ++++++++++++++++++ .../eventsvalidation/GCFinalizers.csproj | 1 + 5 files changed, 273 insertions(+) diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index 99b4b29ddfd77..b729a8d61cc12 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -704,6 +704,62 @@ inline ULONG FireEtwGCSuspendEEBegin_V1( return status; } +inline BOOL EventEnabledDecreaseMemoryPressure(void) {return EventPipeEventEnabledDecreaseMemoryPressure();} + +inline ULONG FireEtwDecreaseMemoryPressure( + const unsigned __int64 BytesFreed, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventDecreaseMemoryPressure(BytesFreed,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatDecreaseMemoryPressure(BytesFreed,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledFinalizeObject(void) {return EventPipeEventEnabledFinalizeObject();}// || EventXplatEnabledFinalizeObject();} + +inline ULONG FireEtwFinalizeObject( + const void* TypeID, + const void* ObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventFinalizeObject(TypeID,ObjectID,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatFinalizeObject(TypeID,ObjectID,ClrInstanceID); + return status; +} + +inline BOOL EventEnabledGCFinalizersBegin_V1(void) {return EventPipeEventEnabledGCFinalizersBegin_V1();}// || EventXplatEnabledGCFinalizersBegin_V1();} + +inline ULONG FireEtwGCFinalizersBegin_V1( + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCFinalizersBegin_V1(ClrInstanceID,ActivityId,RelatedActivityId); +// status &= FireEtXplatGCFinalizersBegin_V1(ClrInstanceID); + return status; +} + +inline BOOL EventEnabledGCFinalizersEnd_V1(void) {return EventPipeEventEnabledGCFinalizersEnd_V1();}// || EventXplatEnabledGCFinalizersEnd_V1();} + +inline ULONG FireEtwGCFinalizersEnd_V1( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCFinalizersEnd_V1(Count,ClrInstanceID,ActivityId,RelatedActivityId); + //status &= FireEtXplatGCFinalizersEnd_V1(Count,ClrInstanceID); + return status; +} + inline BOOL EventEnabledThreadPoolWorkerThreadStart(void) {return EventPipeEventEnabledThreadPoolWorkerThreadStart();}// || EventXplatEnabledThreadPoolWorkerThreadStart();} inline uint32_t FireEtwThreadPoolWorkerThreadStart( diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index b1e29713b8a86..7ad75d19645b9 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -366,6 +366,34 @@ ULONG EventPipeWriteEventGCSuspendEEBegin_V1( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); +BOOL EventPipeEventEnabledDecreaseMemoryPressure(void); +ULONG EventPipeWriteEventDecreaseMemoryPressure( + const unsigned __int64 BytesFreed, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledFinalizeObject(void); +ULONG EventPipeWriteEventFinalizeObject( + const void* TypeID, + const void* ObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCFinalizersBegin_V1(void); +ULONG EventPipeWriteEventGCFinalizersBegin_V1( + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCFinalizersEnd_V1(void); +ULONG EventPipeWriteEventGCFinalizersEnd_V1( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void); ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( const unsigned int ActiveWorkerThreadCount, diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp index eb767a6c46472..a4631a5d5ab2f 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp @@ -481,3 +481,25 @@ ULONG EventPipeWriteEventGCRestartEEEnd_V1( { return 0; } + +ULONG EventPipeWriteEventDecreaseMemoryPressure( + const unsigned __int64 BytesFreed, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + +ULONG EventPipeWriteEventFinalizeObject( + const void* TypeID, + const void* ObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index 3c714dba16b95..4db5926714bad 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -130,6 +130,10 @@ EventPipeEvent *EventPipeEventGCRestartEEEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCRestartEEBegin_V1 = nullptr; EventPipeEvent *EventPipeEventGCSuspendEEEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCSuspendEEBegin_V1 = nullptr; +EventPipeEvent *EventPipeEventDecreaseMemoryPressure = nullptr; +EventPipeEvent *EventPipeEventFinalizeObject = nullptr; +EventPipeEvent *EventPipeEventGCFinalizersBegin_V1 = nullptr; +EventPipeEvent *EventPipeEventGCFinalizersEnd_V1 = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStart = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStop = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadWait = nullptr; @@ -1823,6 +1827,163 @@ ULONG EventPipeWriteEventGCSuspendEEBegin_V1( return ERROR_SUCCESS; } +BOOL EventPipeEventEnabledDecreaseMemoryPressure(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventDecreaseMemoryPressure); +} + +ULONG EventPipeWriteEventDecreaseMemoryPressure( + const unsigned __int64 BytesFreed, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledDecreaseMemoryPressure()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(BytesFreed, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventDecreaseMemoryPressure, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledFinalizeObject(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventFinalizeObject); +} + +ULONG EventPipeWriteEventFinalizeObject( + const void* TypeID, + const void* ObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledFinalizeObject()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(TypeID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ObjectID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventFinalizeObject, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCFinalizersBegin_V1(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFinalizersBegin_V1); +} + +ULONG EventPipeWriteEventGCFinalizersBegin_V1( + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCFinalizersBegin_V1()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCFinalizersBegin_V1, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCFinalizersEnd_V1(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFinalizersEnd_V1); +} + +ULONG EventPipeWriteEventGCFinalizersEnd_V1( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCFinalizersEnd_V1()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCFinalizersEnd_V1, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + return ERROR_SUCCESS; +} + + BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void) { return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStart); @@ -2295,6 +2456,7 @@ ULONG EventPipeWriteEventThreadPoolIOPack( return ERROR_SUCCESS; } + typedef struct _MCGEN_TRACE_CONTEXT { TRACEHANDLE RegistrationHandle; @@ -2472,6 +2634,10 @@ void InitDotNETRuntime(void) EventPipeEventGCRestartEEBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,7,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCSuspendEEEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,8,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCSuspendEEBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,9,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventDecreaseMemoryPressure = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,201,1,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventFinalizeObject = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,29,1,0,EP_EVENT_LEVEL_VERBOSE,false); + EventPipeEventGCFinalizersBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,14,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventGCFinalizersEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,13,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventThreadPoolWorkerThreadStart = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,50,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventThreadPoolWorkerThreadStop = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,51,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventThreadPoolWorkerThreadWait = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,57,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); diff --git a/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj b/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj index 794a4794d1526..bd45959f8c021 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj +++ b/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj @@ -8,6 +8,7 @@ true true + true From 21c63f87c3472d7629ecf38f1cc90ddad7b1f700 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 7 Jun 2023 10:30:10 -0700 Subject: [PATCH 05/22] Additional GC event support --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 207 +++++- .../Runtime/clreventpipewriteevents.h | 136 ++++ .../Runtime/eventpipe/dotnetruntime.cpp | 604 +++++++++++++++++- src/coreclr/nativeaot/Runtime/eventtrace.h | 2 +- 4 files changed, 946 insertions(+), 3 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index b729a8d61cc12..c791db402e0ce 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -931,5 +931,210 @@ inline uint32_t FireEtwThreadPoolIOPack( return status; } +inline BOOL EventEnabledGCAllocationTick_V4(void) {return EventPipeEventEnabledGCAllocationTick_V4();} - #endif // __CLR_ETW_ALL_MAIN_H__ \ No newline at end of file +inline ULONG FireEtwGCAllocationTick_V4( + const unsigned int AllocationAmount, + const unsigned int AllocationKind, + const unsigned short ClrInstanceID, + const unsigned __int64 AllocationAmount64, + const void* TypeID, + const wchar_t* TypeName, + const unsigned int HeapIndex, + const void* Address, + const unsigned __int64 ObjectSize, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCAllocationTick_V4(AllocationAmount,AllocationKind,ClrInstanceID,AllocationAmount64,TypeID,TypeName,HeapIndex,Address,ObjectSize,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCHeapStats_V2(void) {return EventPipeEventEnabledGCHeapStats_V2();} + +inline ULONG FireEtwGCHeapStats_V2( + const unsigned __int64 GenerationSize0, + const unsigned __int64 TotalPromotedSize0, + const unsigned __int64 GenerationSize1, + const unsigned __int64 TotalPromotedSize1, + const unsigned __int64 GenerationSize2, + const unsigned __int64 TotalPromotedSize2, + const unsigned __int64 GenerationSize3, + const unsigned __int64 TotalPromotedSize3, + const unsigned __int64 FinalizationPromotedSize, + const unsigned __int64 FinalizationPromotedCount, + const unsigned int PinnedObjectCount, + const unsigned int SinkBlockCount, + const unsigned int GCHandleCount, + const unsigned short ClrInstanceID, + const unsigned __int64 GenerationSize4, + const unsigned __int64 TotalPromotedSize4, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCHeapStats_V2(GenerationSize0,TotalPromotedSize0,GenerationSize1,TotalPromotedSize1,GenerationSize2,TotalPromotedSize2,GenerationSize3,TotalPromotedSize3,FinalizationPromotedSize,FinalizationPromotedCount,PinnedObjectCount,SinkBlockCount,GCHandleCount,ClrInstanceID,GenerationSize4,TotalPromotedSize4,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCSampledObjectAllocationHigh(void) {return EventPipeEventEnabledGCSampledObjectAllocationHigh();} + +inline ULONG FireEtwGCSampledObjectAllocationHigh( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCSampledObjectAllocationHigh(Address,TypeID,ObjectCountForTypeSample,TotalSizeForTypeSample,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCSampledObjectAllocationLow(void) {return EventPipeEventEnabledGCSampledObjectAllocationLow();} + +inline ULONG FireEtwGCSampledObjectAllocationLow( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCSampledObjectAllocationLow(Address,TypeID,ObjectCountForTypeSample,TotalSizeForTypeSample,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledPinObjectAtGCTime(void) {return EventPipeEventEnabledPinObjectAtGCTime();} + +inline ULONG FireEtwPinObjectAtGCTime( + const void* HandleID, + const void* ObjectID, + const unsigned __int64 ObjectSize, + const wchar_t* TypeName, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventPinObjectAtGCTime(HandleID,ObjectID,ObjectSize,TypeName,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCBulkRootStaticVar(void) {return EventPipeEventEnabledGCBulkRootStaticVar();} + +inline ULONG FireEtwGCBulkRootStaticVar( + const unsigned int Count, + const unsigned __int64 AppDomainID, + const unsigned short ClrInstanceID, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCBulkRootStaticVar(Count,AppDomainID,ClrInstanceID,Values_ElementSize, Values,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledIncreaseMemoryPressure(void) {return EventPipeEventEnabledIncreaseMemoryPressure();} + +inline ULONG FireEtwIncreaseMemoryPressure( + const unsigned __int64 BytesAllocated, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventIncreaseMemoryPressure(BytesAllocated,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCGlobalHeapHistory_V4(void) {return EventPipeEventEnabledGCGlobalHeapHistory_V4();} + +inline ULONG FireEtwGCGlobalHeapHistory_V4( + const unsigned __int64 FinalYoungestDesired, + const signed int NumHeaps, + const unsigned int CondemnedGeneration, + const unsigned int Gen0ReductionCount, + const unsigned int Reason, + const unsigned int GlobalMechanisms, + const unsigned short ClrInstanceID, + const unsigned int PauseMode, + const unsigned int MemoryPressure, + const unsigned int CondemnReasons0, + const unsigned int CondemnReasons1, + const unsigned int Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCGlobalHeapHistory_V4(FinalYoungestDesired,NumHeaps,CondemnedGeneration,Gen0ReductionCount,Reason,GlobalMechanisms,ClrInstanceID,PauseMode,MemoryPressure,CondemnReasons0,CondemnReasons1,Count,Values_ElementSize, Values,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGenAwareBegin(void) {return EventPipeEventEnabledGenAwareBegin();} + +inline ULONG FireEtwGenAwareBegin( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGenAwareBegin(Count,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGenAwareEnd(void) {return EventPipeEventEnabledGenAwareEnd();} + +inline ULONG FireEtwGenAwareEnd( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGenAwareEnd(Count,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCLOHCompact(void) {return EventPipeEventEnabledGCLOHCompact();} + +inline ULONG FireEtwGCLOHCompact( + const unsigned short ClrInstanceID, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCLOHCompact(ClrInstanceID,Count,Values_ElementSize, Values,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledGCFitBucketInfo(void) {return EventPipeEventEnabledGCFitBucketInfo();} + +inline ULONG FireEtwGCFitBucketInfo( + const unsigned short ClrInstanceID, + const unsigned short BucketKind, + const unsigned __int64 TotalSize, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventGCFitBucketInfo(ClrInstanceID,BucketKind,TotalSize,Count,Values_ElementSize, Values,ActivityId,RelatedActivityId); + return status; +} +#endif // __CLR_ETW_ALL_MAIN_H__ \ No newline at end of file diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index 7ad75d19645b9..cef878005c5be 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -492,3 +492,139 @@ ULONG EventPipeWriteEventThreadPoolIOPack( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); +BOOL EventPipeEventEnabledGCAllocationTick_V4(void); +ULONG EventPipeWriteEventGCAllocationTick_V4( + const unsigned int AllocationAmount, + const unsigned int AllocationKind, + const unsigned short ClrInstanceID, + const unsigned __int64 AllocationAmount64, + const void* TypeID, + const wchar_t* TypeName, + const unsigned int HeapIndex, + const void* Address, + const unsigned __int64 ObjectSize, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCHeapStats_V2(void); +ULONG EventPipeWriteEventGCHeapStats_V2( + const unsigned __int64 GenerationSize0, + const unsigned __int64 TotalPromotedSize0, + const unsigned __int64 GenerationSize1, + const unsigned __int64 TotalPromotedSize1, + const unsigned __int64 GenerationSize2, + const unsigned __int64 TotalPromotedSize2, + const unsigned __int64 GenerationSize3, + const unsigned __int64 TotalPromotedSize3, + const unsigned __int64 FinalizationPromotedSize, + const unsigned __int64 FinalizationPromotedCount, + const unsigned int PinnedObjectCount, + const unsigned int SinkBlockCount, + const unsigned int GCHandleCount, + const unsigned short ClrInstanceID, + const unsigned __int64 GenerationSize4, + const unsigned __int64 TotalPromotedSize4, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCSampledObjectAllocationHigh(void); +ULONG EventPipeWriteEventGCSampledObjectAllocationHigh( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCSampledObjectAllocationLow(void); +ULONG EventPipeWriteEventGCSampledObjectAllocationLow( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledPinObjectAtGCTime(void); +ULONG EventPipeWriteEventPinObjectAtGCTime( + const void* HandleID, + const void* ObjectID, + const unsigned __int64 ObjectSize, + const wchar_t* TypeName, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCBulkRootStaticVar(void); +ULONG EventPipeWriteEventGCBulkRootStaticVar( + const unsigned int Count, + const unsigned __int64 AppDomainID, + const unsigned short ClrInstanceID, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledIncreaseMemoryPressure(void); +ULONG EventPipeWriteEventIncreaseMemoryPressure( + const unsigned __int64 BytesAllocated, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCGlobalHeapHistory_V4(void); +ULONG EventPipeWriteEventGCGlobalHeapHistory_V4( + const unsigned __int64 FinalYoungestDesired, + const signed int NumHeaps, + const unsigned int CondemnedGeneration, + const unsigned int Gen0ReductionCount, + const unsigned int Reason, + const unsigned int GlobalMechanisms, + const unsigned short ClrInstanceID, + const unsigned int PauseMode, + const unsigned int MemoryPressure, + const unsigned int CondemnReasons0, + const unsigned int CondemnReasons1, + const unsigned int Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGenAwareBegin(void); +ULONG EventPipeWriteEventGenAwareBegin( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGenAwareEnd(void); +ULONG EventPipeWriteEventGenAwareEnd( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCLOHCompact(void); +ULONG EventPipeWriteEventGCLOHCompact( + const unsigned short ClrInstanceID, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledGCFitBucketInfo(void); +ULONG EventPipeWriteEventGCFitBucketInfo( + const unsigned short ClrInstanceID, + const unsigned short BucketKind, + const unsigned __int64 TotalSize, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); + diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index 4db5926714bad..b2fcec693c7b3 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -145,6 +145,18 @@ EventPipeEvent *EventPipeEventThreadPoolIOEnqueue = nullptr; EventPipeEvent *EventPipeEventThreadPoolIODequeue = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkingThreadCount = nullptr; EventPipeEvent *EventPipeEventThreadPoolIOPack = nullptr; +EventPipeEvent *EventPipeEventGCAllocationTick_V4 = nullptr; +EventPipeEvent *EventPipeEventGCHeapStats_V2 = nullptr; +EventPipeEvent *EventPipeEventGCSampledObjectAllocationHigh = nullptr; +EventPipeEvent *EventPipeEventGCSampledObjectAllocationLow = nullptr; +EventPipeEvent *EventPipeEventPinObjectAtGCTime = nullptr; +EventPipeEvent *EventPipeEventGCBulkRootStaticVar = nullptr; +EventPipeEvent *EventPipeEventIncreaseMemoryPressure = nullptr; +EventPipeEvent *EventPipeEventGCGlobalHeapHistory_V4 = nullptr; +EventPipeEvent *EventPipeEventGenAwareBegin = nullptr; +EventPipeEvent *EventPipeEventGenAwareEnd = nullptr; +EventPipeEvent *EventPipeEventGCLOHCompact = nullptr; +EventPipeEvent *EventPipeEventGCFitBucketInfo = nullptr; BOOL EventPipeEventEnabledDestroyGCHandle(void) { @@ -1983,7 +1995,6 @@ ULONG EventPipeWriteEventGCFinalizersEnd_V1( return ERROR_SUCCESS; } - BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void) { return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStart); @@ -2456,6 +2467,585 @@ ULONG EventPipeWriteEventThreadPoolIOPack( return ERROR_SUCCESS; } +BOOL EventPipeEventEnabledGCAllocationTick_V4(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCAllocationTick_V4); +} + +ULONG EventPipeWriteEventGCAllocationTick_V4( + const unsigned int AllocationAmount, + const unsigned int AllocationKind, + const unsigned short ClrInstanceID, + const unsigned __int64 AllocationAmount64, + const void* TypeID, + const wchar_t* TypeName, + const unsigned int HeapIndex, + const void* Address, + const unsigned __int64 ObjectSize, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCAllocationTick_V4()) + return ERROR_SUCCESS; + + size_t size = 110; + BYTE stackBuffer[110]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + if (!TypeName) { TypeName = L"NULL"; } + success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(AllocationAmount64, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TypeID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TypeName, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(HeapIndex, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Address, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ObjectSize, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCAllocationTick_V4, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCHeapStats_V2(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCHeapStats_V2); +} + +ULONG EventPipeWriteEventGCHeapStats_V2( + const unsigned __int64 GenerationSize0, + const unsigned __int64 TotalPromotedSize0, + const unsigned __int64 GenerationSize1, + const unsigned __int64 TotalPromotedSize1, + const unsigned __int64 GenerationSize2, + const unsigned __int64 TotalPromotedSize2, + const unsigned __int64 GenerationSize3, + const unsigned __int64 TotalPromotedSize3, + const unsigned __int64 FinalizationPromotedSize, + const unsigned __int64 FinalizationPromotedCount, + const unsigned int PinnedObjectCount, + const unsigned int SinkBlockCount, + const unsigned int GCHandleCount, + const unsigned short ClrInstanceID, + const unsigned __int64 GenerationSize4, + const unsigned __int64 TotalPromotedSize4, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCHeapStats_V2()) + return ERROR_SUCCESS; + + size_t size = 110; + BYTE stackBuffer[110]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(GenerationSize0, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalPromotedSize0, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(GenerationSize1, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalPromotedSize1, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(GenerationSize2, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalPromotedSize2, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(GenerationSize3, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalPromotedSize3, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(FinalizationPromotedSize, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(FinalizationPromotedCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(PinnedObjectCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(SinkBlockCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(GCHandleCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(GenerationSize4, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalPromotedSize4, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCHeapStats_V2, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCSampledObjectAllocationHigh(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCSampledObjectAllocationHigh); +} + +ULONG EventPipeWriteEventGCSampledObjectAllocationHigh( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCSampledObjectAllocationHigh()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Address, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TypeID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ObjectCountForTypeSample, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalSizeForTypeSample, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCSampledObjectAllocationHigh, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCSampledObjectAllocationLow(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCSampledObjectAllocationLow); +} + +ULONG EventPipeWriteEventGCSampledObjectAllocationLow( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCSampledObjectAllocationLow()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Address, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TypeID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ObjectCountForTypeSample, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalSizeForTypeSample, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCSampledObjectAllocationLow, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledPinObjectAtGCTime(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventPinObjectAtGCTime); +} + +ULONG EventPipeWriteEventPinObjectAtGCTime( + const void* HandleID, + const void* ObjectID, + const unsigned __int64 ObjectSize, + const wchar_t* TypeName, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledPinObjectAtGCTime()) + return ERROR_SUCCESS; + + size_t size = 90; + BYTE stackBuffer[90]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + if (!TypeName) { TypeName = L"NULL"; } + success &= WriteToBuffer(HandleID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ObjectID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ObjectSize, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TypeName, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventPinObjectAtGCTime, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCBulkRootStaticVar(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkRootStaticVar); +} + +ULONG EventPipeWriteEventGCBulkRootStaticVar( + const unsigned int Count, + const unsigned __int64 AppDomainID, + const unsigned short ClrInstanceID, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCBulkRootStaticVar()) + return ERROR_SUCCESS; + + size_t size = 46; + BYTE stackBuffer[46]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(AppDomainID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer((const BYTE *)Values, (int)(Values_ElementSize), buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCBulkRootStaticVar, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledIncreaseMemoryPressure(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventIncreaseMemoryPressure); +} + +ULONG EventPipeWriteEventIncreaseMemoryPressure( + const unsigned __int64 BytesAllocated, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledIncreaseMemoryPressure()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(BytesAllocated, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventIncreaseMemoryPressure, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCGlobalHeapHistory_V4(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCGlobalHeapHistory_V4); +} + +ULONG EventPipeWriteEventGCGlobalHeapHistory_V4( + const unsigned __int64 FinalYoungestDesired, + const signed int NumHeaps, + const unsigned int CondemnedGeneration, + const unsigned int Gen0ReductionCount, + const unsigned int Reason, + const unsigned int GlobalMechanisms, + const unsigned short ClrInstanceID, + const unsigned int PauseMode, + const unsigned int MemoryPressure, + const unsigned int CondemnReasons0, + const unsigned int CondemnReasons1, + const unsigned int Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCGlobalHeapHistory_V4()) + return ERROR_SUCCESS; + + size_t size = 82; + BYTE stackBuffer[82]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(FinalYoungestDesired, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(NumHeaps, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(CondemnedGeneration, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Gen0ReductionCount, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Reason, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(GlobalMechanisms, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(PauseMode, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(MemoryPressure, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(CondemnReasons0, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(CondemnReasons1, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer((const BYTE *)Values, (int)Values_ElementSize * (int)Count, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCGlobalHeapHistory_V4, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGenAwareBegin(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGenAwareBegin); +} + +ULONG EventPipeWriteEventGenAwareBegin( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGenAwareBegin()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGenAwareBegin, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGenAwareEnd(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGenAwareEnd); +} + +ULONG EventPipeWriteEventGenAwareEnd( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGenAwareEnd()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGenAwareEnd, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCLOHCompact(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCLOHCompact); +} + +ULONG EventPipeWriteEventGCLOHCompact( + const unsigned short ClrInstanceID, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCLOHCompact()) + return ERROR_SUCCESS; + + size_t size = 36; + BYTE stackBuffer[36]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer((const BYTE *)Values, (int)Values_ElementSize * (int)Count, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCLOHCompact, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledGCFitBucketInfo(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFitBucketInfo); +} + +ULONG EventPipeWriteEventGCFitBucketInfo( + const unsigned short ClrInstanceID, + const unsigned short BucketKind, + const unsigned __int64 TotalSize, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledGCFitBucketInfo()) + return ERROR_SUCCESS; + + size_t size = 46; + BYTE stackBuffer[46]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(BucketKind, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(TotalSize, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer((const BYTE *)Values, (int)Values_ElementSize * (int)Count, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventGCFitBucketInfo, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} typedef struct _MCGEN_TRACE_CONTEXT { @@ -2648,4 +3238,16 @@ void InitDotNETRuntime(void) EventPipeEventThreadPoolIOEnqueue = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,63,2147549184,0,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventThreadPoolIODequeue = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,64,2147549184,0,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventThreadPoolWorkingThreadCount = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,60,65536,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventGCAllocationTick_V4 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,10,1,4,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventGCHeapStats_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,4,1,2,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventGCSampledObjectAllocationHigh = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,20,2097152,0,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventGCSampledObjectAllocationLow = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,32,33554432,0,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventPinObjectAtGCTime = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,33,1,0,EP_EVENT_LEVEL_VERBOSE,false); + EventPipeEventGCBulkRootStaticVar = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,38,1048576,0,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventIncreaseMemoryPressure = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,200,1,0,EP_EVENT_LEVEL_VERBOSE,true); + EventPipeEventGCGlobalHeapHistory_V4 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,205,1,4,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventGenAwareBegin = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,206,1048576,0,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventGenAwareEnd = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,207,1048576,0,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventGCLOHCompact = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,208,1,0,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventGCFitBucketInfo = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,209,1,0,EP_EVENT_LEVEL_VERBOSE,true); } diff --git a/src/coreclr/nativeaot/Runtime/eventtrace.h b/src/coreclr/nativeaot/Runtime/eventtrace.h index e2e26857427dd..410a9ed55b680 100644 --- a/src/coreclr/nativeaot/Runtime/eventtrace.h +++ b/src/coreclr/nativeaot/Runtime/eventtrace.h @@ -338,6 +338,6 @@ inline void ETW::GCLog::RootReference( DWORD rootFlags) { } #endif -inline BOOL EventEnabledPinObjectAtGCTime() { return FALSE; } +//inline BOOL EventEnabledPinObjectAtGCTime() { return FALSE; } #endif //_VMEVENTTRACE_H_ From 95e214959512585c62fbd9d268ee1bf2c8b1def2 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 14 Jun 2023 08:01:07 -0700 Subject: [PATCH 06/22] NativeAOT to use sink threadpool file --- .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 2bd9120537752..74c3b4e3fc1b1 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 @@ -2531,8 +2531,8 @@ - - + + From dcda64ecb2f9d0452a0314c06c1203890f807371 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Sun, 18 Jun 2023 14:45:50 -0700 Subject: [PATCH 07/22] CI check --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 15 -- .../eventpipe/disableddotnetruntime.cpp | 202 ++++++++++++++++++ src/coreclr/nativeaot/Runtime/eventtrace.h | 2 - .../nativeaot/Runtime/gctoclreventsink.cpp | 27 +-- ...ortableThreadPool.NativeSinks.NativeAot.cs | 16 +- .../simpleprovidervalidation.cs | 44 +++- 6 files changed, 265 insertions(+), 41 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index 317934a2b0601..de40be56220f6 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -714,7 +714,6 @@ inline ULONG FireEtwDecreaseMemoryPressure( ) { ULONG status = EventPipeWriteEventDecreaseMemoryPressure(BytesFreed,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatDecreaseMemoryPressure(BytesFreed,ClrInstanceID); return status; } @@ -729,7 +728,6 @@ inline ULONG FireEtwFinalizeObject( ) { ULONG status = EventPipeWriteEventFinalizeObject(TypeID,ObjectID,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatFinalizeObject(TypeID,ObjectID,ClrInstanceID); return status; } @@ -742,7 +740,6 @@ inline ULONG FireEtwGCFinalizersBegin_V1( ) { ULONG status = EventPipeWriteEventGCFinalizersBegin_V1(ClrInstanceID,ActivityId,RelatedActivityId); -// status &= FireEtXplatGCFinalizersBegin_V1(ClrInstanceID); return status; } @@ -756,7 +753,6 @@ inline ULONG FireEtwGCFinalizersEnd_V1( ) { ULONG status = EventPipeWriteEventGCFinalizersEnd_V1(Count,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatGCFinalizersEnd_V1(Count,ClrInstanceID); return status; } @@ -771,7 +767,6 @@ inline uint32_t FireEtwThreadPoolWorkerThreadStart( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); - // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); return status; } @@ -784,7 +779,6 @@ inline uint32_t FireEtwThreadPoolWorkerThreadStop( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadStop(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); - // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); return status; } @@ -797,7 +791,6 @@ inline uint32_t FireEtwThreadPoolWorkerThreadWait( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadWait(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID,ActivityId,RelatedActivityId); - // status &= FireEtXplatThreadPoolWorkerThreadStart(ActiveWorkerThreadCount,RetiredWorkerThreadCount,ClrInstanceID); return status; } @@ -814,7 +807,6 @@ inline uint32_t FireEtwThreadPoolMinMaxThreads( ) { uint32_t status = EventPipeWriteEventThreadPoolMinMaxThreads(MinWorkerThreads,MaxWorkerThreads,MinIOCompletionThreads,MaxIOCompletionThreads,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolMinMaxThreads(MinWorkerThreads,MaxWorkerThreads,MinIOCompletionThreads,MaxIOCompletionThreads,ClrInstanceID); return status; } @@ -828,7 +820,6 @@ inline uint32_t FireEtwThreadPoolWorkerThreadAdjustmentSample( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadAdjustmentSample(Throughput,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolWorkerThreadAdjustmentSample(Throughput,ClrInstanceID); return status; } @@ -844,7 +835,6 @@ inline uint32_t FireEtwThreadPoolWorkerThreadAdjustmentAdjustment( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput,NewWorkerThreadCount,Reason,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput,NewWorkerThreadCount,Reason,ClrInstanceID); return status; } @@ -867,7 +857,6 @@ inline uint32_t FireEtwThreadPoolWorkerThreadAdjustmentStats( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkerThreadAdjustmentStats(Duration,Throughput,ThreadWave,ThroughputWave,ThroughputErrorEstimate,AverageThroughputErrorEstimate,ThroughputRatio,Confidence,NewControlSetting,NewThreadWaveMagnitude,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolWorkerThreadAdjustmentStats(Duration,Throughput,ThreadWave,ThroughputWave,ThroughputErrorEstimate,AverageThroughputErrorEstimate,ThroughputRatio,Confidence,NewControlSetting,NewThreadWaveMagnitude,ClrInstanceID); return status; } @@ -883,7 +872,6 @@ inline uint32_t FireEtwThreadPoolIOEnqueue( ) { uint32_t status = EventPipeWriteEventThreadPoolIOEnqueue(NativeOverlapped,Overlapped,MultiDequeues,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolIOEnqueue(NativeOverlapped,Overlapped,MultiDequeues,ClrInstanceID); return status; } @@ -898,7 +886,6 @@ inline uint32_t FireEtwThreadPoolIODequeue( ) { uint32_t status = EventPipeWriteEventThreadPoolIODequeue(NativeOverlapped,Overlapped,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolIODequeue(NativeOverlapped,Overlapped,ClrInstanceID); return status; } @@ -912,7 +899,6 @@ inline uint32_t FireEtwThreadPoolWorkingThreadCount( ) { uint32_t status = EventPipeWriteEventThreadPoolWorkingThreadCount(Count,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolWorkingThreadCount(Count,ClrInstanceID); return status; } @@ -927,7 +913,6 @@ inline uint32_t FireEtwThreadPoolIOPack( ) { uint32_t status = EventPipeWriteEventThreadPoolIOPack(NativeOverlapped,Overlapped,ClrInstanceID,ActivityId,RelatedActivityId); - //status &= FireEtXplatThreadPoolIOPack(NativeOverlapped,Overlapped,ClrInstanceID); return status; } diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp index f18c5ab704e52..535663ec57050 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp @@ -503,3 +503,205 @@ ULONG EventPipeWriteEventFinalizeObject( return 0; } +ULONG EventPipeWriteEventGCFinalizersBegin_V1( + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCFinalizersEnd_V1( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCAllocationTick_V4( + const unsigned int AllocationAmount, + const unsigned int AllocationKind, + const unsigned short ClrInstanceID, + const unsigned __int64 AllocationAmount64, + const void* TypeID, + const wchar_t* TypeName, + const unsigned int HeapIndex, + const void* Address, + const unsigned __int64 ObjectSize, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCHeapStats_V2( + const unsigned __int64 GenerationSize0, + const unsigned __int64 TotalPromotedSize0, + const unsigned __int64 GenerationSize1, + const unsigned __int64 TotalPromotedSize1, + const unsigned __int64 GenerationSize2, + const unsigned __int64 TotalPromotedSize2, + const unsigned __int64 GenerationSize3, + const unsigned __int64 TotalPromotedSize3, + const unsigned __int64 FinalizationPromotedSize, + const unsigned __int64 FinalizationPromotedCount, + const unsigned int PinnedObjectCount, + const unsigned int SinkBlockCount, + const unsigned int GCHandleCount, + const unsigned short ClrInstanceID, + const unsigned __int64 GenerationSize4, + const unsigned __int64 TotalPromotedSize4, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCSampledObjectAllocationHigh( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCSampledObjectAllocationLow( + const void* Address, + const void* TypeID, + const unsigned int ObjectCountForTypeSample, + const unsigned __int64 TotalSizeForTypeSample, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventPinObjectAtGCTime( + const void* HandleID, + const void* ObjectID, + const unsigned __int64 ObjectSize, + const wchar_t* TypeName, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCBulkRootStaticVar( + const unsigned int Count, + const unsigned __int64 AppDomainID, + const unsigned short ClrInstanceID, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventIncreaseMemoryPressure( + const unsigned __int64 BytesAllocated, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCGlobalHeapHistory_V4( + const unsigned __int64 FinalYoungestDesired, + const signed int NumHeaps, + const unsigned int CondemnedGeneration, + const unsigned int Gen0ReductionCount, + const unsigned int Reason, + const unsigned int GlobalMechanisms, + const unsigned short ClrInstanceID, + const unsigned int PauseMode, + const unsigned int MemoryPressure, + const unsigned int CondemnReasons0, + const unsigned int CondemnReasons1, + const unsigned int Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGenAwareBegin( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGenAwareEnd( + const unsigned int Count, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCLOHCompact( + const unsigned short ClrInstanceID, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} + + +ULONG EventPipeWriteEventGCFitBucketInfo( + const unsigned short ClrInstanceID, + const unsigned short BucketKind, + const unsigned __int64 TotalSize, + const unsigned short Count, + int Values_ElementSize, + const void* Values, + const GUID * ActivityId, + const GUID * RelatedActivityId +) +{ + return 0; +} diff --git a/src/coreclr/nativeaot/Runtime/eventtrace.h b/src/coreclr/nativeaot/Runtime/eventtrace.h index 116e052fab9cb..4328753db1f89 100644 --- a/src/coreclr/nativeaot/Runtime/eventtrace.h +++ b/src/coreclr/nativeaot/Runtime/eventtrace.h @@ -338,6 +338,4 @@ inline void ETW::GCLog::RootReference( DWORD rootFlags) { } #endif -//inline BOOL EventEnabledPinObjectAtGCTime() { return FALSE; } - #endif //_VMEVENTTRACE_H_ diff --git a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp index 8a4385f1bb5f8..427dbb96f2c18 100644 --- a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp +++ b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp @@ -70,11 +70,11 @@ void GCToCLREventSink::FireGCHeapStats_V2( { LIMITED_METHOD_CONTRACT; - // TODO: FireEtwGCHeapStats_V2 - FireEtwGCHeapStats_V1(generationSize0, totalPromotedSize0, generationSize1, totalPromotedSize1, + FireEtwGCHeapStats_V2(generationSize0, totalPromotedSize0, generationSize1, totalPromotedSize1, generationSize2, totalPromotedSize2, generationSize3, totalPromotedSize3, finalizationPromotedSize, finalizationPromotedCount, pinnedObjectCount, - sinkBlockCount, gcHandleCount, GetClrInstanceId()); + sinkBlockCount, gcHandleCount, GetClrInstanceId(), + generationSize4, totalPromotedSize4); } void GCToCLREventSink::FireGCCreateSegment_V1(void* address, size_t size, uint32_t type) @@ -142,9 +142,9 @@ void GCToCLREventSink::FireGCGlobalHeapHistory_V4(uint64_t finalYoungestDesired, { LIMITED_METHOD_CONTRACT; - // TODO: FireEtwGCGlobalHeapHistory_V4 - FireEtwGCGlobalHeapHistory_V2(finalYoungestDesired, numHeaps, condemnedGeneration, gen0reductionCount, reason, - globalMechanisms, GetClrInstanceId(), pauseMode, memoryPressure); + FireEtwGCGlobalHeapHistory_V4(finalYoungestDesired, numHeaps, condemnedGeneration, gen0reductionCount, reason, + globalMechanisms, GetClrInstanceId(), pauseMode, memoryPressure, condemnReasons0, condemnReasons1, + count, valuesLen, values); } void GCToCLREventSink::FireGCAllocationTick_V1(uint32_t allocationAmount, uint32_t allocationKind) @@ -167,14 +167,15 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, if (typeId != nullptr) { - FireEtwGCAllocationTick_V3(static_cast(allocationAmount), + FireEtwGCAllocationTick_V4(static_cast(allocationAmount), allocationKind, GetClrInstanceId(), allocationAmount, typeId, name, heapIndex, - objectAddress); + objectAddress, + objectSize); } } @@ -186,18 +187,12 @@ void GCToCLREventSink::FirePinObjectAtGCTime(void* object, uint8_t** ppObject) void GCToCLREventSink::FireGCLOHCompact(uint16_t count, uint32_t valuesLen, void* values) { - UNREFERENCED_PARAMETER(count); - UNREFERENCED_PARAMETER(valuesLen); - UNREFERENCED_PARAMETER(values); + FireEtwGCLOHCompact(GetClrInstanceId(), count, valuesLen, values); } void GCToCLREventSink::FireGCFitBucketInfo(uint16_t bucketKind, size_t size, uint16_t count, uint32_t valuesLen, void* values) { - UNREFERENCED_PARAMETER(bucketKind); - UNREFERENCED_PARAMETER(size); - UNREFERENCED_PARAMETER(count); - UNREFERENCED_PARAMETER(valuesLen); - UNREFERENCED_PARAMETER(values); + FireEtwGCFitBucketInfo(GetClrInstanceId(), bucketKind, size, count, valuesLen, values); } void GCToCLREventSink::FirePinPlugAtGCTime(uint8_t* plugStart, uint8_t* plugEnd, uint8_t* gapBeforeSize) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs index 1dd9710c1fa18..fd7021b58133e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs @@ -16,6 +16,13 @@ namespace System.Diagnostics.Tracing // It contains the runtime specific interop to native event sinks. internal sealed partial class NativeRuntimeEventSource : EventSource { + // We don't have these keywords defined from the genRuntimeEventSources.py, so we need to manually define them here. + public static class Keywords + { + public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000; + public const EventKeywords ThreadTransferKeyword = (EventKeywords)0x80000000; + } + [NonEvent] internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { @@ -46,12 +53,15 @@ internal static void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); } - [NonEvent] +#if TARGET_UNIX // Reason parameter is an enum in NativeRuntimeEventSource but passed here as the underlying type - internal static void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, uint Reason, ushort ClrInstanceID) + // In Windows, this event is not fired in managed code + [NonEvent] + internal static void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, Reason, ClrInstanceID); + RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, (uint)Reason, ClrInstanceID); } +#endif [NonEvent] internal static void LogThreadPoolWorkerThreadAdjustmentStats( diff --git a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs index a954e0c322989..f16185b94a4c2 100644 --- a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs +++ b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs @@ -32,10 +32,17 @@ public static int Main() var providers = new List() { new EventPipeProvider("MyEventSource", EventLevel.Verbose), - new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Verbose) + new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Verbose), + //GCKeyword (0x1): 0b1 + new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0xFFFF) }; var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, enableRundownProvider:false); + + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + if (ret < 0) return ret; else @@ -44,18 +51,45 @@ public static int Main() private static Dictionary _expectedEventCounts = new Dictionary() { - { "MyEventSource", 100_000 }, - { "Microsoft-DotNETCore-EventPipe", 1} + { "MyEventSource", 100 }, + { "Microsoft-DotNETCore-EventPipe", 1}, + { "Microsoft-Windows-DotNETRuntime", 1} }; private static Action _eventGeneratingAction = () => { - for (int i = 0; i < 100_000; i++) + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + List list = new List(); + for (int i = 0; i < 100; i++) { - if (i % 10_000 == 0) + list.Add(new Foo(i)); + if (i % 10 == 0) Logger.logger.Log($"Fired MyEvent {i:N0}/100,000 times..."); MyEventSource.Log.MyEvent(); } + int rndValue = new Random().Next(0, 100); + Console.WriteLine($"{list[rndValue].IValue}-{list[rndValue].SValue}"); + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); }; } + public class Foo + { + public int IValue { get; set; } + public string SValue { get; set; } + public Foo(int value) + { + IValue = value; + SValue = value.ToString(); + } + + ~Foo() + { + Console.WriteLine("In Destructor"); + } + } + } From 4d0c67d5ddfd43dfcab811d4e73e27ec56683f33 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 19 Jun 2023 12:35:30 -0700 Subject: [PATCH 08/22] Enable GC runtime tests --- src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp | 11 +++++++++++ .../tracing/eventpipe/eventsvalidation/GCEvents.cs | 13 +++++++++++-- .../eventpipe/eventsvalidation/GCEvents.csproj | 2 ++ .../providervalidation/providervalidation.cs | 13 +++++++++++-- .../providervalidation/providervalidation.csproj | 2 ++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp index 427dbb96f2c18..2e4b57d1ec7d2 100644 --- a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp +++ b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp @@ -167,6 +167,7 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, if (typeId != nullptr) { +#ifdef TARGET_WINDOWS FireEtwGCAllocationTick_V4(static_cast(allocationAmount), allocationKind, GetClrInstanceId(), @@ -176,6 +177,16 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, heapIndex, objectAddress, objectSize); +#else + FireEtwGCAllocationTick_V3(static_cast(allocationAmount), + allocationKind, + GetClrInstanceId(), + allocationAmount, + typeId, + name, + heapIndex, + objectAddress); +#endif } } diff --git a/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.cs b/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.cs index 868aab91453b7..2d2f0bb2aff91 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.cs +++ b/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.cs @@ -21,16 +21,25 @@ public static int Main() new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1) }; - return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents); + bool enableRundown = TestLibrary.Utilities.IsNativeAot? false: true; + Dictionary _expectedEventCounts = TestLibrary.Utilities.IsNativeAot? _expectedEventCountsNativeAOT: _expectedEventCountsCoreCLR; + + return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents, enableRundownProvider:enableRundown); } - private static Dictionary _expectedEventCounts = new Dictionary() + private static Dictionary _expectedEventCountsCoreCLR = new Dictionary() { { "Microsoft-Windows-DotNETRuntime", -1 }, { "Microsoft-Windows-DotNETRuntimeRundown", -1 }, { "Microsoft-DotNETCore-SampleProfiler", -1 } }; + private static Dictionary _expectedEventCountsNativeAOT = new Dictionary() + { + { "Microsoft-Windows-DotNETRuntime", -1 } + }; + + private static Action _eventGeneratingAction = () => { for (int i = 0; i < 50; i++) diff --git a/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj b/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj index 92eb223634307..a818d9955ee34 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj +++ b/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj @@ -8,10 +8,12 @@ true true + true + diff --git a/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs b/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs index 2da95c1523960..d51df1f34c8d3 100644 --- a/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs +++ b/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs @@ -35,20 +35,29 @@ public static int Main() new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Verbose) }; - var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024); + bool enableRundown = TestLibrary.Utilities.IsNativeAot? false: true; + + Dictionary _expectedEventCounts = TestLibrary.Utilities.IsNativeAot? _expectedEventCountsNativeAOT: _expectedEventCountsCoreCLR; + var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, enableRundownProvider:enableRundown); if (ret < 0) return ret; else return 100; } - private static Dictionary _expectedEventCounts = new Dictionary() + private static Dictionary _expectedEventCountsCoreCLR = new Dictionary() { { "MyEventSource", new ExpectedEventCount(100_000, 0.30f) }, { "Microsoft-Windows-DotNETRuntimeRundown", -1 }, { "Microsoft-DotNETCore-SampleProfiler", -1 } }; + private static Dictionary _expectedEventCountsNativeAOT = new Dictionary() + { + { "MyEventSource", 100_000 }, + { "Microsoft-DotNETCore-EventPipe", 1 } + }; + private static Action _eventGeneratingAction = () => { for (int i = 0; i < 100_000; i++) diff --git a/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj b/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj index 18068018243a0..916d67f99dbe0 100644 --- a/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj +++ b/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj @@ -7,10 +7,12 @@ true true + true + From aab2ab0762cfaf89d7af3655d2033c94c11c9a61 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 19 Jun 2023 14:08:06 -0700 Subject: [PATCH 09/22] Post main merge fixups --- ...ortableThreadPool.NativeSinks.NativeAot.cs | 7 -- .../simpleprovidervalidation.cs | 86 ++++++++++--------- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs index fd7021b58133e..e37f6cfa9ad74 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs @@ -16,13 +16,6 @@ namespace System.Diagnostics.Tracing // It contains the runtime specific interop to native event sinks. internal sealed partial class NativeRuntimeEventSource : EventSource { - // We don't have these keywords defined from the genRuntimeEventSources.py, so we need to manually define them here. - public static class Keywords - { - public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000; - public const EventKeywords ThreadTransferKeyword = (EventKeywords)0x80000000; - } - [NonEvent] internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { diff --git a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs index f16185b94a4c2..a5e8031953bb6 100644 --- a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs +++ b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs @@ -14,13 +14,6 @@ namespace Tracing.Tests.SimpleProviderValidation { - public sealed class MyEventSource : EventSource - { - private MyEventSource() {} - public static MyEventSource Log = new MyEventSource(); - public void MyEvent() { WriteEvent(1, "MyEvent"); } - } - public class ProviderValidation { public static int Main() @@ -31,13 +24,12 @@ public static int Main() var providers = new List() { - new EventPipeProvider("MyEventSource", EventLevel.Verbose), new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Verbose), //GCKeyword (0x1): 0b1 - new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0xFFFF) + new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1) }; - var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, enableRundownProvider:false); + var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents, enableRundownProvider:false); GC.Collect(); GC.WaitForPendingFinalizers(); @@ -51,45 +43,59 @@ public static int Main() private static Dictionary _expectedEventCounts = new Dictionary() { - { "MyEventSource", 100 }, - { "Microsoft-DotNETCore-EventPipe", 1}, - { "Microsoft-Windows-DotNETRuntime", 1} + { "Microsoft-Windows-DotNETRuntime", -1 } }; private static Action _eventGeneratingAction = () => { - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - List list = new List(); - for (int i = 0; i < 100; i++) + for (int i = 0; i < 50; i++) { - list.Add(new Foo(i)); if (i % 10 == 0) - Logger.logger.Log($"Fired MyEvent {i:N0}/100,000 times..."); - MyEventSource.Log.MyEvent(); + Logger.logger.Log($"Called GC.Collect() {i} times..."); + ProviderValidation providerValidation = new ProviderValidation(); + providerValidation = null; + GC.Collect(); } - int rndValue = new Random().Next(0, 100); - Console.WriteLine($"{list[rndValue].IValue}-{list[rndValue].SValue}"); - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); }; - } - public class Foo - { - public int IValue { get; set; } - public string SValue { get; set; } - public Foo(int value) - { - IValue = value; - SValue = value.ToString(); - } - ~Foo() + private static Func> _DoesTraceContainEvents = (source) => { - Console.WriteLine("In Destructor"); - } - } + int GCStartEvents = 0; + int GCEndEvents = 0; + source.Clr.GCStart += (eventData) => GCStartEvents += 1; + source.Clr.GCStop += (eventData) => GCEndEvents += 1; + + int GCRestartEEStartEvents = 0; + int GCRestartEEStopEvents = 0; + source.Clr.GCRestartEEStart += (eventData) => GCRestartEEStartEvents += 1; + source.Clr.GCRestartEEStop += (eventData) => GCRestartEEStopEvents += 1; + + int GCSuspendEEEvents = 0; + int GCSuspendEEEndEvents = 0; + source.Clr.GCSuspendEEStart += (eventData) => GCSuspendEEEvents += 1; + source.Clr.GCSuspendEEStop += (eventData) => GCSuspendEEEndEvents += 1; + + return () => { + Logger.logger.Log("Event counts validation"); + + Logger.logger.Log("GCStartEvents: " + GCStartEvents); + Logger.logger.Log("GCEndEvents: " + GCEndEvents); + bool GCStartStopResult = GCStartEvents >= 50 && GCEndEvents >= 50 && Math.Abs(GCStartEvents - GCEndEvents) <=2; + Logger.logger.Log("GCStartStopResult check: " + GCStartStopResult); + Logger.logger.Log("GCRestartEEStartEvents: " + GCRestartEEStartEvents); + Logger.logger.Log("GCRestartEEStopEvents: " + GCRestartEEStopEvents); + bool GCRestartEEStartStopResult = GCRestartEEStartEvents >= 50 && GCRestartEEStopEvents >= 50; + Logger.logger.Log("GCRestartEEStartStopResult check: " + GCRestartEEStartStopResult); + + Logger.logger.Log("GCSuspendEEEvents: " + GCSuspendEEEvents); + Logger.logger.Log("GCSuspendEEEndEvents: " + GCSuspendEEEndEvents); + bool GCSuspendEEStartStopResult = GCSuspendEEEvents >= 50 && GCSuspendEEEndEvents >= 50; + Logger.logger.Log("GCSuspendEEStartStopResult check: " + GCSuspendEEStartStopResult); + + return GCStartStopResult && GCRestartEEStartStopResult && GCSuspendEEStartStopResult ? 100 : -1; + }; + }; + + } } From 41f064450458186c2ea6127429b6071e777a4111 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 19 Jun 2023 14:47:10 -0700 Subject: [PATCH 10/22] change tests that run in CI --- eng/pipelines/runtime.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 784d3f86da5d6..24fc41ceef43a 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -248,7 +248,7 @@ extends: extraStepsTemplate: /eng/pipelines/coreclr/nativeaot-post-build-steps.yml extraStepsParameters: creator: dotnet-bot - testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' + testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;tracing/eventpipe/simpleprovidervalidation;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' liveLibrariesBuildConfig: Release testRunNamePrefixSuffix: NativeAOT_$(_BuildConfig) extraVariablesTemplates: @@ -290,7 +290,7 @@ extends: extraStepsTemplate: /eng/pipelines/coreclr/nativeaot-post-build-steps.yml extraStepsParameters: creator: dotnet-bot - testBuildArgs: 'nativeaot tree ";nativeaot;tracing/eventpipe/simpleprovidervalidation;"' + testBuildArgs: 'nativeaot tree ";nativeaot;tracing/eventpipe/providervalidation;"' liveLibrariesBuildConfig: Release testRunNamePrefixSuffix: NativeAOT_$(_BuildConfig) extraVariablesTemplates: From 6f5de9d78473130c5e4a8345264897035c6ef71f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 21 Jun 2023 13:40:06 -0700 Subject: [PATCH 11/22] Support native sinks for threading events --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 52 ++++++- .../Runtime/clreventpipewriteevents.h | 26 ++++ .../Runtime/disabledeventpipeinternal.cpp | 15 ++ .../Runtime/eventpipe/dotnetruntime.cpp | 136 ++++++++++++++++++ .../nativeaot/Runtime/eventpipeinternal.cpp | 15 ++ .../src/System.Private.CoreLib.csproj | 2 +- ...Source.Threading.NativeSinks.NativeAot.cs} | 30 +++- .../src/System/Runtime/RuntimeImports.cs | 12 ++ .../System.Private.CoreLib.Shared.projitems | 4 +- src/tests/tracing/Directory.Build.props | 8 ++ .../eventcounter/runtimecounters.csproj | 1 - .../EventListenerThreadPool.csproj | 1 - .../config/name_config_with_pid.csproj | 1 - .../diagnosticport/diagnosticport.csproj | 1 - .../eventsvalidation/ExceptionThrown_V1.cs | 12 +- .../ExceptionThrown_V1.csproj | 1 + .../eventsvalidation/GCEvents.csproj | 1 - .../eventsvalidation/GCFinalizers.cs | 12 +- .../eventsvalidation/GCFinalizers.csproj | 2 +- .../providervalidation.csproj | 1 - .../tracing/eventpipe/reverse/reverse.csproj | 1 - .../simpleprovidervalidation.csproj | 1 - 22 files changed, 310 insertions(+), 25 deletions(-) rename src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/{NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs => NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs} (78%) create mode 100644 src/tests/tracing/Directory.Build.props diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index de40be56220f6..9217753e0431e 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -717,7 +717,7 @@ inline ULONG FireEtwDecreaseMemoryPressure( return status; } -inline BOOL EventEnabledFinalizeObject(void) {return EventPipeEventEnabledFinalizeObject();}// || EventXplatEnabledFinalizeObject();} +inline BOOL EventEnabledFinalizeObject(void) {return EventPipeEventEnabledFinalizeObject();} inline ULONG FireEtwFinalizeObject( const void* TypeID, @@ -731,7 +731,7 @@ inline ULONG FireEtwFinalizeObject( return status; } -inline BOOL EventEnabledGCFinalizersBegin_V1(void) {return EventPipeEventEnabledGCFinalizersBegin_V1();}// || EventXplatEnabledGCFinalizersBegin_V1();} +inline BOOL EventEnabledGCFinalizersBegin_V1(void) {return EventPipeEventEnabledGCFinalizersBegin_V1();} inline ULONG FireEtwGCFinalizersBegin_V1( const unsigned short ClrInstanceID, @@ -743,7 +743,7 @@ inline ULONG FireEtwGCFinalizersBegin_V1( return status; } -inline BOOL EventEnabledGCFinalizersEnd_V1(void) {return EventPipeEventEnabledGCFinalizersEnd_V1();}// || EventXplatEnabledGCFinalizersEnd_V1();} +inline BOOL EventEnabledGCFinalizersEnd_V1(void) {return EventPipeEventEnabledGCFinalizersEnd_V1();} inline ULONG FireEtwGCFinalizersEnd_V1( const unsigned int Count, @@ -756,7 +756,51 @@ inline ULONG FireEtwGCFinalizersEnd_V1( return status; } -inline BOOL EventEnabledThreadPoolWorkerThreadStart(void) {return EventPipeEventEnabledThreadPoolWorkerThreadStart();}// || EventXplatEnabledThreadPoolWorkerThreadStart();} +inline BOOL EventEnabledContentionStart_V2(void) {return EventPipeEventEnabledContentionStart_V2();} + +inline ULONG FireEtwContentionStart_V2( + const unsigned char ContentionFlags, + const unsigned short ClrInstanceID, + const void* LockID, + const void* AssociatedObjectID, + const unsigned __int64 LockOwnerThreadID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventContentionStart_V2(ContentionFlags,ClrInstanceID,LockID,AssociatedObjectID,LockOwnerThreadID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledContentionStop_V1(void) {return EventPipeEventEnabledContentionStop_V1();} + +inline ULONG FireEtwContentionStop_V1( + const unsigned char ContentionFlags, + const unsigned short ClrInstanceID, + const double DurationNs, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventContentionStop_V1(ContentionFlags,ClrInstanceID,DurationNs,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledContentionLockCreated(void) {return EventPipeEventEnabledContentionLockCreated();} + +inline ULONG FireEtwContentionLockCreated( + const void* LockID, + const void* AssociatedObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +) +{ + ULONG status = EventPipeWriteEventContentionLockCreated(LockID,AssociatedObjectID,ClrInstanceID,ActivityId,RelatedActivityId); + return status; +} + +inline BOOL EventEnabledThreadPoolWorkerThreadStart(void) {return EventPipeEventEnabledThreadPoolWorkerThreadStart();} inline uint32_t FireEtwThreadPoolWorkerThreadStart( const unsigned int ActiveWorkerThreadCount, diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index a258103488bc9..2642664a6d422 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -394,6 +394,32 @@ ULONG EventPipeWriteEventGCFinalizersEnd_V1( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); +BOOL EventPipeEventEnabledContentionStart_V2(void); +ULONG EventPipeWriteEventContentionStart_V2( + const unsigned char ContentionFlags, + const unsigned short ClrInstanceID, + const void* LockID, + const void* AssociatedObjectID, + const unsigned __int64 LockOwnerThreadID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledContentionStop_V1(void); +ULONG EventPipeWriteEventContentionStop_V1( + const unsigned char ContentionFlags, + const unsigned short ClrInstanceID, + const double DurationNs, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); +BOOL EventPipeEventEnabledContentionLockCreated(void); +ULONG EventPipeWriteEventContentionLockCreated( + const void* LockID, + const void* AssociatedObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId = nullptr, + const GUID * RelatedActivityId = nullptr +); BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void); ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( const unsigned int ActiveWorkerThreadCount, diff --git a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp index 05a6def648d05..584d50b334c14 100644 --- a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp @@ -101,6 +101,21 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return FALSE; } +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) +{ + PalDebugBreak(); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) +{ + PalDebugBreak(); +} + EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) { PalDebugBreak(); diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index e235b62428bbc..a934973031801 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -134,6 +134,9 @@ EventPipeEvent *EventPipeEventDecreaseMemoryPressure = nullptr; EventPipeEvent *EventPipeEventFinalizeObject = nullptr; EventPipeEvent *EventPipeEventGCFinalizersBegin_V1 = nullptr; EventPipeEvent *EventPipeEventGCFinalizersEnd_V1 = nullptr; +EventPipeEvent *EventPipeEventContentionStart_V2 = nullptr; +EventPipeEvent *EventPipeEventContentionStop_V1 = nullptr; +EventPipeEvent *EventPipeEventContentionLockCreated = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStart = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadStop = nullptr; EventPipeEvent *EventPipeEventThreadPoolWorkerThreadWait = nullptr; @@ -1995,6 +1998,136 @@ ULONG EventPipeWriteEventGCFinalizersEnd_V1( return ERROR_SUCCESS; } +BOOL EventPipeEventEnabledContentionStart_V2(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventContentionStart_V2); +} + +ULONG EventPipeWriteEventContentionStart_V2( + const unsigned char ContentionFlags, + const unsigned short ClrInstanceID, + const void* LockID, + const void* AssociatedObjectID, + const unsigned __int64 LockOwnerThreadID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledContentionStart_V2()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ContentionFlags, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(LockID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(AssociatedObjectID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(LockOwnerThreadID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventContentionStart_V2, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledContentionStop_V1(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventContentionStop_V1); +} + +ULONG EventPipeWriteEventContentionStop_V1( + const unsigned char ContentionFlags, + const unsigned short ClrInstanceID, + const double DurationNs, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledContentionStop_V1()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(ContentionFlags, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(DurationNs, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventContentionStop_V1, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + +BOOL EventPipeEventEnabledContentionLockCreated(void) +{ + return EventPipeAdapter::EventIsEnabled(EventPipeEventContentionLockCreated); +} + +ULONG EventPipeWriteEventContentionLockCreated( + const void* LockID, + const void* AssociatedObjectID, + const unsigned short ClrInstanceID, + const GUID * ActivityId, + const GUID * RelatedActivityId) +{ + if (!EventPipeEventEnabledContentionLockCreated()) + return ERROR_SUCCESS; + + size_t size = 32; + BYTE stackBuffer[32]; + BYTE *buffer = stackBuffer; + size_t offset = 0; + bool fixedBuffer = true; + bool success = true; + + success &= WriteToBuffer(LockID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(AssociatedObjectID, buffer, offset, size, fixedBuffer); + success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); + + if (!success) + { + if (!fixedBuffer) + delete[] buffer; + return ERROR_WRITE_FAULT; + } + + EventPipeAdapter::WriteEvent(EventPipeEventContentionLockCreated, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); + + if (!fixedBuffer) + delete[] buffer; + + + return ERROR_SUCCESS; +} + BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void) { return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStart); @@ -3228,6 +3361,9 @@ void InitDotNETRuntime(void) EventPipeEventFinalizeObject = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,29,1,0,EP_EVENT_LEVEL_VERBOSE,false); EventPipeEventGCFinalizersBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,14,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCFinalizersEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,13,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventContentionStart_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,81,16384,2,EP_EVENT_LEVEL_INFORMATIONAL,true); + EventPipeEventContentionStop_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,91,16384,1,EP_EVENT_LEVEL_INFORMATIONAL,false); + EventPipeEventContentionLockCreated = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,90,16384,0,EP_EVENT_LEVEL_INFORMATIONAL,true); EventPipeEventThreadPoolWorkerThreadStart = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,50,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventThreadPoolWorkerThreadStop = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,51,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventThreadPoolWorkerThreadWait = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,57,65536,0,EP_EVENT_LEVEL_INFORMATIONAL,false); diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 805aa1db1c552..b67eea23a62e3 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -180,6 +180,21 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return EventPipeAdapter::WaitForSessionSignal(sessionID, timeoutMs); } +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) +{ + FireEtwContentionLockCreated(reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) +{ + FireEtwContentionStart_V2((const unsigned char)(ContentionFlags), ClrInstanceID, reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), LockOwnerThreadID); +} + +EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) +{ + FireEtwContentionStop_V1((const unsigned char)(ContentionFlags), ClrInstanceID, DurationNs); +} + EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) { FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 5c737312a12c4..33a80c09c09b4 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -174,7 +174,7 @@ - + diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs similarity index 78% rename from src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs rename to src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs index e37f6cfa9ad74..c3459c0f0e5e7 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.PortableThreadPool.NativeSinks.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs @@ -16,6 +16,32 @@ namespace System.Diagnostics.Tracing // It contains the runtime specific interop to native event sinks. internal sealed partial class NativeRuntimeEventSource : EventSource { + // We don't have these keywords defined from the genRuntimeEventSources.py, so we need to manually define them here. + public static partial class Keywords + { + public const EventKeywords ContentionKeyword = (EventKeywords)0x4000; + public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000; + public const EventKeywords ThreadTransferKeyword = (EventKeywords)0x80000000; + } + + [NonEvent] + internal static void LogContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID) + { + RuntimeImports.RhEventPipeInternal_LogContentionLockCreated(LockID, AssociatedObjectID, ClrInstanceID); + } + + [NonEvent] + internal static void LogContentionStart(ContentionFlagsMap ContentionFlags, ushort ClrInstanceID, nint LockID, nint AssociatedObjectID, ulong LockOwnerThreadID) + { + RuntimeImports.RhEventPipeInternal_LogContentionStart((byte)ContentionFlags, ClrInstanceID, LockID, AssociatedObjectID, LockOwnerThreadID); + } + + [NonEvent] + internal static void LogContentionStop(ContentionFlagsMap ContentionFlags, ushort ClrInstanceID, double DurationNs) + { + RuntimeImports.RhEventPipeInternal_LogContentionStop((byte)ContentionFlags, ClrInstanceID, DurationNs); + } + [NonEvent] internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { @@ -46,15 +72,11 @@ internal static void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); } -#if TARGET_UNIX - // Reason parameter is an enum in NativeRuntimeEventSource but passed here as the underlying type - // In Windows, this event is not fired in managed code [NonEvent] internal static void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID) { RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, (uint)Reason, ClrInstanceID); } -#endif [NonEvent] internal static void LogThreadPoolWorkerThreadAdjustmentStats( diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index cbdcee2636ea3..885d36924b08a 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -742,6 +742,18 @@ internal static unsafe partial void RhEventPipeInternal_WriteEventData( [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] internal static partial uint RhEventPipeInternal_WaitForSessionSignal(ulong sessionID, int timeoutMs); + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogContentionStart(byte ContentionFlags, ushort ClrInstanceID, nint LockID, nint AssociatedObjectID, ulong LockOwnerThreadID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static partial void RhEventPipeInternal_LogContentionStop(byte ContentionFlags, ushort ClrInstanceID, double DurationNs); + [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); 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 0912d9b45989e..e9b13bc24a247 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 @@ -1445,8 +1445,8 @@ - - + + diff --git a/src/tests/tracing/Directory.Build.props b/src/tests/tracing/Directory.Build.props new file mode 100644 index 0000000000000..4d3d8c7ee19c2 --- /dev/null +++ b/src/tests/tracing/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + + true + + \ No newline at end of file diff --git a/src/tests/tracing/eventcounter/runtimecounters.csproj b/src/tests/tracing/eventcounter/runtimecounters.csproj index 5c364fac879ea..34660af281c07 100644 --- a/src/tests/tracing/eventcounter/runtimecounters.csproj +++ b/src/tests/tracing/eventcounter/runtimecounters.csproj @@ -7,7 +7,6 @@ true true - true diff --git a/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj b/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj index dc56ff89f8835..203b64d1a3101 100644 --- a/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj +++ b/src/tests/tracing/eventlistener/EventListenerThreadPool.csproj @@ -6,7 +6,6 @@ true true - true diff --git a/src/tests/tracing/eventpipe/config/name_config_with_pid.csproj b/src/tests/tracing/eventpipe/config/name_config_with_pid.csproj index 187b43060edfb..c090cb1e64fbf 100644 --- a/src/tests/tracing/eventpipe/config/name_config_with_pid.csproj +++ b/src/tests/tracing/eventpipe/config/name_config_with_pid.csproj @@ -5,7 +5,6 @@ true true - true diff --git a/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.csproj b/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.csproj index 2dd6c137f3385..e266e498b4219 100644 --- a/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.csproj +++ b/src/tests/tracing/eventpipe/diagnosticport/diagnosticport.csproj @@ -7,7 +7,6 @@ true true - true diff --git a/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.cs b/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.cs index 54b99d1f553dc..47512faeb1292 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.cs +++ b/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.cs @@ -20,16 +20,22 @@ public static int Main() new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Warning, 0b1000_0000_0000_0000) }; - return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024); + bool enableRundown = TestLibrary.Utilities.IsNativeAot? false: true; + Dictionary _expectedEventCounts = TestLibrary.Utilities.IsNativeAot? _expectedEventCountsNativeAOT: _expectedEventCountsCoreCLR; + + return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, enableRundownProvider:enableRundown); } - private static Dictionary _expectedEventCounts = new Dictionary() + private static Dictionary _expectedEventCountsCoreCLR = new Dictionary() { { "Microsoft-Windows-DotNETRuntime", new ExpectedEventCount(1000, 0.2f) }, { "Microsoft-Windows-DotNETRuntimeRundown", -1 }, { "Microsoft-DotNETCore-SampleProfiler", -1 } }; - + private static Dictionary _expectedEventCountsNativeAOT = new Dictionary() + { + { "Microsoft-Windows-DotNETRuntime", new ExpectedEventCount(1000, 0.2f) } + }; private static Action _eventGeneratingAction = () => { for (int i = 0; i < 1000; i++) diff --git a/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.csproj b/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.csproj index 722bf260cd64b..9454202eb4523 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.csproj +++ b/src/tests/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.csproj @@ -13,5 +13,6 @@ + diff --git a/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj b/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj index a818d9955ee34..ef843105ee839 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj +++ b/src/tests/tracing/eventpipe/eventsvalidation/GCEvents.csproj @@ -8,7 +8,6 @@ true true - true diff --git a/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.cs b/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.cs index 0401c1466272f..a89b9f240c417 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.cs +++ b/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.cs @@ -21,16 +21,24 @@ public static int Main() new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1) }; - return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents); + bool enableRundown = TestLibrary.Utilities.IsNativeAot? false: true; + Dictionary _expectedEventCounts = TestLibrary.Utilities.IsNativeAot? _expectedEventCountsNativeAOT: _expectedEventCountsCoreCLR; + + return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents, enableRundownProvider:enableRundown); } - private static Dictionary _expectedEventCounts = new Dictionary() + private static Dictionary _expectedEventCountsCoreCLR = new Dictionary() { { "Microsoft-Windows-DotNETRuntime", -1 }, { "Microsoft-Windows-DotNETRuntimeRundown", -1 }, { "Microsoft-DotNETCore-SampleProfiler", -1 } }; + private static Dictionary _expectedEventCountsNativeAOT = new Dictionary() + { + { "Microsoft-Windows-DotNETRuntime", -1 } + }; + private static Action _eventGeneratingAction = () => { for (int i = 0; i < 50; i++) diff --git a/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj b/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj index bd45959f8c021..7d5b89cdd57a3 100644 --- a/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj +++ b/src/tests/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj @@ -8,11 +8,11 @@ true true - true + diff --git a/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj b/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj index 916d67f99dbe0..683e3dda99097 100644 --- a/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj +++ b/src/tests/tracing/eventpipe/providervalidation/providervalidation.csproj @@ -7,7 +7,6 @@ true true - true diff --git a/src/tests/tracing/eventpipe/reverse/reverse.csproj b/src/tests/tracing/eventpipe/reverse/reverse.csproj index 4b4bae03bc0b5..a2fca0e2c1cca 100644 --- a/src/tests/tracing/eventpipe/reverse/reverse.csproj +++ b/src/tests/tracing/eventpipe/reverse/reverse.csproj @@ -8,7 +8,6 @@ true true - true diff --git a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.csproj b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.csproj index b9330517e010f..18068018243a0 100644 --- a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.csproj +++ b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.csproj @@ -7,7 +7,6 @@ true true - true From 8168918c546b16c99ab76c26a11e74fcd08e9f8e Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 23 Jun 2023 14:12:31 -0700 Subject: [PATCH 12/22] Enable managed exceptions via eventpipe --- .../nativeaot/Runtime/gctoclreventsink.cpp | 11 +++- .../nativeaot/Runtime/rheventtrace.cpp | 7 +-- .../src/System/Exception.NativeAot.cs | 3 +- .../src/System/Runtime/RuntimeImports.cs | 11 ++-- .../simpleprovidervalidation.cs | 53 ++++++++++++++----- 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp index 2e4b57d1ec7d2..4e2d45dd5162f 100644 --- a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp +++ b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp @@ -192,8 +192,15 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, void GCToCLREventSink::FirePinObjectAtGCTime(void* object, uint8_t** ppObject) { - UNREFERENCED_PARAMETER(object); - UNREFERENCED_PARAMETER(ppObject); + LIMITED_METHOD_CONTRACT; + + Object* obj = (Object*)object; + + FireEtwPinObjectAtGCTime(ppObject, + object, + obj->GetSize(), + NULL, + GetClrInstanceId()); } void GCToCLREventSink::FireGCLOHCompact(uint16_t count, uint32_t valuesLen, void* values) diff --git a/src/coreclr/nativeaot/Runtime/rheventtrace.cpp b/src/coreclr/nativeaot/Runtime/rheventtrace.cpp index c9ab168ccc8a8..fc7073e123325 100644 --- a/src/coreclr/nativeaot/Runtime/rheventtrace.cpp +++ b/src/coreclr/nativeaot/Runtime/rheventtrace.cpp @@ -356,15 +356,12 @@ void ETW::TypeSystemLog::LogTypeAndParametersIfNecessary(BulkTypeEventLogger * p #endif // defined(FEATURE_EVENT_TRACE) } -COOP_PINVOKE_HELPER(void, RhpEtwExceptionThrown, (LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult)) +EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) { - FireEtXplatExceptionThrown_V1(exceptionTypeName, + FireEtwExceptionThrown_V1(exceptionTypeName, exceptionMessage, faultingIP, hresult, 0, GetClrInstanceId()); } - - - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs index bbe9a1b9b2f4b..acf1f1959bd3e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs @@ -135,8 +135,7 @@ private static void AppendExceptionStackFrame(object exceptionObj, IntPtr IP, in if (!fatalOutOfMemory) ex.AppendStackIP(IP, isFirstRethrowFrame); - // UNIX-TODO: RhpEtwExceptionThrown -#if TARGET_WINDOWS + #if FEATURE_PERFTRACING if (isFirstFrame) { string typeName = !fatalOutOfMemory ? ex.GetType().ToString() : "System.OutOfMemoryException"; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 885d36924b08a..5e33a43874361 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -665,14 +665,15 @@ public GCFrameRegistration(void* allocation, uint elemCount, bool areByRefs = tr [RuntimeImport(RuntimeLibrary, "RhUnregisterForGCReporting")] internal static extern unsafe void RhUnregisterForGCReporting(GCFrameRegistration* pRegistration); + +#if FEATURE_PERFTRACING + // // ETW helpers. // - [MethodImplAttribute(MethodImplOptions.InternalCall)] - [RuntimeImport(RuntimeLibrary, "RhpEtwExceptionThrown")] - internal static extern unsafe void RhpEtwExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); - -#if FEATURE_PERFTRACING + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static unsafe partial void RhpEtwExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); // // EventPipeInternal helpers. diff --git a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs index a5e8031953bb6..141b22d967d1c 100644 --- a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs +++ b/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs @@ -22,31 +22,38 @@ public static int Main() // Its currently not enabled in NativeAOT runs and the below issue tracks the work // https://github.com/dotnet/runtime/issues/84701 - var providers = new List() - { - new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Verbose), + var ret = IpcTraceTest.RunAndValidateEventCounts( + // Validation is done with _DoesTraceContainEvents + new Dictionary(){{ "Microsoft-Windows-DotNETRuntime", -1 }}, + _eventGeneratingActionForGC, //GCKeyword (0x1): 0b1 - new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1) - }; - - var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents, enableRundownProvider:false); + new List(){new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1)}, + 1024, _DoesTraceContainEvents, enableRundownProvider:false); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); + // Run the 2nd test scenario only if the first one passes + if(ret== 100) + { + ret = IpcTraceTest.RunAndValidateEventCounts( + // Validate the exception type and message after the below issue is fixed. For now, check that the event is fired + // https://github.com/dotnet/runtime/issues/87978 + new Dictionary(){{ "Microsoft-Windows-DotNETRuntime", 1000 }}, + _eventGeneratingActionForExceptions, + //ExceptionKeyword (0x8000): 0b1000_0000_0000_0000 + new List(){new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Warning, 0b1000_0000_0000_0000)}, + 1024, enableRundownProvider:false); + } + if (ret < 0) return ret; else return 100; } - private static Dictionary _expectedEventCounts = new Dictionary() - { - { "Microsoft-Windows-DotNETRuntime", -1 } - }; - - private static Action _eventGeneratingAction = () => + private static Action _eventGeneratingActionForGC = () => { for (int i = 0; i < 50; i++) { @@ -58,6 +65,24 @@ public static int Main() } }; + private static Action _eventGeneratingActionForExceptions = () => + { + for (int i = 0; i < 1000; i++) + { + if (i % 100 == 0) + Logger.logger.Log($"Thrown an exception {i} times..."); + try + { + throw new ArgumentNullException("Throw ArgumentNullException"); + } + catch (Exception e) + { + //Do nothing + } + } + }; + + private static Func> _DoesTraceContainEvents = (source) => { int GCStartEvents = 0; @@ -68,7 +93,7 @@ public static int Main() int GCRestartEEStartEvents = 0; int GCRestartEEStopEvents = 0; source.Clr.GCRestartEEStart += (eventData) => GCRestartEEStartEvents += 1; - source.Clr.GCRestartEEStop += (eventData) => GCRestartEEStopEvents += 1; + source.Clr.GCRestartEEStop += (eventData) => GCRestartEEStopEvents += 1; int GCSuspendEEEvents = 0; int GCSuspendEEEndEvents = 0; From 99c62bd01d40ff1977f68ad3f3fee7b5557a3ced Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 26 Jun 2023 08:50:37 -0700 Subject: [PATCH 13/22] Move Exception event to EventPipe --- src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp | 10 ++++++++++ src/coreclr/nativeaot/Runtime/rheventtrace.cpp | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index b67eea23a62e3..dd78816d988f5 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -265,4 +265,14 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint FireEtwThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); } +EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) +{ + FireEtwExceptionThrown_V1(exceptionTypeName, + exceptionMessage, + faultingIP, + hresult, + 0, + GetClrInstanceId()); +} + #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/rheventtrace.cpp b/src/coreclr/nativeaot/Runtime/rheventtrace.cpp index fc7073e123325..32c01f26cae26 100644 --- a/src/coreclr/nativeaot/Runtime/rheventtrace.cpp +++ b/src/coreclr/nativeaot/Runtime/rheventtrace.cpp @@ -355,13 +355,3 @@ void ETW::TypeSystemLog::LogTypeAndParametersIfNecessary(BulkTypeEventLogger * p #endif // defined(FEATURE_EVENT_TRACE) } - -EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) -{ - FireEtwExceptionThrown_V1(exceptionTypeName, - exceptionMessage, - faultingIP, - hresult, - 0, - GetClrInstanceId()); -} From 4e13d995d15a1f674d692eca7c294b3e31182d8f Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 26 Jun 2023 10:33:34 -0700 Subject: [PATCH 14/22] Add an empty exception event to disabled EventPipe --- src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp index 584d50b334c14..2c7613e75a22d 100644 --- a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp @@ -186,4 +186,9 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint PalDebugBreak(); } +EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) +{ + PalDebugBreak(); +} + #endif // FEATURE_PERFTRACING From c2f65c1f059bff944eca9d1de7cc9354aa471f93 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 26 Jun 2023 15:43:59 -0700 Subject: [PATCH 15/22] make events do no-op in disabled eventpipe --- .../Runtime/disabledeventpipeinternal.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp index 2c7613e75a22d..6c06c7ef70895 100644 --- a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp @@ -101,49 +101,42 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return FALSE; } +// We will do a no-op for events in the disabled EventPipe This is similar to the way eventpipe checks if the provider and an event is enabled before firting the event, and no-op otherwise. + EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( @@ -159,7 +152,6 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThrea uint16_t NewThreadWaveMagnitude, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOEnqueue( @@ -168,27 +160,22 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOEnqueue( bool MultiDequeues, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) { - PalDebugBreak(); } #endif // FEATURE_PERFTRACING From d13003b829dca1fee54128ad0b378254e219b95d Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 30 Jun 2023 04:29:55 -0700 Subject: [PATCH 16/22] Update src/coreclr/nativeaot/Runtime/clretwallmain.h Co-authored-by: Elinor Fung --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index 9217753e0431e..f5157c4d9c6f8 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -4,8 +4,8 @@ // Work In Progress to add native events to EventPipe // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase // @TODO: Audit native events in NativeAOT Runtime -#ifndef __CLR_ETW_ALL_MAIN_H__ -#define __CLR_ETW_ALL_MAIN_H__ +#ifndef CLR_ETW_ALL_MAIN_H +#define CLR_ETW_ALL_MAIN_H #include "clreventpipewriteevents.h" #include "EtwEvents.h" From df3a3d56770bf56239eea568658bcbf1ea3abdeb Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 30 Jun 2023 08:34:01 -0700 Subject: [PATCH 17/22] FB first stage --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 102 ------- .../Runtime/clreventpipewriteevents.h | 57 ---- .../Runtime/disabledeventpipeinternal.cpp | 85 ------ .../Runtime/disabledruntimeeventinternal.cpp | 85 ++++++ .../Runtime/eventpipe/CMakeLists.txt | 2 + .../eventpipe/disableddotnetruntime.cpp | 73 ----- .../Runtime/eventpipe/dotnetruntime.cpp | 257 ------------------ .../nativeaot/Runtime/eventpipeinternal.cpp | 110 +------- .../nativeaot/Runtime/gctoclreventsink.cpp | 19 +- .../Runtime/runtimeeventinternal.cpp | 103 +++++++ ...tSource.Threading.NativeSinks.NativeAot.cs | 28 +- .../src/System/Exception.NativeAot.cs | 2 +- .../src/System/Runtime/RuntimeImports.cs | 30 +- 13 files changed, 230 insertions(+), 723 deletions(-) create mode 100644 src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp create mode 100644 src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index f5157c4d9c6f8..979804600fb54 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -46,66 +46,6 @@ inline ULONG FireEtwExceptionThrown_V1( return status; } -inline BOOL EventEnabledGCAllocationTick_V1(void) {return EventPipeEventEnabledGCAllocationTick_V1();} - -inline ULONG FireEtwGCAllocationTick_V1( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -) -{ - ULONG status = EventPipeWriteEventGCAllocationTick_V1(AllocationAmount,AllocationKind,ClrInstanceID,ActivityId,RelatedActivityId); -#ifndef TARGET_UNIX - status &= FireEtXplatGCAllocationTick_V1(AllocationAmount,AllocationKind,ClrInstanceID); -#endif - return status; -} - -inline BOOL EventEnabledGCAllocationTick_V2(void) {return EventPipeEventEnabledGCAllocationTick_V2();} - -inline ULONG FireEtwGCAllocationTick_V2( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -) -{ - ULONG status = EventPipeWriteEventGCAllocationTick_V2(AllocationAmount,AllocationKind,ClrInstanceID,AllocationAmount64,TypeID,TypeName,HeapIndex,ActivityId,RelatedActivityId); -#ifndef TARGET_UNIX - status &= FireEtXplatGCAllocationTick_V2(AllocationAmount,AllocationKind,ClrInstanceID,AllocationAmount64,TypeID,TypeName,HeapIndex); -#endif - return status; -} - -inline BOOL EventEnabledGCAllocationTick_V3(void) {return EventPipeEventEnabledGCAllocationTick_V3();} - -inline ULONG FireEtwGCAllocationTick_V3( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - void* Address, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -) -{ - ULONG status = EventPipeWriteEventGCAllocationTick_V3(AllocationAmount,AllocationKind,ClrInstanceID,AllocationAmount64,TypeID,TypeName,HeapIndex,Address,ActivityId,RelatedActivityId); -#ifndef TARGET_UNIX - status &= FireEtXplatGCAllocationTick_V3(AllocationAmount,AllocationKind,ClrInstanceID,AllocationAmount64,TypeID,TypeName,HeapIndex,Address); -#endif - return status; -} - inline BOOL EventEnabledGCBulkEdge(void) {return EventPipeEventEnabledGCBulkEdge();} inline ULONG FireEtwGCBulkEdge( @@ -341,29 +281,6 @@ inline ULONG FireEtwGCGenerationRange( return status; } -inline BOOL EventEnabledGCGlobalHeapHistory_V2(void) {return EventPipeEventEnabledGCGlobalHeapHistory_V2();} - -inline ULONG FireEtwGCGlobalHeapHistory_V2( - const unsigned __int64 FinalYoungestDesired, - const signed int NumHeaps, - const unsigned int CondemnedGeneration, - const unsigned int Gen0ReductionCount, - const unsigned int Reason, - const unsigned int GlobalMechanisms, - const unsigned short ClrInstanceID, - const unsigned int PauseMode, - const unsigned int MemoryPressure, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -) -{ - ULONG status = EventPipeWriteEventGCGlobalHeapHistory_V2(FinalYoungestDesired,NumHeaps,CondemnedGeneration,Gen0ReductionCount,Reason,GlobalMechanisms,ClrInstanceID,PauseMode,MemoryPressure,ActivityId,RelatedActivityId); -#ifndef TARGET_UNIX - status &= FireEtXplatGCGlobalHeapHistory_V2(FinalYoungestDesired,NumHeaps,CondemnedGeneration,Gen0ReductionCount,Reason,GlobalMechanisms,ClrInstanceID,PauseMode,MemoryPressure); -#endif - return status; -} - inline BOOL EventEnabledGCHeapStats_V1(void) {return EventPipeEventEnabledGCHeapStats_V1();} inline ULONG FireEtwGCHeapStats_V1( @@ -602,25 +519,6 @@ inline ULONG FireEtwSetGCHandle( return status; } -inline BOOL EventEnabledGCStart_V1(void) {return EventPipeEventEnabledGCStart_V1();} - -inline ULONG FireEtwGCStart_V1( - const unsigned int Count, - const unsigned int Depth, - const unsigned int Reason, - const unsigned int Type, - const unsigned short ClrInstanceID, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -) -{ - ULONG status = EventPipeWriteEventGCStart_V1(Count,Depth,Reason,Type,ClrInstanceID,ActivityId,RelatedActivityId); -#ifndef TARGET_UNIX - status &= FireEtXplatGCStart_V1(Count,Depth,Reason,Type,ClrInstanceID); -#endif - return status; -} - inline BOOL EventEnabledGCStart_V2(void) {return EventPipeEventEnabledGCStart_V2();} inline ULONG FireEtwGCStart_V2( diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index 2642664a6d422..211b0ae2fbeca 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -24,39 +24,6 @@ ULONG EventPipeWriteEventExceptionThrown_V1( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); -BOOL EventPipeEventEnabledGCAllocationTick_V1(void); -ULONG EventPipeWriteEventGCAllocationTick_V1( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -); -BOOL EventPipeEventEnabledGCAllocationTick_V2(void); -ULONG EventPipeWriteEventGCAllocationTick_V2( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - const void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -); -BOOL EventPipeEventEnabledGCAllocationTick_V3(void); -ULONG EventPipeWriteEventGCAllocationTick_V3( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - const void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const void* Address, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -); BOOL EventPipeEventEnabledGCBulkEdge(void); ULONG EventPipeWriteEventGCBulkEdge( const unsigned int Index, @@ -175,20 +142,6 @@ ULONG EventPipeWriteEventGCGenerationRange( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); -BOOL EventPipeEventEnabledGCGlobalHeapHistory_V2(void); -ULONG EventPipeWriteEventGCGlobalHeapHistory_V2( - const unsigned __int64 FinalYoungestDesired, - const signed int NumHeaps, - const unsigned int CondemnedGeneration, - const unsigned int Gen0ReductionCount, - const unsigned int Reason, - const unsigned int GlobalMechanisms, - const unsigned short ClrInstanceID, - const unsigned int PauseMode, - const unsigned int MemoryPressure, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -); BOOL EventPipeEventEnabledGCHeapStats_V1(void); ULONG EventPipeWriteEventGCHeapStats_V1( const unsigned __int64 GenerationSize0, @@ -319,16 +272,6 @@ ULONG EventPipeWriteEventSetGCHandle( const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr ); -BOOL EventPipeEventEnabledGCStart_V1(void); -ULONG EventPipeWriteEventGCStart_V1( - const unsigned int Count, - const unsigned int Depth, - const unsigned int Reason, - const unsigned int Type, - const unsigned short ClrInstanceID, - const GUID * ActivityId = nullptr, - const GUID * RelatedActivityId = nullptr -); BOOL EventPipeEventEnabledGCStart_V2(void); ULONG EventPipeWriteEventGCStart_V2( const unsigned int Count, diff --git a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp index 6c06c7ef70895..f2de93efbf035 100644 --- a/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp @@ -23,13 +23,11 @@ EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( /* COR_PRF_EVENTPIPE_PROVIDER_CONFIG */ const void * pProviders, uint32_t numProviders) { - PalDebugBreak(); return 0; } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_Disable(uint64_t sessionID) { - PalDebugBreak(); } EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_CreateProvider( @@ -54,7 +52,6 @@ EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_DefineEvent( EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_GetProvider(LPCWSTR providerName) { - PalDebugBreak(); return 0; } @@ -64,7 +61,6 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_DeleteProvider(intptr_t EXTERN_C NATIVEAOT_API int __cdecl RhEventPipeInternal_EventActivityIdControl(uint32_t controlCode, GUID *pActivityId) { - PalDebugBreak(); return 0; } @@ -79,103 +75,22 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_WriteEventData( EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetSessionInfo(uint64_t sessionID, EventPipeSessionInfo *pSessionInfo) { - PalDebugBreak(); return FALSE; } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetNextEvent(uint64_t sessionID, EventPipeEventInstanceData *pInstance) { - PalDebugBreak(); return FALSE; } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_SignalSession(uint64_t sessionID) { - PalDebugBreak(); return FALSE; } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSignal(uint64_t sessionID, int32_t timeoutMs) { - PalDebugBreak(); return FALSE; } -// We will do a no-op for events in the disabled EventPipe This is similar to the way eventpipe checks if the provider and an event is enabled before firting the event, and no-op otherwise. - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( - double Duration, - double Throughput, - double ThreadPoolWorkerThreadWait, - double ThroughputWave, - double ThroughputErrorEstimate, - double AverageThroughputErrorEstimate, - double ThroughputRatio, - double Confidence, - double NewControlSetting, - uint16_t NewThreadWaveMagnitude, - uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOEnqueue( - uint32_t * NativeOverlapped, - uint32_t * Overlapped, - bool MultiDequeues, - uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) -{ -} - -EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) -{ -} - #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp new file mode 100644 index 0000000000000..86a76cc938152 --- /dev/null +++ b/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "eventpipeadapter.h" + +#ifdef FEATURE_PERFTRACING + +// We will do a no-op for events in the disabled EventPipe This is similar to the way eventpipe checks if the provider and an event is enabled before firting the event, and no-op otherwise. + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentStats( + double Duration, + double Throughput, + double ThreadPoolWorkerThreadWait, + double ThroughputWave, + double ThroughputErrorEstimate, + double AverageThroughputErrorEstimate, + double ThroughputRatio, + double Confidence, + double NewControlSetting, + uint16_t NewThreadWaveMagnitude, + uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOEnqueue( + uint32_t * NativeOverlapped, + uint32_t * Overlapped, + bool MultiDequeues, + uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) +{ +} + +#endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt index d0b918e3aabc3..b8a8808f9b0f1 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt @@ -95,6 +95,7 @@ list(APPEND AOT_EVENTPIPE_MANAGED_TO_NATIVE_SOURCES ${RUNTIME_DIR}/eventpipeadapter.h ${RUNTIME_DIR}/diagnosticserveradapter.h ${RUNTIME_DIR}/EnabledEventPipeInterface.cpp + ${RUNTIME_DIR}/runtimeeventinternal.cpp ) list(APPEND EVENTPIPE_SOURCES @@ -110,6 +111,7 @@ list(APPEND EVENTPIPE_SOURCES list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES ${RUNTIME_DIR}/DisabledEventPipeInterface.cpp ${RUNTIME_DIR}/disabledeventpipeinternal.cpp + ${RUNTIME_DIR}/disabledruntimeeventinternal.cpp ${AOT_EVENTPIPE_SHIM_DIR}/disableddotnetruntime.cpp ) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp index 535663ec57050..137ba48870043 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp @@ -39,49 +39,6 @@ ULONG EventPipeWriteEventExceptionThrown_V1( return 0; } -ULONG EventPipeWriteEventGCAllocationTick_V1( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const GUID * ActivityId, - const GUID * RelatedActivityId -) -{ - return 0; -} - - -ULONG EventPipeWriteEventGCAllocationTick_V2( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - const void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const GUID * ActivityId, - const GUID * RelatedActivityId -) -{ - return 0; -} - -ULONG EventPipeWriteEventGCAllocationTick_V3( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - const void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const void* Address, - const GUID * ActivityId, - const GUID * RelatedActivityId -) -{ - return 0; -} - ULONG EventPipeWriteEventGCBulkEdge( const unsigned int Index, const unsigned int Count, @@ -239,23 +196,6 @@ ULONG EventPipeWriteEventGCGenerationRange( return 0; } -ULONG EventPipeWriteEventGCGlobalHeapHistory_V2( - const unsigned __int64 FinalYoungestDesired, - const signed int NumHeaps, - const unsigned int CondemnedGeneration, - const unsigned int Gen0ReductionCount, - const unsigned int Reason, - const unsigned int GlobalMechanisms, - const unsigned short ClrInstanceID, - const unsigned int PauseMode, - const unsigned int MemoryPressure, - const GUID * ActivityId, - const GUID * RelatedActivityId -) -{ - return 0; -} - ULONG EventPipeWriteEventGCHeapStats_V1( const unsigned __int64 GenerationSize0, const unsigned __int64 TotalPromotedSize0, @@ -422,19 +362,6 @@ ULONG EventPipeWriteEventSetGCHandle( return 0; } -ULONG EventPipeWriteEventGCStart_V1( - const unsigned int Count, - const unsigned int Depth, - const unsigned int Reason, - const unsigned int Type, - const unsigned short ClrInstanceID, - const GUID * ActivityId, - const GUID * RelatedActivityId -) -{ - return 0; -} - ULONG EventPipeWriteEventGCStart_V2( const unsigned int Count, const unsigned int Depth, diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index a934973031801..1b566604ff4df 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -95,9 +95,6 @@ const WCHAR* DotNETRuntimeName = W("Microsoft-Windows-DotNETRuntime"); EventPipeProvider *EventPipeProviderDotNETRuntime = nullptr; EventPipeEvent *EventPipeEventDestroyGCHandle = nullptr; EventPipeEvent *EventPipeEventExceptionThrown_V1 = nullptr; -EventPipeEvent *EventPipeEventGCAllocationTick_V1 = nullptr; -EventPipeEvent *EventPipeEventGCAllocationTick_V2 = nullptr; -EventPipeEvent *EventPipeEventGCAllocationTick_V3 = nullptr; EventPipeEvent *EventPipeEventGCBulkEdge = nullptr; EventPipeEvent *EventPipeEventGCBulkMovedObjectRanges = nullptr; EventPipeEvent *EventPipeEventGCBulkNode = nullptr; @@ -111,7 +108,6 @@ EventPipeEvent *EventPipeEventGCCreateSegment_V1 = nullptr; EventPipeEvent *EventPipeEventGCEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCFreeSegment_V1 = nullptr; EventPipeEvent *EventPipeEventGCGenerationRange = nullptr; -EventPipeEvent *EventPipeEventGCGlobalHeapHistory_V2 = nullptr; EventPipeEvent *EventPipeEventGCHeapStats_V1 = nullptr; EventPipeEvent *EventPipeEventGCJoin_V2 = nullptr; EventPipeEvent *EventPipeEventGCMarkFinalizeQueueRoots = nullptr; @@ -124,7 +120,6 @@ EventPipeEvent *EventPipeEventGCTerminateConcurrentThread_V1 = nullptr; EventPipeEvent *EventPipeEventGCTriggered = nullptr; EventPipeEvent *EventPipeEventModuleLoad_V2 = nullptr; EventPipeEvent *EventPipeEventSetGCHandle = nullptr; -EventPipeEvent *EventPipeEventGCStart_V1 = nullptr; EventPipeEvent *EventPipeEventGCStart_V2 = nullptr; EventPipeEvent *EventPipeEventGCRestartEEEnd_V1 = nullptr; EventPipeEvent *EventPipeEventGCRestartEEBegin_V1 = nullptr; @@ -251,152 +246,6 @@ ULONG EventPipeWriteEventExceptionThrown_V1( return ERROR_SUCCESS; } -BOOL EventPipeEventEnabledGCAllocationTick_V1(void) -{ - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCAllocationTick_V1); -} - -ULONG EventPipeWriteEventGCAllocationTick_V1( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const GUID * ActivityId, - const GUID * RelatedActivityId) -{ - if (!EventPipeEventEnabledGCAllocationTick_V1()) - return ERROR_SUCCESS; - - size_t size = 32; - BYTE stackBuffer[32]; - BYTE *buffer = stackBuffer; - size_t offset = 0; - bool fixedBuffer = true; - bool success = true; - - success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); - - if (!success) - { - if (!fixedBuffer) - delete[] buffer; - return ERROR_WRITE_FAULT; - } - - EventPipeAdapter::WriteEvent(EventPipeEventGCAllocationTick_V1, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); - - if (!fixedBuffer) - delete[] buffer; - - - return ERROR_SUCCESS; -} - -BOOL EventPipeEventEnabledGCAllocationTick_V2(void) -{ - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCAllocationTick_V2); -} - -ULONG EventPipeWriteEventGCAllocationTick_V2( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - const void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const GUID * ActivityId, - const GUID * RelatedActivityId) -{ - if (!EventPipeEventEnabledGCAllocationTick_V2()) - return ERROR_SUCCESS; - - size_t size = 94; - BYTE stackBuffer[94]; - BYTE *buffer = stackBuffer; - size_t offset = 0; - bool fixedBuffer = true; - bool success = true; - - if (!TypeName) { TypeName = W("NULL"); } - success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(AllocationAmount64, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(TypeID, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(TypeName, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(HeapIndex, buffer, offset, size, fixedBuffer); - - if (!success) - { - if (!fixedBuffer) - delete[] buffer; - return ERROR_WRITE_FAULT; - } - - EventPipeAdapter::WriteEvent(EventPipeEventGCAllocationTick_V2, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); - - if (!fixedBuffer) - delete[] buffer; - - - return ERROR_SUCCESS; -} - -BOOL EventPipeEventEnabledGCAllocationTick_V3(void) -{ - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCAllocationTick_V3); -} - -ULONG EventPipeWriteEventGCAllocationTick_V3( - const unsigned int AllocationAmount, - const unsigned int AllocationKind, - const unsigned short ClrInstanceID, - const unsigned __int64 AllocationAmount64, - const void* TypeID, - const WCHAR* TypeName, - const unsigned int HeapIndex, - const void* Address, - const GUID * ActivityId, - const GUID * RelatedActivityId) -{ - if (!EventPipeEventEnabledGCAllocationTick_V3()) - return ERROR_SUCCESS; - - size_t size = 102; - BYTE stackBuffer[102]; - BYTE *buffer = stackBuffer; - size_t offset = 0; - bool fixedBuffer = true; - bool success = true; - - if (!TypeName) { TypeName = W("NULL"); } - success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(AllocationAmount64, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(TypeID, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(TypeName, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(HeapIndex, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(Address, buffer, offset, size, fixedBuffer); - - if (!success) - { - if (!fixedBuffer) - delete[] buffer; - return ERROR_WRITE_FAULT; - } - - EventPipeAdapter::WriteEvent(EventPipeEventGCAllocationTick_V3, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); - - if (!fixedBuffer) - delete[] buffer; - - - return ERROR_SUCCESS; -} - BOOL EventPipeEventEnabledGCBulkEdge(void) { return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkEdge); @@ -963,60 +812,6 @@ ULONG EventPipeWriteEventGCGenerationRange( return ERROR_SUCCESS; } -BOOL EventPipeEventEnabledGCGlobalHeapHistory_V2(void) -{ - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCGlobalHeapHistory_V2); -} - -ULONG EventPipeWriteEventGCGlobalHeapHistory_V2( - const unsigned __int64 FinalYoungestDesired, - const signed int NumHeaps, - const unsigned int CondemnedGeneration, - const unsigned int Gen0ReductionCount, - const unsigned int Reason, - const unsigned int GlobalMechanisms, - const unsigned short ClrInstanceID, - const unsigned int PauseMode, - const unsigned int MemoryPressure, - const GUID * ActivityId, - const GUID * RelatedActivityId) -{ - if (!EventPipeEventEnabledGCGlobalHeapHistory_V2()) - return ERROR_SUCCESS; - - size_t size = 38; - BYTE stackBuffer[38]; - BYTE *buffer = stackBuffer; - size_t offset = 0; - bool fixedBuffer = true; - bool success = true; - - success &= WriteToBuffer(FinalYoungestDesired, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(NumHeaps, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(CondemnedGeneration, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(Gen0ReductionCount, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(Reason, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(GlobalMechanisms, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(PauseMode, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(MemoryPressure, buffer, offset, size, fixedBuffer); - - if (!success) - { - if (!fixedBuffer) - delete[] buffer; - return ERROR_WRITE_FAULT; - } - - EventPipeAdapter::WriteEvent(EventPipeEventGCGlobalHeapHistory_V2, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); - - if (!fixedBuffer) - delete[] buffer; - - - return ERROR_SUCCESS; -} - BOOL EventPipeEventEnabledGCHeapStats_V1(void) { return EventPipeAdapter::EventIsEnabled(EventPipeEventGCHeapStats_V1); @@ -1592,52 +1387,6 @@ ULONG EventPipeWriteEventSetGCHandle( return ERROR_SUCCESS; } -BOOL EventPipeEventEnabledGCStart_V1(void) -{ - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCStart_V1); -} - -ULONG EventPipeWriteEventGCStart_V1( - const unsigned int Count, - const unsigned int Depth, - const unsigned int Reason, - const unsigned int Type, - const unsigned short ClrInstanceID, - const GUID * ActivityId, - const GUID * RelatedActivityId) -{ - if (!EventPipeEventEnabledGCStart_V1()) - return ERROR_SUCCESS; - - size_t size = 32; - BYTE stackBuffer[32]; - BYTE *buffer = stackBuffer; - size_t offset = 0; - bool fixedBuffer = true; - bool success = true; - - success &= WriteToBuffer(Count, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(Depth, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(Reason, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(Type, buffer, offset, size, fixedBuffer); - success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); - - if (!success) - { - if (!fixedBuffer) - delete[] buffer; - return ERROR_WRITE_FAULT; - } - - EventPipeAdapter::WriteEvent(EventPipeEventGCStart_V1, (BYTE *)buffer, (unsigned int)offset, ActivityId, RelatedActivityId); - - if (!fixedBuffer) - delete[] buffer; - - - return ERROR_SUCCESS; -} - BOOL EventPipeEventEnabledGCStart_V2(void) { return EventPipeAdapter::EventIsEnabled(EventPipeEventGCStart_V2); @@ -3318,13 +3067,9 @@ void InitProvidersAndEvents(void) void InitDotNETRuntime(void) { // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // @TODO - Events need to be audited EventPipeProviderDotNETRuntime = EventPipeAdapter::CreateProvider(DotNETRuntimeName, reinterpret_cast(EventPipeEtwCallbackDotNETRuntime)); EventPipeEventDestroyGCHandle = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,31,2,0,EP_EVENT_LEVEL_INFORMATIONAL,true); EventPipeEventExceptionThrown_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,80,8589967360,1,EP_EVENT_LEVEL_ERROR,true); - EventPipeEventGCAllocationTick_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,10,1,1,EP_EVENT_LEVEL_VERBOSE,true); - EventPipeEventGCAllocationTick_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,10,1,2,EP_EVENT_LEVEL_VERBOSE,true); - EventPipeEventGCAllocationTick_V3 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,10,1,3,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventGCBulkEdge = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,19,1048576,0,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCBulkMovedObjectRanges = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,22,4194304,0,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCBulkNode = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,18,1048576,0,EP_EVENT_LEVEL_INFORMATIONAL,false); @@ -3338,7 +3083,6 @@ void InitDotNETRuntime(void) EventPipeEventGCEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,2,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCFreeSegment_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,6,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCGenerationRange = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,23,4194304,0,EP_EVENT_LEVEL_INFORMATIONAL,false); - EventPipeEventGCGlobalHeapHistory_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,205,1,2,EP_EVENT_LEVEL_INFORMATIONAL,true); EventPipeEventGCHeapStats_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,4,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCJoin_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,203,1,2,EP_EVENT_LEVEL_VERBOSE,true); EventPipeEventGCMarkFinalizeQueueRoots = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,26,1,0,EP_EVENT_LEVEL_INFORMATIONAL,false); @@ -3351,7 +3095,6 @@ void InitDotNETRuntime(void) EventPipeEventGCTriggered = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,35,1,0,EP_EVENT_LEVEL_INFORMATIONAL,true); EventPipeEventModuleLoad_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,152,536870920,2,EP_EVENT_LEVEL_INFORMATIONAL,true); EventPipeEventSetGCHandle = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,30,2,0,EP_EVENT_LEVEL_INFORMATIONAL,true); - EventPipeEventGCStart_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,1,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCStart_V2 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,1,1,2,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCRestartEEEnd_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,3,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); EventPipeEventGCRestartEEBegin_V1 = EventPipeAdapter::AddEvent(EventPipeProviderDotNETRuntime,7,1,1,EP_EVENT_LEVEL_INFORMATIONAL,false); diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index dd78816d988f5..58105ac769ee7 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -26,9 +26,9 @@ struct EventPipeEventInstanceData struct EventPipeSessionInfo { - FILETIME StartTimeAsUTCFileTime; - LARGE_INTEGER StartTimeStamp; - LARGE_INTEGER TimeStampFrequency; + int64_t StartTimeAsUTCFileTime; + int64_t StartTimeStamp; + uint64_t TimeStampFrequency; }; EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( @@ -136,13 +136,12 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetSessionInfo(ui bool retVal = false; if (pSessionInfo != NULL) { - EventPipeSession *pSession = EventPipeAdapter::GetSession(sessionID); + EventPipeSession *pSession = ep_get_session(sessionID); if (pSession != NULL) { - pSessionInfo->StartTimeAsUTCFileTime = EventPipeAdapter::GetSessionStartTime(pSession); - pSessionInfo->StartTimeStamp.QuadPart = EventPipeAdapter::GetSessionStartTimestamp(pSession); - // @TODO - //pSessionInfo->TimeStampFrequency = reinterpret_cast(PalQueryPerformanceFrequency()); + pSessionInfo->StartTimeAsUTCFileTime = ep_session_get_session_start_time (pSession); + pSessionInfo->StartTimeStamp = ep_session_get_session_start_timestamp(pSession); + pSessionInfo->TimeStampFrequency = PalQueryPerformanceFrequency(); retVal = true; } } @@ -180,99 +179,4 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSig return EventPipeAdapter::WaitForSessionSignal(sessionID, timeoutMs); } -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) -{ - FireEtwContentionLockCreated(reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) -{ - FireEtwContentionStart_V2((const unsigned char)(ContentionFlags), ClrInstanceID, reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), LockOwnerThreadID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) -{ - FireEtwContentionStop_V1((const unsigned char)(ContentionFlags), ClrInstanceID, DurationNs); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) -{ - FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, Reason, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( - double Duration, - double Throughput, - double ThreadPoolWorkerThreadWait, - double ThroughputWave, - double ThroughputErrorEstimate, - double AverageThroughputErrorEstimate, - double ThroughputRatio, - double Confidence, - double NewControlSetting, - uint16_t NewThreadWaveMagnitude, - uint16_t ClrInstanceID) -{ - FireEtwThreadPoolWorkerThreadAdjustmentStats(Duration, Throughput, ThreadPoolWorkerThreadWait, ThroughputWave, ThroughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, Confidence, NewControlSetting, NewThreadWaveMagnitude, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOEnqueue( - uint32_t * NativeOverlapped, - uint32_t * Overlapped, - bool MultiDequeues, - uint16_t ClrInstanceID) -{ - FireEtwThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolWorkingThreadCount(Count, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) -{ - FireEtwThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); -} - -EXTERN_C NATIVEAOT_API void __cdecl RhpEtwExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) -{ - FireEtwExceptionThrown_V1(exceptionTypeName, - exceptionMessage, - faultingIP, - hresult, - 0, - GetClrInstanceId()); -} - #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp index 4e2d45dd5162f..095c90a7375a8 100644 --- a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp +++ b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp @@ -147,11 +147,9 @@ void GCToCLREventSink::FireGCGlobalHeapHistory_V4(uint64_t finalYoungestDesired, count, valuesLen, values); } -void GCToCLREventSink::FireGCAllocationTick_V1(uint32_t allocationAmount, uint32_t allocationKind) +void GCToCLREventSink::FireGCAllocationTick_V1(uint32_t allocationAmount, + uint32_t allocationKind) { - LIMITED_METHOD_CONTRACT; - - FireEtwGCAllocationTick_V1(allocationAmount, allocationKind, GetClrInstanceId()); } void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, @@ -163,11 +161,10 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, LIMITED_METHOD_CONTRACT; void * typeId = RedhawkGCInterface::GetLastAllocEEType(); - WCHAR * name = nullptr; + wchar_t * name = nullptr; if (typeId != nullptr) { -#ifdef TARGET_WINDOWS FireEtwGCAllocationTick_V4(static_cast(allocationAmount), allocationKind, GetClrInstanceId(), @@ -177,16 +174,6 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, heapIndex, objectAddress, objectSize); -#else - FireEtwGCAllocationTick_V3(static_cast(allocationAmount), - allocationKind, - GetClrInstanceId(), - allocationAmount, - typeId, - name, - heapIndex, - objectAddress); -#endif } } diff --git a/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp b/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp new file mode 100644 index 0000000000000..469b94282a895 --- /dev/null +++ b/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp @@ -0,0 +1,103 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "eventpipeadapter.h" + +#ifdef FEATURE_PERFTRACING + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionLockCreated(intptr_t LockID, intptr_t AssociatedObjectID, uint16_t ClrInstanceID) +{ + FireEtwContentionLockCreated(reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) +{ + FireEtwContentionStart_V2((const unsigned char)(ContentionFlags), ClrInstanceID, reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), LockOwnerThreadID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) +{ + FireEtwContentionStop_V1((const unsigned char)(ContentionFlags), ClrInstanceID, DurationNs); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint32_t activeWorkerThreadCount, uint32_t retiredWorkerThreadCount, uint16_t clrInstanceID) +{ + FireEtwThreadPoolWorkerThreadStart(activeWorkerThreadCount, retiredWorkerThreadCount, clrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(uint32_t ActiveWorkerThreadCount, uint32_t RetiredWorkerThreadCount, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolMinMaxThreads(uint16_t MinWorkerThreads, uint16_t MaxWorkerThreads, uint16_t MinIOCompletionThreads, uint16_t MaxIOCompletionThreads, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint32_t NewWorkerThreadCount, uint32_t Reason, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, Reason, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentStats( + double Duration, + double Throughput, + double ThreadPoolWorkerThreadWait, + double ThroughputWave, + double ThroughputErrorEstimate, + double AverageThroughputErrorEstimate, + double ThroughputRatio, + double Confidence, + double NewControlSetting, + uint16_t NewThreadWaveMagnitude, + uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkerThreadAdjustmentStats(Duration, Throughput, ThreadPoolWorkerThreadWait, ThroughputWave, ThroughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, Confidence, NewControlSetting, NewThreadWaveMagnitude, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOEnqueue( + uint32_t * NativeOverlapped, + uint32_t * Overlapped, + bool MultiDequeues, + uint16_t ClrInstanceID) +{ + FireEtwThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkingThreadCount(uint32_t Count, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolWorkingThreadCount(Count, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +{ + FireEtwThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); +} + +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult) +{ + FireEtwExceptionThrown_V1(exceptionTypeName, + exceptionMessage, + faultingIP, + hresult, + 0, + GetClrInstanceId()); +} + +#endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs index c3459c0f0e5e7..b7db6c9618df9 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/Eventing/NativeRuntimeEventSource.Threading.NativeSinks.NativeAot.cs @@ -27,55 +27,55 @@ public static partial class Keywords [NonEvent] internal static void LogContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogContentionLockCreated(LockID, AssociatedObjectID, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogContentionLockCreated(LockID, AssociatedObjectID, ClrInstanceID); } [NonEvent] internal static void LogContentionStart(ContentionFlagsMap ContentionFlags, ushort ClrInstanceID, nint LockID, nint AssociatedObjectID, ulong LockOwnerThreadID) { - RuntimeImports.RhEventPipeInternal_LogContentionStart((byte)ContentionFlags, ClrInstanceID, LockID, AssociatedObjectID, LockOwnerThreadID); + RuntimeImports.NativeRuntimeEventSource_LogContentionStart((byte)ContentionFlags, ClrInstanceID, LockID, AssociatedObjectID, LockOwnerThreadID); } [NonEvent] internal static void LogContentionStop(ContentionFlagsMap ContentionFlags, ushort ClrInstanceID, double DurationNs) { - RuntimeImports.RhEventPipeInternal_LogContentionStop((byte)ContentionFlags, ClrInstanceID, DurationNs); + RuntimeImports.NativeRuntimeEventSource_LogContentionStop((byte)ContentionFlags, ClrInstanceID, DurationNs); } [NonEvent] internal static void LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadStart(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(ActiveWorkerThreadCount, RetiredWorkerThreadCount, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentSample(Throughput, ClrInstanceID); } [NonEvent] internal static void LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, ThreadAdjustmentReasonMap Reason, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, (uint)Reason, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentAdjustment(AverageThroughput, NewWorkerThreadCount, (uint)Reason, ClrInstanceID); } [NonEvent] @@ -92,7 +92,7 @@ internal static void LogThreadPoolWorkerThreadAdjustmentStats( ushort NewThreadWaveMagnitude, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats(Duration, Throughput, ThreadPoolWorkerThreadWait, ThroughputWave, + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentStats(Duration, Throughput, ThreadPoolWorkerThreadWait, ThroughputWave, ThroughputErrorEstimate, AverageThroughputErrorEstimate, ThroughputRatio, Confidence, NewControlSetting, NewThreadWaveMagnitude, ClrInstanceID); } @@ -103,7 +103,7 @@ internal static void LogThreadPoolIOEnqueue( [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); } [NonEvent] @@ -112,7 +112,7 @@ internal static void LogThreadPoolIODequeue( IntPtr Overlapped, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); } [NonEvent] @@ -121,7 +121,7 @@ internal static void LogThreadPoolWorkingThreadCount( ushort ClrInstanceID ) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolWorkingThreadCount(Count, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolWorkingThreadCount(Count, ClrInstanceID); } [NonEvent] @@ -130,7 +130,7 @@ internal static void LogThreadPoolIOPack( IntPtr Overlapped, ushort ClrInstanceID) { - RuntimeImports.RhEventPipeInternal_LogThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); + RuntimeImports.NativeRuntimeEventSource_LogThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); } } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs index acf1f1959bd3e..db496ad22e5f3 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs @@ -145,7 +145,7 @@ private static void AppendExceptionStackFrame(object exceptionObj, IntPtr IP, in unsafe { fixed (char* exceptionTypeName = typeName, exceptionMessage = message) - RuntimeImports.RhpEtwExceptionThrown(exceptionTypeName, exceptionMessage, IP, ex.HResult); + RuntimeImports.NativeRuntimeEventSource_LogExceptionThrown(exceptionTypeName, exceptionMessage, IP, ex.HResult); } } #endif diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 5e33a43874361..6d2d4f18563a8 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -673,7 +673,7 @@ public GCFrameRegistration(void* allocation, uint elemCount, bool areByRefs = tr // [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static unsafe partial void RhpEtwExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); + internal static unsafe partial void NativeRuntimeEventSource_LogExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); // // EventPipeInternal helpers. @@ -745,43 +745,43 @@ internal static unsafe partial void RhEventPipeInternal_WriteEventData( [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogContentionStart(byte ContentionFlags, ushort ClrInstanceID, nint LockID, nint AssociatedObjectID, ulong LockOwnerThreadID); + internal static partial void NativeRuntimeEventSource_LogContentionStart(byte ContentionFlags, ushort ClrInstanceID, nint LockID, nint AssociatedObjectID, ulong LockOwnerThreadID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogContentionStop(byte ContentionFlags, ushort ClrInstanceID, double DurationNs); + internal static partial void NativeRuntimeEventSource_LogContentionStop(byte ContentionFlags, ushort ClrInstanceID, double DurationNs); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkerThreadStart(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkerThreadStop(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkerThreadWait(uint ActiveWorkerThreadCount, uint RetiredWorkerThreadCount, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogThreadPoolMinMaxThreads(ushort MinWorkerThreads, ushort MaxWorkerThreads, ushort MinIOCompletionThreads, ushort MaxIOCompletionThreads, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentSample(double Throughput, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, uint Reason, ushort ClrInstanceID); + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentAdjustment(double AverageThroughput, uint NewWorkerThreadCount, uint Reason, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjustmentStats( + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkerThreadAdjustmentStats( double Duration, double Throughput, double ThreadPoolWorkerThreadWait, @@ -796,7 +796,7 @@ internal static partial void RhEventPipeInternal_LogThreadPoolWorkerThreadAdjust [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolIOEnqueue( + internal static partial void NativeRuntimeEventSource_LogThreadPoolIOEnqueue( IntPtr NativeOverlapped, IntPtr Overlapped, [MarshalAs(UnmanagedType.Bool)] bool MultiDequeues, @@ -804,21 +804,21 @@ internal static partial void RhEventPipeInternal_LogThreadPoolIOEnqueue( [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolIODequeue( + internal static partial void NativeRuntimeEventSource_LogThreadPoolIODequeue( IntPtr NativeOverlapped, IntPtr Overlapped, ushort ClrInstanceID); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolWorkingThreadCount( + internal static partial void NativeRuntimeEventSource_LogThreadPoolWorkingThreadCount( uint Count, ushort ClrInstanceID ); [LibraryImport(RuntimeLibrary)] [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static partial void RhEventPipeInternal_LogThreadPoolIOPack( + internal static partial void NativeRuntimeEventSource_LogThreadPoolIOPack( IntPtr NativeOverlapped, IntPtr Overlapped, ushort ClrInstanceID); From 1fb838a967185bd6dd66518f82dc7ec4de3a3f86 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 30 Jun 2023 11:10:28 -0700 Subject: [PATCH 18/22] Test change --- eng/pipelines/runtime.yml | 2 +- .../simpleruntimeeventvalidation.cs} | 13 +++++-------- .../simpleruntimeeventvalidation.csproj} | 0 3 files changed, 6 insertions(+), 9 deletions(-) rename src/tests/tracing/eventpipe/{simpleprovidervalidation/simpleprovidervalidation.cs => simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs} (91%) rename src/tests/tracing/eventpipe/{simpleprovidervalidation/simpleprovidervalidation.csproj => simpleruntimeeventvalidation/simpleruntimeeventvalidation.csproj} (100%) diff --git a/eng/pipelines/runtime.yml b/eng/pipelines/runtime.yml index 24fc41ceef43a..91ead51228b64 100644 --- a/eng/pipelines/runtime.yml +++ b/eng/pipelines/runtime.yml @@ -248,7 +248,7 @@ extends: extraStepsTemplate: /eng/pipelines/coreclr/nativeaot-post-build-steps.yml extraStepsParameters: creator: dotnet-bot - testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;tracing/eventpipe/simpleprovidervalidation;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' + testBuildArgs: 'nativeaot tree ";nativeaot;Loader;Interop;tracing/eventpipe/config;tracing/eventpipe/diagnosticport;tracing/eventpipe/reverse;tracing/eventpipe/simpleruntimeeventvalidation;" test tracing/eventcounter/runtimecounters.csproj /p:BuildNativeAotFrameworkObjects=true' liveLibrariesBuildConfig: Release testRunNamePrefixSuffix: NativeAOT_$(_BuildConfig) extraVariablesTemplates: diff --git a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs similarity index 91% rename from src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs rename to src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs index 141b22d967d1c..4f4a95d5d5f95 100644 --- a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.cs +++ b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs @@ -12,16 +12,13 @@ using Tracing.Tests.Common; using Microsoft.Diagnostics.NETCore.Client; -namespace Tracing.Tests.SimpleProviderValidation +namespace Tracing.Tests.SimpleRuntimeEventValidation { - public class ProviderValidation + public class RuntimeEventValidation { public static int Main() { - // This test is meant to validate NativeAOT EventPipe implementation and is meant to run in regular CI - // Its currently not enabled in NativeAOT runs and the below issue tracks the work - // https://github.com/dotnet/runtime/issues/84701 - + // This test validates GC and Exception events in the runtime var ret = IpcTraceTest.RunAndValidateEventCounts( // Validation is done with _DoesTraceContainEvents new Dictionary(){{ "Microsoft-Windows-DotNETRuntime", -1 }}, @@ -59,8 +56,8 @@ public static int Main() { if (i % 10 == 0) Logger.logger.Log($"Called GC.Collect() {i} times..."); - ProviderValidation providerValidation = new ProviderValidation(); - providerValidation = null; + RuntimeEventValidation eventValidation = new RuntimeEventValidation(); + eventValidation = null; GC.Collect(); } }; diff --git a/src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.csproj b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.csproj similarity index 100% rename from src/tests/tracing/eventpipe/simpleprovidervalidation/simpleprovidervalidation.csproj rename to src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.csproj From 60ebb00c59e4681e052dc50d276bcb8d9d7d65c6 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Mon, 3 Jul 2023 05:54:11 -0700 Subject: [PATCH 19/22] FB --- .../nativeaot/Runtime/EventPipeInterface.h | 6 +- .../Runtime/diagnosticserveradapter.h | 6 +- .../Runtime/eventpipe/dotnetruntime.cpp | 124 +++++----- .../nativeaot/Runtime/eventpipe/ds-rt-aot.h | 6 +- .../Runtime/eventpipe/ds-rt-types-aot.h | 6 +- .../nativeaot/Runtime/eventpipe/ep-rt-aot.h | 6 +- .../Runtime/eventpipe/ep-rt-config-aot.h | 6 +- .../Runtime/eventpipe/ep-rt-types-aot.h | 6 +- .../nativeaot/Runtime/eventpipeadapter.h | 233 +----------------- .../nativeaot/Runtime/eventpipeadaptertypes.h | 6 +- .../nativeaot/Runtime/eventpipeinternal.cpp | 88 +++++-- 11 files changed, 150 insertions(+), 343 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/EventPipeInterface.h b/src/coreclr/nativeaot/Runtime/EventPipeInterface.h index 662259f930270..406b180a23d69 100644 --- a/src/coreclr/nativeaot/Runtime/EventPipeInterface.h +++ b/src/coreclr/nativeaot/Runtime/EventPipeInterface.h @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#ifndef __EVENTPIPE_INTERFACE_H__ -#define __EVENTPIPE_INTERFACE_H__ +#ifndef EVENTPIPE_INTERFACE_H +#define EVENTPIPE_INTERFACE_H // Initialize EventPipe void EventPipeAdapter_Initialize(); @@ -18,4 +18,4 @@ void EventPipeAdapter_FinishInitialize(); void EventPipeAdapter_Shutdown(); bool DiagnosticServerAdapter_Shutdown(); -#endif //__EVENTPIPE_INTERFACE_H__ \ No newline at end of file +#endif //EVENTPIPE_INTERFACE_H \ No newline at end of file diff --git a/src/coreclr/nativeaot/Runtime/diagnosticserveradapter.h b/src/coreclr/nativeaot/Runtime/diagnosticserveradapter.h index 62cd5816d08fd..7a133ce9f9c15 100644 --- a/src/coreclr/nativeaot/Runtime/diagnosticserveradapter.h +++ b/src/coreclr/nativeaot/Runtime/diagnosticserveradapter.h @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#ifndef __DIAGNOSTIC_SERVER_ADAPTER_H__ -#define __DIAGNOSTIC_SERVER_ADAPTER_H__ +#ifndef DIAGNOSTIC_SERVER_ADAPTER_H +#define DIAGNOSTIC_SERVER_ADAPTER_H #if defined(FEATURE_PERFTRACING) @@ -39,4 +39,4 @@ class DiagnosticServerAdapter final #endif // FEATURE_PERFTRACING -#endif // __DIAGNOSTIC_SERVER_ADAPTER_H__ +#endif // DIAGNOSTIC_SERVER_ADAPTER_H diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index 1b566604ff4df..0084b06f1eb28 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -158,7 +158,7 @@ EventPipeEvent *EventPipeEventGCFitBucketInfo = nullptr; BOOL EventPipeEventEnabledDestroyGCHandle(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventDestroyGCHandle); + return ep_event_is_enabled(EventPipeEventDestroyGCHandle); } ULONG EventPipeWriteEventDestroyGCHandle( @@ -198,7 +198,7 @@ ULONG EventPipeWriteEventDestroyGCHandle( BOOL EventPipeEventEnabledExceptionThrown_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventExceptionThrown_V1); + return ep_event_is_enabled(EventPipeEventExceptionThrown_V1); } ULONG EventPipeWriteEventExceptionThrown_V1( @@ -248,7 +248,7 @@ ULONG EventPipeWriteEventExceptionThrown_V1( BOOL EventPipeEventEnabledGCBulkEdge(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkEdge); + return ep_event_is_enabled(EventPipeEventGCBulkEdge); } ULONG EventPipeWriteEventGCBulkEdge( @@ -293,7 +293,7 @@ ULONG EventPipeWriteEventGCBulkEdge( BOOL EventPipeEventEnabledGCBulkMovedObjectRanges(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkMovedObjectRanges); + return ep_event_is_enabled(EventPipeEventGCBulkMovedObjectRanges); } ULONG EventPipeWriteEventGCBulkMovedObjectRanges( @@ -338,7 +338,7 @@ ULONG EventPipeWriteEventGCBulkMovedObjectRanges( BOOL EventPipeEventEnabledGCBulkNode(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkNode); + return ep_event_is_enabled(EventPipeEventGCBulkNode); } ULONG EventPipeWriteEventGCBulkNode( @@ -383,7 +383,7 @@ ULONG EventPipeWriteEventGCBulkNode( BOOL EventPipeEventEnabledGCBulkRCW(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkRCW); + return ep_event_is_enabled(EventPipeEventGCBulkRCW); } ULONG EventPipeWriteEventGCBulkRCW( @@ -426,7 +426,7 @@ ULONG EventPipeWriteEventGCBulkRCW( BOOL EventPipeEventEnabledGCBulkRootCCW(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkRootCCW); + return ep_event_is_enabled(EventPipeEventGCBulkRootCCW); } ULONG EventPipeWriteEventGCBulkRootCCW( @@ -469,7 +469,7 @@ ULONG EventPipeWriteEventGCBulkRootCCW( BOOL EventPipeEventEnabledGCBulkRootConditionalWeakTableElementEdge(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkRootConditionalWeakTableElementEdge); + return ep_event_is_enabled(EventPipeEventGCBulkRootConditionalWeakTableElementEdge); } ULONG EventPipeWriteEventGCBulkRootConditionalWeakTableElementEdge( @@ -514,7 +514,7 @@ ULONG EventPipeWriteEventGCBulkRootConditionalWeakTableElementEdge( BOOL EventPipeEventEnabledGCBulkRootEdge(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkRootEdge); + return ep_event_is_enabled(EventPipeEventGCBulkRootEdge); } ULONG EventPipeWriteEventGCBulkRootEdge( @@ -559,7 +559,7 @@ ULONG EventPipeWriteEventGCBulkRootEdge( BOOL EventPipeEventEnabledGCBulkSurvivingObjectRanges(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkSurvivingObjectRanges); + return ep_event_is_enabled(EventPipeEventGCBulkSurvivingObjectRanges); } ULONG EventPipeWriteEventGCBulkSurvivingObjectRanges( @@ -604,7 +604,7 @@ ULONG EventPipeWriteEventGCBulkSurvivingObjectRanges( BOOL EventPipeEventEnabledGCCreateConcurrentThread_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCCreateConcurrentThread_V1); + return ep_event_is_enabled(EventPipeEventGCCreateConcurrentThread_V1); } ULONG EventPipeWriteEventGCCreateConcurrentThread_V1( @@ -642,7 +642,7 @@ ULONG EventPipeWriteEventGCCreateConcurrentThread_V1( BOOL EventPipeEventEnabledGCCreateSegment_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCCreateSegment_V1); + return ep_event_is_enabled(EventPipeEventGCCreateSegment_V1); } ULONG EventPipeWriteEventGCCreateSegment_V1( @@ -686,7 +686,7 @@ ULONG EventPipeWriteEventGCCreateSegment_V1( BOOL EventPipeEventEnabledGCEnd_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCEnd_V1); + return ep_event_is_enabled(EventPipeEventGCEnd_V1); } ULONG EventPipeWriteEventGCEnd_V1( @@ -728,7 +728,7 @@ ULONG EventPipeWriteEventGCEnd_V1( BOOL EventPipeEventEnabledGCFreeSegment_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFreeSegment_V1); + return ep_event_is_enabled(EventPipeEventGCFreeSegment_V1); } ULONG EventPipeWriteEventGCFreeSegment_V1( @@ -768,7 +768,7 @@ ULONG EventPipeWriteEventGCFreeSegment_V1( BOOL EventPipeEventEnabledGCGenerationRange(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCGenerationRange); + return ep_event_is_enabled(EventPipeEventGCGenerationRange); } ULONG EventPipeWriteEventGCGenerationRange( @@ -814,7 +814,7 @@ ULONG EventPipeWriteEventGCGenerationRange( BOOL EventPipeEventEnabledGCHeapStats_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCHeapStats_V1); + return ep_event_is_enabled(EventPipeEventGCHeapStats_V1); } ULONG EventPipeWriteEventGCHeapStats_V1( @@ -878,7 +878,7 @@ ULONG EventPipeWriteEventGCHeapStats_V1( BOOL EventPipeEventEnabledGCJoin_V2(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCJoin_V2); + return ep_event_is_enabled(EventPipeEventGCJoin_V2); } ULONG EventPipeWriteEventGCJoin_V2( @@ -924,7 +924,7 @@ ULONG EventPipeWriteEventGCJoin_V2( BOOL EventPipeEventEnabledGCMarkFinalizeQueueRoots(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCMarkFinalizeQueueRoots); + return ep_event_is_enabled(EventPipeEventGCMarkFinalizeQueueRoots); } ULONG EventPipeWriteEventGCMarkFinalizeQueueRoots( @@ -964,7 +964,7 @@ ULONG EventPipeWriteEventGCMarkFinalizeQueueRoots( BOOL EventPipeEventEnabledGCMarkHandles(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCMarkHandles); + return ep_event_is_enabled(EventPipeEventGCMarkHandles); } ULONG EventPipeWriteEventGCMarkHandles( @@ -1004,7 +1004,7 @@ ULONG EventPipeWriteEventGCMarkHandles( BOOL EventPipeEventEnabledGCMarkOlderGenerationRoots(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCMarkOlderGenerationRoots); + return ep_event_is_enabled(EventPipeEventGCMarkOlderGenerationRoots); } ULONG EventPipeWriteEventGCMarkOlderGenerationRoots( @@ -1044,7 +1044,7 @@ ULONG EventPipeWriteEventGCMarkOlderGenerationRoots( BOOL EventPipeEventEnabledGCMarkStackRoots(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCMarkStackRoots); + return ep_event_is_enabled(EventPipeEventGCMarkStackRoots); } ULONG EventPipeWriteEventGCMarkStackRoots( @@ -1084,7 +1084,7 @@ ULONG EventPipeWriteEventGCMarkStackRoots( BOOL EventPipeEventEnabledGCMarkWithType(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCMarkWithType); + return ep_event_is_enabled(EventPipeEventGCMarkWithType); } ULONG EventPipeWriteEventGCMarkWithType( @@ -1128,7 +1128,7 @@ ULONG EventPipeWriteEventGCMarkWithType( BOOL EventPipeEventEnabledGCPerHeapHistory_V3(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCPerHeapHistory_V3); + return ep_event_is_enabled(EventPipeEventGCPerHeapHistory_V3); } ULONG EventPipeWriteEventGCPerHeapHistory_V3( @@ -1197,7 +1197,7 @@ ULONG EventPipeWriteEventGCPerHeapHistory_V3( BOOL EventPipeEventEnabledGCTerminateConcurrentThread_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCTerminateConcurrentThread_V1); + return ep_event_is_enabled(EventPipeEventGCTerminateConcurrentThread_V1); } ULONG EventPipeWriteEventGCTerminateConcurrentThread_V1( @@ -1235,7 +1235,7 @@ ULONG EventPipeWriteEventGCTerminateConcurrentThread_V1( BOOL EventPipeEventEnabledGCTriggered(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCTriggered); + return ep_event_is_enabled(EventPipeEventGCTriggered); } ULONG EventPipeWriteEventGCTriggered( @@ -1275,7 +1275,7 @@ ULONG EventPipeWriteEventGCTriggered( BOOL EventPipeEventEnabledModuleLoad_V2(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventModuleLoad_V2); + return ep_event_is_enabled(EventPipeEventModuleLoad_V2); } ULONG EventPipeWriteEventModuleLoad_V2( @@ -1341,7 +1341,7 @@ ULONG EventPipeWriteEventModuleLoad_V2( BOOL EventPipeEventEnabledSetGCHandle(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventSetGCHandle); + return ep_event_is_enabled(EventPipeEventSetGCHandle); } ULONG EventPipeWriteEventSetGCHandle( @@ -1389,7 +1389,7 @@ ULONG EventPipeWriteEventSetGCHandle( BOOL EventPipeEventEnabledGCStart_V2(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCStart_V2); + return ep_event_is_enabled(EventPipeEventGCStart_V2); } ULONG EventPipeWriteEventGCStart_V2( @@ -1437,7 +1437,7 @@ ULONG EventPipeWriteEventGCStart_V2( BOOL EventPipeEventEnabledGCRestartEEEnd_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCRestartEEEnd_V1); + return ep_event_is_enabled(EventPipeEventGCRestartEEEnd_V1); } ULONG EventPipeWriteEventGCRestartEEEnd_V1( @@ -1475,7 +1475,7 @@ ULONG EventPipeWriteEventGCRestartEEEnd_V1( BOOL EventPipeEventEnabledGCRestartEEBegin_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCRestartEEBegin_V1); + return ep_event_is_enabled(EventPipeEventGCRestartEEBegin_V1); } ULONG EventPipeWriteEventGCRestartEEBegin_V1( @@ -1513,7 +1513,7 @@ ULONG EventPipeWriteEventGCRestartEEBegin_V1( BOOL EventPipeEventEnabledGCSuspendEEEnd_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCSuspendEEEnd_V1); + return ep_event_is_enabled(EventPipeEventGCSuspendEEEnd_V1); } ULONG EventPipeWriteEventGCSuspendEEEnd_V1( @@ -1551,7 +1551,7 @@ ULONG EventPipeWriteEventGCSuspendEEEnd_V1( BOOL EventPipeEventEnabledGCSuspendEEBegin_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCSuspendEEBegin_V1); + return ep_event_is_enabled(EventPipeEventGCSuspendEEBegin_V1); } ULONG EventPipeWriteEventGCSuspendEEBegin_V1( @@ -1593,7 +1593,7 @@ ULONG EventPipeWriteEventGCSuspendEEBegin_V1( BOOL EventPipeEventEnabledDecreaseMemoryPressure(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventDecreaseMemoryPressure); + return ep_event_is_enabled(EventPipeEventDecreaseMemoryPressure); } ULONG EventPipeWriteEventDecreaseMemoryPressure( @@ -1632,7 +1632,7 @@ ULONG EventPipeWriteEventDecreaseMemoryPressure( BOOL EventPipeEventEnabledFinalizeObject(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventFinalizeObject); + return ep_event_is_enabled(EventPipeEventFinalizeObject); } ULONG EventPipeWriteEventFinalizeObject( @@ -1673,7 +1673,7 @@ ULONG EventPipeWriteEventFinalizeObject( BOOL EventPipeEventEnabledGCFinalizersBegin_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFinalizersBegin_V1); + return ep_event_is_enabled(EventPipeEventGCFinalizersBegin_V1); } ULONG EventPipeWriteEventGCFinalizersBegin_V1( @@ -1710,7 +1710,7 @@ ULONG EventPipeWriteEventGCFinalizersBegin_V1( BOOL EventPipeEventEnabledGCFinalizersEnd_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFinalizersEnd_V1); + return ep_event_is_enabled(EventPipeEventGCFinalizersEnd_V1); } ULONG EventPipeWriteEventGCFinalizersEnd_V1( @@ -1749,7 +1749,7 @@ ULONG EventPipeWriteEventGCFinalizersEnd_V1( BOOL EventPipeEventEnabledContentionStart_V2(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventContentionStart_V2); + return ep_event_is_enabled(EventPipeEventContentionStart_V2); } ULONG EventPipeWriteEventContentionStart_V2( @@ -1795,7 +1795,7 @@ ULONG EventPipeWriteEventContentionStart_V2( BOOL EventPipeEventEnabledContentionStop_V1(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventContentionStop_V1); + return ep_event_is_enabled(EventPipeEventContentionStop_V1); } ULONG EventPipeWriteEventContentionStop_V1( @@ -1837,7 +1837,7 @@ ULONG EventPipeWriteEventContentionStop_V1( BOOL EventPipeEventEnabledContentionLockCreated(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventContentionLockCreated); + return ep_event_is_enabled(EventPipeEventContentionLockCreated); } ULONG EventPipeWriteEventContentionLockCreated( @@ -1879,7 +1879,7 @@ ULONG EventPipeWriteEventContentionLockCreated( BOOL EventPipeEventEnabledThreadPoolWorkerThreadStart(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStart); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkerThreadStart); } ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( @@ -1921,7 +1921,7 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadStart( BOOL EventPipeEventEnabledThreadPoolWorkerThreadStop(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadStop); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkerThreadStop); } ULONG EventPipeWriteEventThreadPoolWorkerThreadStop( @@ -1962,7 +1962,7 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadStop( BOOL EventPipeEventEnabledThreadPoolWorkerThreadWait(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadWait); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkerThreadWait); } ULONG EventPipeWriteEventThreadPoolWorkerThreadWait( @@ -2003,7 +2003,7 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadWait( BOOL EventPipeEventEnabledThreadPoolMinMaxThreads(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolMinMaxThreads); + return ep_event_is_enabled(EventPipeEventThreadPoolMinMaxThreads); } ULONG EventPipeWriteEventThreadPoolMinMaxThreads( @@ -2048,7 +2048,7 @@ ULONG EventPipeWriteEventThreadPoolMinMaxThreads( BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentSample(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadAdjustmentSample); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkerThreadAdjustmentSample); } ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentSample( @@ -2087,7 +2087,7 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentSample( BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentAdjustment(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadAdjustmentAdjustment); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkerThreadAdjustmentAdjustment); } ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentAdjustment( @@ -2130,7 +2130,7 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentAdjustment( BOOL EventPipeEventEnabledThreadPoolWorkerThreadAdjustmentStats(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkerThreadAdjustmentStats); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkerThreadAdjustmentStats); } ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentStats( @@ -2187,7 +2187,7 @@ ULONG EventPipeWriteEventThreadPoolWorkerThreadAdjustmentStats( BOOL EventPipeEventEnabledThreadPoolIOEnqueue(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolIOEnqueue); + return ep_event_is_enabled(EventPipeEventThreadPoolIOEnqueue); } ULONG EventPipeWriteEventThreadPoolIOEnqueue( @@ -2230,7 +2230,7 @@ ULONG EventPipeWriteEventThreadPoolIOEnqueue( BOOL EventPipeEventEnabledThreadPoolIODequeue(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolIODequeue); + return ep_event_is_enabled(EventPipeEventThreadPoolIODequeue); } ULONG EventPipeWriteEventThreadPoolIODequeue( @@ -2271,7 +2271,7 @@ ULONG EventPipeWriteEventThreadPoolIODequeue( BOOL EventPipeEventEnabledThreadPoolWorkingThreadCount(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolWorkingThreadCount); + return ep_event_is_enabled(EventPipeEventThreadPoolWorkingThreadCount); } ULONG EventPipeWriteEventThreadPoolWorkingThreadCount( @@ -2310,7 +2310,7 @@ ULONG EventPipeWriteEventThreadPoolWorkingThreadCount( BOOL EventPipeEventEnabledThreadPoolIOPack(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventThreadPoolIOPack); + return ep_event_is_enabled(EventPipeEventThreadPoolIOPack); } ULONG EventPipeWriteEventThreadPoolIOPack( @@ -2351,7 +2351,7 @@ ULONG EventPipeWriteEventThreadPoolIOPack( BOOL EventPipeEventEnabledGCAllocationTick_V4(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCAllocationTick_V4); + return ep_event_is_enabled(EventPipeEventGCAllocationTick_V4); } ULONG EventPipeWriteEventGCAllocationTick_V4( @@ -2406,7 +2406,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V4( BOOL EventPipeEventEnabledGCHeapStats_V2(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCHeapStats_V2); + return ep_event_is_enabled(EventPipeEventGCHeapStats_V2); } ULONG EventPipeWriteEventGCHeapStats_V2( @@ -2474,7 +2474,7 @@ ULONG EventPipeWriteEventGCHeapStats_V2( BOOL EventPipeEventEnabledGCSampledObjectAllocationHigh(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCSampledObjectAllocationHigh); + return ep_event_is_enabled(EventPipeEventGCSampledObjectAllocationHigh); } ULONG EventPipeWriteEventGCSampledObjectAllocationHigh( @@ -2520,7 +2520,7 @@ ULONG EventPipeWriteEventGCSampledObjectAllocationHigh( BOOL EventPipeEventEnabledGCSampledObjectAllocationLow(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCSampledObjectAllocationLow); + return ep_event_is_enabled(EventPipeEventGCSampledObjectAllocationLow); } ULONG EventPipeWriteEventGCSampledObjectAllocationLow( @@ -2566,7 +2566,7 @@ ULONG EventPipeWriteEventGCSampledObjectAllocationLow( BOOL EventPipeEventEnabledPinObjectAtGCTime(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventPinObjectAtGCTime); + return ep_event_is_enabled(EventPipeEventPinObjectAtGCTime); } ULONG EventPipeWriteEventPinObjectAtGCTime( @@ -2613,7 +2613,7 @@ ULONG EventPipeWriteEventPinObjectAtGCTime( BOOL EventPipeEventEnabledGCBulkRootStaticVar(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCBulkRootStaticVar); + return ep_event_is_enabled(EventPipeEventGCBulkRootStaticVar); } ULONG EventPipeWriteEventGCBulkRootStaticVar( @@ -2658,7 +2658,7 @@ ULONG EventPipeWriteEventGCBulkRootStaticVar( BOOL EventPipeEventEnabledIncreaseMemoryPressure(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventIncreaseMemoryPressure); + return ep_event_is_enabled(EventPipeEventIncreaseMemoryPressure); } ULONG EventPipeWriteEventIncreaseMemoryPressure( @@ -2698,7 +2698,7 @@ ULONG EventPipeWriteEventIncreaseMemoryPressure( BOOL EventPipeEventEnabledGCGlobalHeapHistory_V4(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCGlobalHeapHistory_V4); + return ep_event_is_enabled(EventPipeEventGCGlobalHeapHistory_V4); } ULONG EventPipeWriteEventGCGlobalHeapHistory_V4( @@ -2761,7 +2761,7 @@ ULONG EventPipeWriteEventGCGlobalHeapHistory_V4( BOOL EventPipeEventEnabledGenAwareBegin(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGenAwareBegin); + return ep_event_is_enabled(EventPipeEventGenAwareBegin); } ULONG EventPipeWriteEventGenAwareBegin( @@ -2801,7 +2801,7 @@ ULONG EventPipeWriteEventGenAwareBegin( BOOL EventPipeEventEnabledGenAwareEnd(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGenAwareEnd); + return ep_event_is_enabled(EventPipeEventGenAwareEnd); } ULONG EventPipeWriteEventGenAwareEnd( @@ -2841,7 +2841,7 @@ ULONG EventPipeWriteEventGenAwareEnd( BOOL EventPipeEventEnabledGCLOHCompact(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCLOHCompact); + return ep_event_is_enabled(EventPipeEventGCLOHCompact); } ULONG EventPipeWriteEventGCLOHCompact( @@ -2884,7 +2884,7 @@ ULONG EventPipeWriteEventGCLOHCompact( BOOL EventPipeEventEnabledGCFitBucketInfo(void) { - return EventPipeAdapter::EventIsEnabled(EventPipeEventGCFitBucketInfo); + return ep_event_is_enabled(EventPipeEventGCFitBucketInfo); } ULONG EventPipeWriteEventGCFitBucketInfo( diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h index bd982b81da7ee..3afd85aac0d93 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // Implementation of ds-rt.h targeting NativeAOT runtime. -#ifndef __DIAGNOSTICS_RT_AOT_H__ -#define __DIAGNOSTICS_RT_AOT_H__ +#ifndef DIAGNOSTICS_RT_AOT_H +#define DIAGNOSTICS_RT_AOT_H #include @@ -314,4 +314,4 @@ ds_rt_server_log_pause_message (void) } #endif /* ENABLE_PERFTRACING */ -#endif /* __DIAGNOSTICS_RT_AOT_H__ */ +#endif /* DIAGNOSTICS_RT_AOT_H */ diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-types-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-types-aot.h index 7656799718534..e386eca5a2301 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-types-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-types-aot.h @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // Implementation of ds-rt-types.h targeting NativeAOT runtime. -#ifndef __DIAGNOSTICS_RT_TYPES_AOT_H__ -#define __DIAGNOSTICS_RT_TYPES_AOT_H__ +#ifndef DIAGNOSTICS_RT_TYPES_AOT_H +#define DIAGNOSTICS_RT_TYPES_AOT_H #include @@ -11,4 +11,4 @@ #include "ep-rt-types-aot.h" #endif /* ENABLE_PERFTRACING */ -#endif /* __DIAGNOSTICS_RT_TYPES_AOT_H__ */ +#endif /* DIAGNOSTICS_RT_TYPES_AOT_H */ diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index 2687fc8f35ed5..899c949821683 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // Implementation of ep-rt.h targeting NativeAOT runtime. -#ifndef __EVENTPIPE_RT_AOT_H__ -#define __EVENTPIPE_RT_AOT_H__ +#ifndef EVENTPIPE_RT_AOT_H +#define EVENTPIPE_RT_AOT_H #include // For isspace #ifdef TARGET_UNIX @@ -2009,4 +2009,4 @@ ep_rt_volatile_store_ptr_without_barrier ( } #endif /* ENABLE_PERFTRACING */ -#endif /* __EVENTPIPE_RT_AOT_H__ */ +#endif /* EVENTPIPE_RT_AOT_H */ diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h index 75c35c33c14e7..335b8ce56778d 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#ifndef __EVENTPIPE_RT_CONFIG_AOT_H__ -#define __EVENTPIPE_RT_CONFIG_AOT_H__ +#ifndef EVENTPIPE_RT_CONFIG_AOT_H +#define EVENTPIPE_RT_CONFIG_AOT_H -#endif /* __EVENTPIPE_RT_CONFIG_AOT_H__ */ +#endif /* EVENTPIPE_RT_CONFIG_AOT_H */ diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h index 22c777f692812..c6899ba2792f7 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // Implementation of ep-rt-types.h targeting AOT runtime. -#ifndef __EVENTPIPE_RT_TYPES_AOT_H__ -#define __EVENTPIPE_RT_TYPES_AOT_H__ +#ifndef EVENTPIPE_RT_TYPES_AOT_H +#define EVENTPIPE_RT_TYPES_AOT_H #include @@ -102,4 +102,4 @@ typedef struct _rt_aot_thread_params_t { } ep_rt_thread_params_t; #endif /* ENABLE_PERFTRACING */ -#endif /* __EVENTPIPE_RT_TYPES_AOT_H__ */ +#endif /* EVENTPIPE_RT_TYPES_AOT_H */ diff --git a/src/coreclr/nativeaot/Runtime/eventpipeadapter.h b/src/coreclr/nativeaot/Runtime/eventpipeadapter.h index c4e8ff4642d8b..9f1b67db5a89a 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeadapter.h +++ b/src/coreclr/nativeaot/Runtime/eventpipeadapter.h @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#ifndef __EVENTPIPE_ADAPTER_H__ -#define __EVENTPIPE_ADAPTER_H__ +#ifndef EVENTPIPE_ADAPTER_H +#define EVENTPIPE_ADAPTER_H #if defined(FEATURE_PERFTRACING) @@ -24,77 +24,6 @@ #include "holder.h" #include "SpinLock.h" -typedef /* [public][public][public] */ struct __MIDL___MIDL_itf_corprof_0000_0000_0015 -{ -const WCHAR *providerName; -uint64_t keywords; -uint32_t loggingLevel; -const WCHAR *filterData; -} COR_PRF_EVENTPIPE_PROVIDER_CONFIG; - - -class EventPipeProviderConfigurationAdapter final -{ -public: - EventPipeProviderConfigurationAdapter(const COR_PRF_EVENTPIPE_PROVIDER_CONFIG *providerConfigs, uint32_t providerConfigsLen) - { - STATIC_CONTRACT_NOTHROW; - - // This static_assert will fail because EventPipeProviderConfiguration uses char8_t strings rather than char16_t strings. - // This method takes the COR_PRF variant and converts to char8_t strings, so it should be fine. - // Leaving the assert commented out here for posterity. - // - // static_assert(offsetof(EventPipeProviderConfiguration, provider_name) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, providerName) - // && offsetof(EventPipeProviderConfiguration, keywords) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, keywords) - // && offsetof(EventPipeProviderConfiguration, logging_level) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, loggingLevel) - // && offsetof(EventPipeProviderConfiguration, filter_data) == offsetof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG, filterData) - // && sizeof(EventPipeProviderConfiguration) == sizeof(COR_PRF_EVENTPIPE_PROVIDER_CONFIG), - // "Layouts of EventPipeProviderConfiguration type and COR_PRF_EVENTPIPE_PROVIDER_CONFIG type do not match!"); - - m_providerConfigs = new (nothrow) EventPipeProviderConfiguration[providerConfigsLen]; - m_providerConfigsLen = providerConfigsLen; - if (m_providerConfigs) { - for (uint32_t i = 0; i < providerConfigsLen; ++i) { - ep_provider_config_init ( - &m_providerConfigs[i], - ep_rt_utf16_to_utf8_string (reinterpret_cast(providerConfigs[i].providerName), -1), - providerConfigs[i].keywords, - static_cast(providerConfigs[i].loggingLevel), - ep_rt_utf16_to_utf8_string (reinterpret_cast(providerConfigs[i].filterData), -1)); - } - } - } - - ~EventPipeProviderConfigurationAdapter() - { - STATIC_CONTRACT_NOTHROW; - if (m_providerConfigs) { - for (uint32_t i = 0; i < m_providerConfigsLen; ++i) { - ep_rt_utf8_string_free ((ep_char8_t *)ep_provider_config_get_provider_name (&m_providerConfigs[i])); - ep_rt_utf8_string_free ((ep_char8_t *)ep_provider_config_get_filter_data (&m_providerConfigs[i])); - } - delete [] m_providerConfigs; - } - } - - inline const EventPipeProviderConfiguration * GetProviderConfigs() const - { - STATIC_CONTRACT_NOTHROW; - return m_providerConfigs; - } - - inline uint32_t GetProviderConfigsLen() const - { - STATIC_CONTRACT_NOTHROW; - return m_providerConfigsLen; - } - -private: - EventPipeProviderConfiguration *m_providerConfigs; - uint32_t m_providerConfigsLen; -}; - - class EventPipeAdapter final { public: @@ -145,37 +74,6 @@ class EventPipeAdapter final return ep_enabled(); } - static inline EventPipeSessionID Enable( - LPCWSTR outputPath, - uint32_t circularBufferSizeInMB, - const EventPipeProviderConfigurationAdapter &providerConfigs, - EventPipeSessionType sessionType, - EventPipeSerializationFormat format, - const bool rundownRequested, - IpcStream *const stream, - EventPipeSessionSynchronousCallback callback, - void *callbackAdditionalData) - { - STATIC_CONTRACT_NOTHROW; - - ep_char8_t *outputPathUTF8 = NULL; - if (outputPath) - outputPathUTF8 = ep_rt_utf16_to_utf8_string (reinterpret_cast(outputPath), -1); - EventPipeSessionID result = ep_enable ( - outputPathUTF8, - circularBufferSizeInMB, - providerConfigs.GetProviderConfigs(), - providerConfigs.GetProviderConfigsLen(), - sessionType, - format, - rundownRequested, - stream, - callback, - callbackAdditionalData); - ep_rt_utf8_string_free (outputPathUTF8); - return result; - } - static inline void Disable(EventPipeSessionID id) { CONTRACTL @@ -189,69 +87,6 @@ class EventPipeAdapter final ep_disable(id); } - static inline void StartStreaming(EventPipeSessionID id) - { - CONTRACTL - { - NOTHROW; - GC_TRIGGERS; - MODE_ANY; - } - CONTRACTL_END; - - ep_start_streaming(id); - } - - static inline EventPipeSession * GetSession(EventPipeSessionID id) - { - STATIC_CONTRACT_NOTHROW; - return ep_get_session(id); - } - - static inline bool SignalSession(EventPipeSessionID id) - { - STATIC_CONTRACT_NOTHROW; - - EventPipeSession *const session = ep_get_session (id); - if (!session) - return false; - - return ep_rt_wait_event_set (ep_session_get_wait_event (session)); - } - - static inline bool WaitForSessionSignal(EventPipeSessionID id, int32_t timeoutMs) - { - STATIC_CONTRACT_NOTHROW; - - EventPipeSession *const session = ep_get_session (id); - if (!session) - return false; - - return !ep_rt_wait_event_wait (ep_session_get_wait_event (session), (uint32_t)timeoutMs, false) ? true : false; - } - - static inline FILETIME GetSessionStartTime(EventPipeSession *session) - { - STATIC_CONTRACT_NOTHROW; - - FILETIME fileTime; - LARGE_INTEGER largeValue; - - _ASSERTE(session != NULL); - largeValue.QuadPart = ep_session_get_session_start_time(session); - fileTime.dwLowDateTime = largeValue.u.LowPart; - fileTime.dwHighDateTime = largeValue.u.HighPart; - return fileTime; - } - - static inline int64_t GetSessionStartTimestamp(EventPipeSession *session) - { - STATIC_CONTRACT_NOTHROW; - - _ASSERTE(session != NULL); - return ep_session_get_session_start_timestamp(session); - } - static inline EventPipeProvider * GetProvider (LPCWSTR providerName) { CONTRACTL @@ -313,69 +148,7 @@ class EventPipeAdapter final reinterpret_cast(activityId), reinterpret_cast(relatedActivityId)); } - - static inline bool EventIsEnabled (const EventPipeEvent *epEvent) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_is_enabled(epEvent); - } - - static inline EventPipeEventInstance * GetNextEvent (EventPipeSessionID id) - { - STATIC_CONTRACT_NOTHROW; - return ep_get_next_event(id); - } - - static inline EventPipeProvider * GetEventProvider (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_get_provider(ep_event_instance_get_ep_event(eventInstance)); - } - - static inline uint32_t GetEventID (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_get_event_id(ep_event_instance_get_ep_event(eventInstance)); - } - - static inline uint64_t GetEventThreadID (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_instance_get_thread_id(eventInstance); - } - - static inline int64_t GetEventTimestamp (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_instance_get_timestamp(eventInstance); - } - - static inline const GUID * GetEventActivityID (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - static_assert(sizeof(GUID) == EP_ACTIVITY_ID_SIZE, "Size mismatch, sizeof(GUID) should be equal to EP_ACTIVITY_ID_SIZE"); - return reinterpret_cast(ep_event_instance_get_activity_id_cref(eventInstance)); - } - - static inline const GUID * GetEventRelativeActivityID (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - static_assert(sizeof(GUID) == EP_ACTIVITY_ID_SIZE, "Size mismatch, sizeof(GUID) should be equal to EP_ACTIVITY_ID_SIZE"); - return reinterpret_cast(ep_event_instance_get_related_activity_id_cref(eventInstance)); - } - - static inline const uint8_t * GetEventData (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_instance_get_data(eventInstance); - } - - static inline uint32_t GetEventDataLen (EventPipeEventInstance *eventInstance) - { - STATIC_CONTRACT_NOTHROW; - return ep_event_instance_get_data_len(eventInstance); - } }; #endif // FEATURE_PERFTRACING -#endif // __EVENTPIPE_ADAPTER_H__ +#endif // EVENTPIPE_ADAPTER_H diff --git a/src/coreclr/nativeaot/Runtime/eventpipeadaptertypes.h b/src/coreclr/nativeaot/Runtime/eventpipeadaptertypes.h index f473bde10488d..9d9df452ac7b0 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeadaptertypes.h +++ b/src/coreclr/nativeaot/Runtime/eventpipeadaptertypes.h @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#ifndef __EVENTPIPE_ADAPTER_TYPES_H__ -#define __EVENTPIPE_ADAPTER_TYPES_H__ +#ifndef EVENTPIPE_ADAPTER_TYPES_H +#define EVENTPIPE_ADAPTER_TYPES_H #if defined(FEATURE_PERFTRACING) @@ -12,4 +12,4 @@ typedef struct _EventPipeProvider EventPipeProvider; typedef struct _EventPipeSession EventPipeSession; #endif // FEATURE_PERFTRACING -#endif // __EVENTPIPE_ADAPTER_TYPES_H__ +#endif // EVENTPIPE_ADAPTER_TYPES_H diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 58105ac769ee7..38f1dead1e847 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -31,6 +31,14 @@ struct EventPipeSessionInfo uint64_t TimeStampFrequency; }; +struct EventPipeProviderConfigurationNative +{ + wchar_t *pProviderName; + uint64_t keywords; + uint32_t loggingLevel; + wchar_t *pFilterData; +}; + EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( LPCWSTR outputFile, EventPipeSerializationFormat format, @@ -48,21 +56,40 @@ EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( return 0; } - EventPipeProviderConfigurationAdapter configAdapter(reinterpret_cast(pProviders), numProviders); - - sessionID = EventPipeAdapter::Enable( - outputFile, - circularBufferSizeInMB, - configAdapter, - outputFile != NULL ? EP_SESSION_TYPE_FILE : EP_SESSION_TYPE_LISTENER, - format, - true, - nullptr, - nullptr, - nullptr); - EventPipeAdapter::StartStreaming(sessionID); - - return sessionID; + const EventPipeProviderConfigurationNative *nativeProviders = reinterpret_cast(pProviders); + + EventPipeProviderConfiguration * configProviders = reinterpret_cast(malloc ((numProviders) * sizeof (EventPipeProviderConfiguration))); + + if (configProviders) { + for (uint32_t i = 0; i < numProviders; ++i) { + ep_provider_config_init ( + &configProviders[i], + ep_rt_utf16_to_utf8_string (reinterpret_cast(nativeProviders[i].pProviderName), -1), + nativeProviders[i].keywords, + static_cast(nativeProviders[i].loggingLevel), + ep_rt_utf16_to_utf8_string (reinterpret_cast(nativeProviders[i].pFilterData), -1)); + } + } + + ep_char8_t *outputPathUTF8 = NULL; + if (outputFile) + outputPathUTF8 = ep_rt_utf16_to_utf8_string (reinterpret_cast(outputFile), -1); + EventPipeSessionID result = ep_enable ( + outputPathUTF8, + circularBufferSizeInMB, + configProviders, + numProviders, + outputFile != NULL ? EP_SESSION_TYPE_FILE : EP_SESSION_TYPE_LISTENER, + format, + false, + nullptr, + nullptr, + nullptr); + ep_rt_utf8_string_free (outputPathUTF8); + + ep_start_streaming(result); + + return result; } EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_Disable(uint64_t sessionID) @@ -115,7 +142,6 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_DeleteProvider(intptr_t EXTERN_C NATIVEAOT_API int __cdecl RhEventPipeInternal_EventActivityIdControl(uint32_t controlCode, GUID *pActivityId) { - PalDebugBreak(); return 0; } @@ -153,17 +179,17 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetNextEvent(uint EventPipeEventInstance *pNextInstance = NULL; _ASSERTE(pInstance != NULL); - pNextInstance = EventPipeAdapter::GetNextEvent(sessionID); + pNextInstance = ep_get_next_event(sessionID); if (pNextInstance) { - pInstance->ProviderID = EventPipeAdapter::GetEventProvider(pNextInstance); - pInstance->EventID = EventPipeAdapter::GetEventID(pNextInstance); - pInstance->ThreadID = static_cast(EventPipeAdapter::GetEventThreadID(pNextInstance)); - pInstance->TimeStamp.QuadPart = EventPipeAdapter::GetEventTimestamp(pNextInstance); - pInstance->ActivityId = *EventPipeAdapter::GetEventActivityID(pNextInstance); - pInstance->RelatedActivityId = *EventPipeAdapter::GetEventRelativeActivityID(pNextInstance); - pInstance->Payload = EventPipeAdapter::GetEventData(pNextInstance); - pInstance->PayloadLength = EventPipeAdapter::GetEventDataLen(pNextInstance); + pInstance->ProviderID = ep_event_get_provider(ep_event_instance_get_ep_event(pNextInstance)); + pInstance->EventID = ep_event_get_event_id(ep_event_instance_get_ep_event(pNextInstance)); + pInstance->ThreadID = static_cast(ep_event_get_event_id(ep_event_instance_get_ep_event(pNextInstance))); + pInstance->TimeStamp.QuadPart = ep_event_instance_get_timestamp(pNextInstance); + pInstance->ActivityId = *reinterpret_cast(ep_event_instance_get_activity_id_cref(pNextInstance)); + pInstance->RelatedActivityId = *reinterpret_cast(ep_event_instance_get_related_activity_id_cref(pNextInstance)); + pInstance->Payload = ep_event_instance_get_data(pNextInstance); + pInstance->PayloadLength = ep_event_instance_get_data_len(pNextInstance); } return pNextInstance != NULL; @@ -171,12 +197,20 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_GetNextEvent(uint EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_SignalSession(uint64_t sessionID) { - return EventPipeAdapter::SignalSession(sessionID); + EventPipeSession *const session = ep_get_session (sessionID); + if (!session) + return false; + + return ep_rt_wait_event_set (ep_session_get_wait_event (session)); } EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSignal(uint64_t sessionID, int32_t timeoutMs) { - return EventPipeAdapter::WaitForSessionSignal(sessionID, timeoutMs); + EventPipeSession *const session = ep_get_session (sessionID); + if (!session) + return false; + + return !ep_rt_wait_event_wait (ep_session_get_wait_event (session), (uint32_t)timeoutMs, false) ? true : false; } #endif // FEATURE_PERFTRACING From e4926c80aa5d1a0b1a16966aaa258d2453a19345 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Tue, 4 Jul 2023 07:27:49 -0700 Subject: [PATCH 20/22] latest FB --- src/coreclr/nativeaot/Runtime/clretwallmain.h | 4 +- .../Runtime/clreventpipewriteevents.h | 4 +- .../Runtime/disabledruntimeeventinternal.cpp | 12 ++--- .../eventpipe/disableddotnetruntime.cpp | 4 +- .../Runtime/eventpipe/dotnetruntime.cpp | 8 +-- .../nativeaot/Runtime/eventpipeinternal.cpp | 54 +++++++++++-------- .../nativeaot/Runtime/gctoclreventsink.cpp | 2 +- .../Runtime/runtimeeventinternal.cpp | 14 ++--- .../src/System/Runtime/RuntimeImports.cs | 12 ++--- 9 files changed, 59 insertions(+), 55 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/clretwallmain.h b/src/coreclr/nativeaot/Runtime/clretwallmain.h index 979804600fb54..99c60a92c7f01 100644 --- a/src/coreclr/nativeaot/Runtime/clretwallmain.h +++ b/src/coreclr/nativeaot/Runtime/clretwallmain.h @@ -866,7 +866,7 @@ inline ULONG FireEtwGCAllocationTick_V4( const unsigned short ClrInstanceID, const unsigned __int64 AllocationAmount64, const void* TypeID, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned int HeapIndex, const void* Address, const unsigned __int64 ObjectSize, @@ -943,7 +943,7 @@ inline ULONG FireEtwPinObjectAtGCTime( const void* HandleID, const void* ObjectID, const unsigned __int64 ObjectSize, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned short ClrInstanceID, const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr diff --git a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h index 211b0ae2fbeca..92da9196ec901 100644 --- a/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h +++ b/src/coreclr/nativeaot/Runtime/clreventpipewriteevents.h @@ -468,7 +468,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V4( const unsigned short ClrInstanceID, const unsigned __int64 AllocationAmount64, const void* TypeID, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned int HeapIndex, const void* Address, const unsigned __int64 ObjectSize, @@ -521,7 +521,7 @@ ULONG EventPipeWriteEventPinObjectAtGCTime( const void* HandleID, const void* ObjectID, const unsigned __int64 ObjectSize, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned short ClrInstanceID, const GUID * ActivityId = nullptr, const GUID * RelatedActivityId = nullptr diff --git a/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp b/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp index 86a76cc938152..57ef8d3604b68 100644 --- a/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp @@ -11,11 +11,11 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionLockCr { } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStart(uint8_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) { } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStop(uint8_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) { } @@ -59,14 +59,14 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorker } EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOEnqueue( - uint32_t * NativeOverlapped, - uint32_t * Overlapped, + void * NativeOverlapped, + void * Overlapped, bool MultiDequeues, uint16_t ClrInstanceID) { } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIODequeue(void * NativeOverlapped, void * Overlapped, uint16_t ClrInstanceID) { } @@ -74,7 +74,7 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkin { } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack(void * NativeOverlapped, void * Overlapped, uint16_t ClrInstanceID) { } diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp index 137ba48870043..f2ba91f3c4d2d 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/disableddotnetruntime.cpp @@ -457,7 +457,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V4( const unsigned short ClrInstanceID, const unsigned __int64 AllocationAmount64, const void* TypeID, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned int HeapIndex, const void* Address, const unsigned __int64 ObjectSize, @@ -526,7 +526,7 @@ ULONG EventPipeWriteEventPinObjectAtGCTime( const void* HandleID, const void* ObjectID, const unsigned __int64 ObjectSize, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned short ClrInstanceID, const GUID * ActivityId, const GUID * RelatedActivityId diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index 0084b06f1eb28..302b3ab7491ff 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -2360,7 +2360,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V4( const unsigned short ClrInstanceID, const unsigned __int64 AllocationAmount64, const void* TypeID, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned int HeapIndex, const void* Address, const unsigned __int64 ObjectSize, @@ -2377,7 +2377,7 @@ ULONG EventPipeWriteEventGCAllocationTick_V4( bool fixedBuffer = true; bool success = true; - if (!TypeName) { TypeName = L"NULL"; } + if (!TypeName) { TypeName = W("NULL"); } success &= WriteToBuffer(AllocationAmount, buffer, offset, size, fixedBuffer); success &= WriteToBuffer(AllocationKind, buffer, offset, size, fixedBuffer); success &= WriteToBuffer(ClrInstanceID, buffer, offset, size, fixedBuffer); @@ -2573,7 +2573,7 @@ ULONG EventPipeWriteEventPinObjectAtGCTime( const void* HandleID, const void* ObjectID, const unsigned __int64 ObjectSize, - const wchar_t* TypeName, + const WCHAR* TypeName, const unsigned short ClrInstanceID, const GUID * ActivityId, const GUID * RelatedActivityId) @@ -2588,7 +2588,7 @@ ULONG EventPipeWriteEventPinObjectAtGCTime( bool fixedBuffer = true; bool success = true; - if (!TypeName) { TypeName = L"NULL"; } + if (!TypeName) { TypeName = W("NULL"); } success &= WriteToBuffer(HandleID, buffer, offset, size, fixedBuffer); success &= WriteToBuffer(ObjectID, buffer, offset, size, fixedBuffer); success &= WriteToBuffer(ObjectSize, buffer, offset, size, fixedBuffer); diff --git a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp index 38f1dead1e847..d9e77f9db0e89 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp @@ -33,10 +33,10 @@ struct EventPipeSessionInfo struct EventPipeProviderConfigurationNative { - wchar_t *pProviderName; + WCHAR *pProviderName; uint64_t keywords; uint32_t loggingLevel; - wchar_t *pFilterData; + WCHAR *pFilterData; }; EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( @@ -71,23 +71,31 @@ EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable( } } - ep_char8_t *outputPathUTF8 = NULL; - if (outputFile) - outputPathUTF8 = ep_rt_utf16_to_utf8_string (reinterpret_cast(outputFile), -1); - EventPipeSessionID result = ep_enable ( - outputPathUTF8, - circularBufferSizeInMB, - configProviders, - numProviders, - outputFile != NULL ? EP_SESSION_TYPE_FILE : EP_SESSION_TYPE_LISTENER, - format, - false, - nullptr, - nullptr, - nullptr); - ep_rt_utf8_string_free (outputPathUTF8); - - ep_start_streaming(result); + ep_char8_t *outputPathUTF8 = NULL; + if (outputFile) + outputPathUTF8 = ep_rt_utf16_to_utf8_string (reinterpret_cast(outputFile), -1); + EventPipeSessionID result = ep_enable ( + outputPathUTF8, + circularBufferSizeInMB, + configProviders, + numProviders, + outputFile != NULL ? EP_SESSION_TYPE_FILE : EP_SESSION_TYPE_LISTENER, + format, + false, + nullptr, + nullptr, + nullptr); + ep_rt_utf8_string_free (outputPathUTF8); + + ep_start_streaming(result); + + if (configProviders) { + for (uint32_t i = 0; i < numProviders; ++i) { + ep_rt_utf8_string_free ((ep_char8_t *)ep_provider_config_get_provider_name (&configProviders[i])); + ep_rt_utf8_string_free ((ep_char8_t *)ep_provider_config_get_filter_data (&configProviders[i])); + } + free(configProviders); + } return result; } @@ -206,11 +214,11 @@ EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_SignalSession(uin EXTERN_C NATIVEAOT_API UInt32_BOOL __cdecl RhEventPipeInternal_WaitForSessionSignal(uint64_t sessionID, int32_t timeoutMs) { - EventPipeSession *const session = ep_get_session (sessionID); - if (!session) - return false; + EventPipeSession *const session = ep_get_session (sessionID); + if (!session) + return false; - return !ep_rt_wait_event_wait (ep_session_get_wait_event (session), (uint32_t)timeoutMs, false) ? true : false; + return !ep_rt_wait_event_wait (ep_session_get_wait_event (session), (uint32_t)timeoutMs, false) ? true : false; } #endif // FEATURE_PERFTRACING diff --git a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp index 095c90a7375a8..2dbf0b6482bd5 100644 --- a/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp +++ b/src/coreclr/nativeaot/Runtime/gctoclreventsink.cpp @@ -161,7 +161,7 @@ void GCToCLREventSink::FireGCAllocationTick_V4(uint64_t allocationAmount, LIMITED_METHOD_CONTRACT; void * typeId = RedhawkGCInterface::GetLastAllocEEType(); - wchar_t * name = nullptr; + WCHAR * name = nullptr; if (typeId != nullptr) { diff --git a/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp b/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp index 469b94282a895..eebe490f3e0b6 100644 --- a/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp +++ b/src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp @@ -10,12 +10,12 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionLockCr FireEtwContentionLockCreated(reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), ClrInstanceID); } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStart(uint16_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStart(uint8_t ContentionFlags, uint16_t ClrInstanceID, intptr_t LockID, intptr_t AssociatedObjectID, uint64_t LockOwnerThreadID) { FireEtwContentionStart_V2((const unsigned char)(ContentionFlags), ClrInstanceID, reinterpret_cast(LockID), reinterpret_cast(AssociatedObjectID), LockOwnerThreadID); } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStop(uint16_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogContentionStop(uint8_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs) { FireEtwContentionStop_V1((const unsigned char)(ContentionFlags), ClrInstanceID, DurationNs); } @@ -67,15 +67,15 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorker } EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOEnqueue( - uint32_t * NativeOverlapped, - uint32_t * Overlapped, - bool MultiDequeues, + void * NativeOverlapped, + void * Overlapped, + BOOL MultiDequeues, uint16_t ClrInstanceID) { FireEtwThreadPoolIOEnqueue(NativeOverlapped, Overlapped, MultiDequeues, ClrInstanceID); } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIODequeue(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIODequeue(void * NativeOverlapped, void * Overlapped, uint16_t ClrInstanceID) { FireEtwThreadPoolIODequeue(NativeOverlapped, Overlapped, ClrInstanceID); } @@ -85,7 +85,7 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolWorkin FireEtwThreadPoolWorkingThreadCount(Count, ClrInstanceID); } -EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack(uint32_t * NativeOverlapped, uint32_t * Overlapped, uint16_t ClrInstanceID) +EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack(void * NativeOverlapped, void * Overlapped, uint16_t ClrInstanceID) { FireEtwThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID); } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 6d2d4f18563a8..6b9f785dc00ee 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -667,14 +667,6 @@ public GCFrameRegistration(void* allocation, uint elemCount, bool areByRefs = tr #if FEATURE_PERFTRACING - - // - // ETW helpers. - // - [LibraryImport(RuntimeLibrary)] - [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] - internal static unsafe partial void NativeRuntimeEventSource_LogExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); - // // EventPipeInternal helpers. // @@ -822,6 +814,10 @@ internal static partial void NativeRuntimeEventSource_LogThreadPoolIOPack( IntPtr NativeOverlapped, IntPtr Overlapped, ushort ClrInstanceID); + + [LibraryImport(RuntimeLibrary)] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })] + internal static unsafe partial void NativeRuntimeEventSource_LogExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); #endif // FEATURE_PERFTRACING // From fb14519260171bbeedc9daf57418d0a94a2284e4 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Wed, 5 Jul 2023 04:27:31 -0700 Subject: [PATCH 21/22] Pulled PR 88365 --- .../Runtime/eventpipe/dotnetruntime.cpp | 17 +++++++++++ .../simpleruntimeeventvalidation.cs | 30 ++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp index 302b3ab7491ff..53c4574f9f2b6 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp @@ -64,6 +64,23 @@ bool WriteToBuffer(const BYTE *src, size_t len, BYTE *&buffer, size_t& offset, s return true; } +bool WriteToBuffer(const WCHAR* str, BYTE *&buffer, size_t& offset, size_t& size, bool &fixedBuffer) +{ + if (str == NULL) + return true; + + size_t byteCount = (ep_rt_utf16_string_len(reinterpret_cast(str)) + 1) * sizeof(*str); + if (offset + byteCount > size) + { + if (!ResizeBuffer(buffer, size, offset, size + byteCount, fixedBuffer)) + return false; + } + + memcpy(buffer + offset, str, byteCount); + offset += byteCount; + return true; +} + bool ResizeBuffer(BYTE *&buffer, size_t& size, size_t currLen, size_t newSize, bool &fixedBuffer) { newSize = (size_t)(newSize * 1.5); diff --git a/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs index 4f4a95d5d5f95..6272649d06885 100644 --- a/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs +++ b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs @@ -25,7 +25,7 @@ public static int Main() _eventGeneratingActionForGC, //GCKeyword (0x1): 0b1 new List(){new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1)}, - 1024, _DoesTraceContainEvents, enableRundownProvider:false); + 1024, _DoesTraceContainGCEvents, enableRundownProvider:false); GC.Collect(); GC.WaitForPendingFinalizers(); @@ -37,11 +37,11 @@ public static int Main() ret = IpcTraceTest.RunAndValidateEventCounts( // Validate the exception type and message after the below issue is fixed. For now, check that the event is fired // https://github.com/dotnet/runtime/issues/87978 - new Dictionary(){{ "Microsoft-Windows-DotNETRuntime", 1000 }}, + new Dictionary(){{ "Microsoft-DotNETCore-EventPipe", 1 }}, _eventGeneratingActionForExceptions, //ExceptionKeyword (0x8000): 0b1000_0000_0000_0000 new List(){new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Warning, 0b1000_0000_0000_0000)}, - 1024, enableRundownProvider:false); + 1024, _DoesTraceContainExceptionEvents, enableRundownProvider:false); } if (ret < 0) @@ -64,9 +64,9 @@ public static int Main() private static Action _eventGeneratingActionForExceptions = () => { - for (int i = 0; i < 1000; i++) + for (int i = 0; i < 10; i++) { - if (i % 100 == 0) + if (i % 5 == 0) Logger.logger.Log($"Thrown an exception {i} times..."); try { @@ -79,8 +79,7 @@ public static int Main() } }; - - private static Func> _DoesTraceContainEvents = (source) => + private static Func> _DoesTraceContainGCEvents = (source) => { int GCStartEvents = 0; int GCEndEvents = 0; @@ -119,5 +118,22 @@ public static int Main() }; }; + private static Func> _DoesTraceContainExceptionEvents = (source) => + { + int ExStartEvents = 0; + source.Clr.ExceptionStart += (eventData) => + { + if(eventData.ToString().IndexOf("System.ArgumentNullException")>=0) + ExStartEvents += 1; + }; + + return () => { + Logger.logger.Log("Exception Event counts validation"); + Logger.logger.Log("ExStartEvents: " + ExStartEvents); + bool ExStartResult = ExStartEvents >= 10; + + return ExStartResult ? 100 : -1; + }; + }; } } From 07721f68390f0a069802942434bc217ce84bc963 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Thu, 6 Jul 2023 03:22:13 -0700 Subject: [PATCH 22/22] FB --- .../eventpipe/providervalidation/providervalidation.cs | 2 +- .../simpleruntimeeventvalidation.cs | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs b/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs index d51df1f34c8d3..1f061e8456b24 100644 --- a/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs +++ b/src/tests/tracing/eventpipe/providervalidation/providervalidation.cs @@ -38,7 +38,7 @@ public static int Main() bool enableRundown = TestLibrary.Utilities.IsNativeAot? false: true; Dictionary _expectedEventCounts = TestLibrary.Utilities.IsNativeAot? _expectedEventCountsNativeAOT: _expectedEventCountsCoreCLR; - var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, enableRundownProvider:enableRundown); + var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, enableRundownProvider: enableRundown); if (ret < 0) return ret; else diff --git a/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs index 6272649d06885..6a851e23385af 100644 --- a/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs +++ b/src/tests/tracing/eventpipe/simpleruntimeeventvalidation/simpleruntimeeventvalidation.cs @@ -27,16 +27,10 @@ public static int Main() new List(){new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1)}, 1024, _DoesTraceContainGCEvents, enableRundownProvider:false); - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - // Run the 2nd test scenario only if the first one passes if(ret== 100) { ret = IpcTraceTest.RunAndValidateEventCounts( - // Validate the exception type and message after the below issue is fixed. For now, check that the event is fired - // https://github.com/dotnet/runtime/issues/87978 new Dictionary(){{ "Microsoft-DotNETCore-EventPipe", 1 }}, _eventGeneratingActionForExceptions, //ExceptionKeyword (0x8000): 0b1000_0000_0000_0000