From 6363c47af81032dff501c8778dd6d69b8d540ea1 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 22 Apr 2026 19:51:35 +0200 Subject: [PATCH 1/9] DOTNET_EventPipeCpuSamplingRate --- src/coreclr/inc/clrconfigvalues.h | 1 + .../nativeaot/Runtime/eventpipe/ep-rt-aot.h | 17 +++++++++++++++++ .../vm/eventing/eventpipe/ep-rt-coreclr.h | 18 +++++++++++++----- src/mono/mono/eventpipe/ep-rt-mono.h | 13 +++++++++++++ ...crosoft.NET.Sdk.WebAssembly.Browser.targets | 11 ++++++++++- src/native/eventpipe/ds-ipc-pal-websocket.h | 8 +++++++- src/native/eventpipe/ep-rt.h | 5 +++++ src/native/eventpipe/ep-session.c | 1 + src/native/eventpipe/ep.c | 8 +++++++- 9 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index 7e280e3e059be6..23373591e9ea8e 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -610,6 +610,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"), RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"), 0, "Enable/disable capturing processor numbers in EventPipe event headers") RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeOutputStreaming, W("EventPipeOutputStreaming"), 1, "Enable/disable streaming for trace file set in DOTNET_EventPipeOutputPath. Non-zero values enable streaming.") RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeEnableStackwalk, W("EventPipeEnableStackwalk"), 1, "Set to 0 to disable collecting stacks for EventPipe events.") +RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCpuSamplingRate, W("EventPipeCpuSamplingRate"), 0, "Desired sample interval in milliseconds for EventPipe CPU sampling profiler. 0 means use the default.") #ifdef FEATURE_AUTO_TRACE RETAIL_CONFIG_DWORD_INFO_EX(INTERNAL_AutoTrace_N_Tracers, W("AutoTrace_N_Tracers"), 0, "", CLRConfig::LookupOptions::ParseIntegerAsBase10) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index 78d6578dce29c8..9939965bfd3beb 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -507,6 +507,23 @@ ep_rt_config_value_get_enable_stackwalk (void) return false; } +static +inline +uint32_t +ep_rt_config_value_get_sampling_rate (void) +{ + STATIC_CONTRACT_NOTHROW; + + uint64_t value; + if (RhConfig::Environment::TryGetIntegerValue("EventPipeCpuSamplingRate", &value, true)) + { + EP_ASSERT(value <= UINT32_MAX); + return static_cast(value); + } + + return 0; +} + /* * EventPipeSampleProfiler. */ diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 97991823eaff97..8f148f01767546 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -444,9 +444,9 @@ ep_rt_provider_config_init (EventPipeProviderConfiguration *provider_config) // This function is auto-generated from /src/scripts/genEventPipe.py #ifdef TARGET_UNIX extern "C" void InitProvidersAndEvents (); -#else +#else // TARGET_UNIX extern void InitProvidersAndEvents (); -#endif +#endif // TARGET_UNIX static void @@ -572,6 +572,15 @@ ep_rt_config_value_get_enable_stackwalk (void) return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeEnableStackwalk) != 0; } +static +inline +uint32_t +ep_rt_config_value_get_sampling_rate (void) +{ + STATIC_CONTRACT_NOTHROW; + return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeCpuSamplingRate); +} + /* * EventPipeSampleProfiler. */ @@ -622,13 +631,12 @@ void ep_rt_notify_profiler_provider_created (EventPipeProvider *provider) { STATIC_CONTRACT_NOTHROW; - -#ifndef DACCESS_COMPILE +#if !defined(DACCESS_COMPILE) && defined(PROFILING_SUPPORTED) // Let the profiler know the provider has been created so it can register if it wants to BEGIN_PROFILER_CALLBACK (CORProfilerTrackEventPipe ()); (&g_profControlBlock)->EventPipeProviderCreated (provider); END_PROFILER_CALLBACK (); -#endif // DACCESS_COMPILE +#endif // !DACCESS_COMPILE && PROFILING_SUPPORTED } /* diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index ce5c7f7e95af96..89c796af904140 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -637,6 +637,19 @@ ep_rt_config_value_get_enable_stackwalk (void) return value_uint32_t != 0; } +static +inline +uint32_t +ep_rt_config_value_get_sampling_rate (void) +{ + uint32_t value_uint32_t = 0; + gchar *value = g_getenv ("DOTNET_EventPipeCpuSamplingRate"); + if (value) + value_uint32_t = (uint32_t)atoi (value); + g_free (value); + return value_uint32_t; +} + /* * EventPipeSampleProfiler. */ diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index bd63688adeed59..627cf7481f5116 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -477,9 +477,18 @@ Copyright (c) .NET Foundation. All rights reserved. - + + + <_WasmPerfInstFilter>$(WasmPerformanceInstrumentation) + <_WasmPerfInstInterval> + <_WasmPerfInstInterval Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring($([MSBuild]::Add($(WasmPerformanceInstrumentation.IndexOf(',interval=')), 10)))) + <_WasmPerfInstFilter Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring(0, $(WasmPerformanceInstrumentation.IndexOf(',interval=')))) + <_WasmPerfInstInterval Condition="'$(_WasmPerfInstInterval)' != '' and $(_WasmPerfInstInterval.Contains(','))">$(_WasmPerfInstInterval.Substring(0, $(_WasmPerfInstInterval.IndexOf(',')))) + + + diff --git a/src/native/eventpipe/ds-ipc-pal-websocket.h b/src/native/eventpipe/ds-ipc-pal-websocket.h index 1273d9367c9d41..9b948ab89ed4db 100644 --- a/src/native/eventpipe/ds-ipc-pal-websocket.h +++ b/src/native/eventpipe/ds-ipc-pal-websocket.h @@ -53,11 +53,17 @@ struct _DiagnosticsIpcStream { }; #endif +#ifdef __cplusplus +extern "C" { +#endif extern int ds_rt_websocket_poll (int client_socket); extern int ds_rt_websocket_create (const char* url); -extern int ds_rt_websocket_recv (int client_socket, const uint8_t* buffer, uint32_t bytes_to_read); +extern int ds_rt_websocket_recv (int client_socket, uint8_t* buffer, uint32_t bytes_to_read); extern int ds_rt_websocket_send (int client_socket, const uint8_t* buffer, uint32_t bytes_to_write); extern int ds_rt_websocket_close(int client_socket); +#ifdef __cplusplus +} +#endif #endif /* ENABLE_PERFTRACING */ #endif /* __DIAGNOSTICS_IPC_PAL_WEB_SOCKET_H__ */ diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index ef28cb5147240c..d3cc68db3ffded 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -200,6 +200,11 @@ inline bool ep_rt_config_value_get_enable_stackwalk (void); +static +inline +uint32_t +ep_rt_config_value_get_sampling_rate (void); + /* * EventPipeSampleProfiler. */ diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 19ff91952ce31e..7036d087ceb54f 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -156,6 +156,7 @@ static size_t streaming_loop_tick(EventPipeSession *const session) { bool events_written = false; bool ok; if (!ep_session_get_streaming_enabled (session)){ + EP_ASSERT (session->buffer_manager != NULL); session->streaming_thread = NULL; ep_session_dec_ref (session); return 1; // done diff --git a/src/native/eventpipe/ep.c b/src/native/eventpipe/ep.c index 0b45cf280d3fdc..5336982ae774b1 100644 --- a/src/native/eventpipe/ep.c +++ b/src/native/eventpipe/ep.c @@ -1496,7 +1496,13 @@ ep_init (void) #else // PERFTRACING_DISABLE_THREADS const uint32_t default_profiler_sample_rate_in_nanoseconds = 5000000; // 5 msec. #endif // PERFTRACING_DISABLE_THREADS - ep_sample_profiler_set_sampling_rate (default_profiler_sample_rate_in_nanoseconds); + + // Allow overriding the sampling rate via DOTNET_EventPipeCpuSamplingRate (in milliseconds). + uint32_t configured_rate_ms = ep_rt_config_value_get_sampling_rate (); + if (configured_rate_ms > 0) + ep_sample_profiler_set_sampling_rate ((uint64_t)configured_rate_ms * 1000000); + else + ep_sample_profiler_set_sampling_rate (default_profiler_sample_rate_in_nanoseconds); _ep_deferred_enable_session_ids = dn_vector_alloc_t (EventPipeSessionID); _ep_deferred_disable_session_ids = dn_vector_alloc_t (EventPipeSessionID); From 6c03fdccaef55b7e7afe5d025fc34c93b5a1e378 Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Wed, 22 Apr 2026 20:31:12 +0200 Subject: [PATCH 2/9] Update src/native/eventpipe/ep-session.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/native/eventpipe/ep-session.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 7036d087ceb54f..14888e03246d67 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -156,7 +156,8 @@ static size_t streaming_loop_tick(EventPipeSession *const session) { bool events_written = false; bool ok; if (!ep_session_get_streaming_enabled (session)){ - EP_ASSERT (session->buffer_manager != NULL); + if (ep_session_type_uses_buffer_manager (session->session_type)) + EP_ASSERT (session->buffer_manager != NULL); session->streaming_thread = NULL; ep_session_dec_ref (session); return 1; // done From 9a89ca58aee03a9c8f2bb33dd6e6dcdaa8bad3cf Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Wed, 22 Apr 2026 20:31:32 +0200 Subject: [PATCH 3/9] Update src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 627cf7481f5116..235f0833953802 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -481,13 +481,15 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmPerfInstFilter>$(WasmPerformanceInstrumentation) <_WasmPerfInstInterval> + <_WasmPerfInstDescriptor> <_WasmPerfInstInterval Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring($([MSBuild]::Add($(WasmPerformanceInstrumentation.IndexOf(',interval=')), 10)))) <_WasmPerfInstFilter Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring(0, $(WasmPerformanceInstrumentation.IndexOf(',interval=')))) <_WasmPerfInstInterval Condition="'$(_WasmPerfInstInterval)' != '' and $(_WasmPerfInstInterval.Contains(','))">$(_WasmPerfInstInterval.Substring(0, $(_WasmPerfInstInterval.IndexOf(',')))) + <_WasmPerfInstDescriptor Condition="'$(_WasmPerfInstFilter)' != ''">eventpipe,callspec=$(_WasmPerfInstFilter) - + From 53cf0688c35c070ef7bc44dda69ce96aa7796685 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Wed, 22 Apr 2026 20:42:25 +0200 Subject: [PATCH 4/9] fix --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 235f0833953802..ceeef77fd25d1b 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -204,7 +204,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmEnableWebcil Condition="'$(_TargetingNET80OrLater)' != 'true'">false <_WasmEnableWebcil Condition="'$(_WasmEnableWebcil)' == ''">true <_WasmWebcilVersion Condition="'$(_WasmWebcilVersion)' == ''">$(WasmWebcilVersion) - <_WasmWebcilVersion Condition="'$(_WasmWebcilVersion)' == '' and '$(RuntimeFlavor)' == 'CoreCLR'">1 + <_WasmWebcilVersion Condition="'$(_WasmWebcilVersion)' == '' and '$(UseMonoRuntime)' == 'false'">1 <_WasmWebcilVersion Condition="'$(_WasmWebcilVersion)' == ''">0 <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) @@ -485,7 +485,9 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmPerfInstInterval Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring($([MSBuild]::Add($(WasmPerformanceInstrumentation.IndexOf(',interval=')), 10)))) <_WasmPerfInstFilter Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring(0, $(WasmPerformanceInstrumentation.IndexOf(',interval=')))) <_WasmPerfInstInterval Condition="'$(_WasmPerfInstInterval)' != '' and $(_WasmPerfInstInterval.Contains(','))">$(_WasmPerfInstInterval.Substring(0, $(_WasmPerfInstInterval.IndexOf(',')))) - <_WasmPerfInstDescriptor Condition="'$(_WasmPerfInstFilter)' != ''">eventpipe,callspec=$(_WasmPerfInstFilter) + <_WasmPerfInstDescriptor Condition="'$(_WasmPerfInstFilter)' != '' and '$(UseMonoRuntime)' != 'false'">eventpipe,callspec=$(_WasmPerfInstFilter) + <_WasmPerfInstFilter Condition="'$(_WasmPerfInstFilter)' == 'all' and '$(UseMonoRuntime)' == 'false'">* + <_WasmPerfInstDescriptor Condition="'$(_WasmPerfInstFilter)' != '' and '$(UseMonoRuntime)' == 'false'">$(_WasmPerfInstFilter) From 77d3a9923838329fbd468e7329b03e97146a5246 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 24 Apr 2026 11:19:19 +0200 Subject: [PATCH 5/9] feedback --- src/mono/browser/build/WasmApp.InTree.props | 6 +++++- src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c | 2 -- src/native/eventpipe/ep-session.c | 2 -- src/native/eventpipe/ep.c | 3 +++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/mono/browser/build/WasmApp.InTree.props b/src/mono/browser/build/WasmApp.InTree.props index d097d45119197d..9031c6f6d0cc25 100644 --- a/src/mono/browser/build/WasmApp.InTree.props +++ b/src/mono/browser/build/WasmApp.InTree.props @@ -14,10 +14,14 @@ - + false + false + + true + library diff --git a/src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c b/src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c index 2fff49357e844c..5503c2c0b9eebf 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c +++ b/src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c @@ -1507,8 +1507,6 @@ void ep_rt_mono_sample_profiler_enabled (EventPipeEvent *sampling_event) { desired_sample_interval_ms = ((double)ep_sample_profiler_get_sampling_rate ()) / 1000000.0; - EP_ASSERT (desired_sample_interval_ms >= 0.0); - EP_ASSERT (desired_sample_interval_ms < 1000.0); current_sampling_event = sampling_event; current_sampling_thread = ep_rt_thread_get_handle (); diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 14888e03246d67..19ff91952ce31e 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -156,8 +156,6 @@ static size_t streaming_loop_tick(EventPipeSession *const session) { bool events_written = false; bool ok; if (!ep_session_get_streaming_enabled (session)){ - if (ep_session_type_uses_buffer_manager (session->session_type)) - EP_ASSERT (session->buffer_manager != NULL); session->streaming_thread = NULL; ep_session_dec_ref (session); return 1; // done diff --git a/src/native/eventpipe/ep.c b/src/native/eventpipe/ep.c index 5336982ae774b1..e606daf2afe1da 100644 --- a/src/native/eventpipe/ep.c +++ b/src/native/eventpipe/ep.c @@ -1499,6 +1499,9 @@ ep_init (void) // Allow overriding the sampling rate via DOTNET_EventPipeCpuSamplingRate (in milliseconds). uint32_t configured_rate_ms = ep_rt_config_value_get_sampling_rate (); + EP_ASSERT (configured_rate_ms >= 0); + EP_ASSERT (configured_rate_ms < 1000); + if (configured_rate_ms > 0) ep_sample_profiler_set_sampling_rate ((uint64_t)configured_rate_ms * 1000000); else From 7297326b07e900966d5df13b567727afb227e301 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Fri, 24 Apr 2026 14:44:33 +0200 Subject: [PATCH 6/9] feedback --- src/native/eventpipe/ep.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/native/eventpipe/ep.c b/src/native/eventpipe/ep.c index e606daf2afe1da..4626cc112e96e3 100644 --- a/src/native/eventpipe/ep.c +++ b/src/native/eventpipe/ep.c @@ -1499,11 +1499,10 @@ ep_init (void) // Allow overriding the sampling rate via DOTNET_EventPipeCpuSamplingRate (in milliseconds). uint32_t configured_rate_ms = ep_rt_config_value_get_sampling_rate (); - EP_ASSERT (configured_rate_ms >= 0); - EP_ASSERT (configured_rate_ms < 1000); - - if (configured_rate_ms > 0) + if (configured_rate_ms > 0) { + if (configured_rate_ms > 1000) configured_rate_ms = 1000; ep_sample_profiler_set_sampling_rate ((uint64_t)configured_rate_ms * 1000000); + } else ep_sample_profiler_set_sampling_rate (default_profiler_sample_rate_in_nanoseconds); From 6e9b7803db9b3b333148c6638eb8c8f46d828299 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 27 Apr 2026 15:11:39 +0200 Subject: [PATCH 7/9] feedback --- src/native/eventpipe/ep.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/native/eventpipe/ep.c b/src/native/eventpipe/ep.c index 4626cc112e96e3..5336982ae774b1 100644 --- a/src/native/eventpipe/ep.c +++ b/src/native/eventpipe/ep.c @@ -1499,10 +1499,8 @@ ep_init (void) // Allow overriding the sampling rate via DOTNET_EventPipeCpuSamplingRate (in milliseconds). uint32_t configured_rate_ms = ep_rt_config_value_get_sampling_rate (); - if (configured_rate_ms > 0) { - if (configured_rate_ms > 1000) configured_rate_ms = 1000; + if (configured_rate_ms > 0) ep_sample_profiler_set_sampling_rate ((uint64_t)configured_rate_ms * 1000000); - } else ep_sample_profiler_set_sampling_rate (default_profiler_sample_rate_in_nanoseconds); From ffb89e53bef5e4cc0221e55df3bd9ea68a468e4c Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Mon, 27 Apr 2026 19:44:05 +0200 Subject: [PATCH 8/9] feedback --- src/coreclr/inc/clrconfigvalues.h | 2 +- src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h | 2 +- src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | 2 +- src/mono/mono/eventpipe/ep-rt-mono.h | 12 +++++++++--- .../Microsoft.NET.Sdk.WebAssembly.Browser.targets | 2 +- src/native/eventpipe/ep.c | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index 23373591e9ea8e..7767eb65a9b9c4 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -610,7 +610,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"), RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"), 0, "Enable/disable capturing processor numbers in EventPipe event headers") RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeOutputStreaming, W("EventPipeOutputStreaming"), 1, "Enable/disable streaming for trace file set in DOTNET_EventPipeOutputPath. Non-zero values enable streaming.") RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeEnableStackwalk, W("EventPipeEnableStackwalk"), 1, "Set to 0 to disable collecting stacks for EventPipe events.") -RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCpuSamplingRate, W("EventPipeCpuSamplingRate"), 0, "Desired sample interval in milliseconds for EventPipe CPU sampling profiler. 0 means use the default.") +RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeThreadSamplingRate, W("EventPipeThreadSamplingRate"), 0, "Desired sample interval in milliseconds for EventPipe thread time sampling profiler. 0 means use the default.") #ifdef FEATURE_AUTO_TRACE RETAIL_CONFIG_DWORD_INFO_EX(INTERNAL_AutoTrace_N_Tracers, W("AutoTrace_N_Tracers"), 0, "", CLRConfig::LookupOptions::ParseIntegerAsBase10) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index 9939965bfd3beb..c9ae8dcbd80c8e 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -515,7 +515,7 @@ ep_rt_config_value_get_sampling_rate (void) STATIC_CONTRACT_NOTHROW; uint64_t value; - if (RhConfig::Environment::TryGetIntegerValue("EventPipeCpuSamplingRate", &value, true)) + if (RhConfig::Environment::TryGetIntegerValue("EventPipeThreadSamplingRate", &value, true)) { EP_ASSERT(value <= UINT32_MAX); return static_cast(value); diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 8f148f01767546..ebb46b8eb5396c 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -578,7 +578,7 @@ uint32_t ep_rt_config_value_get_sampling_rate (void) { STATIC_CONTRACT_NOTHROW; - return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeCpuSamplingRate); + return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeThreadSamplingRate); } /* diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 89c796af904140..e84b25d1a0a11c 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -643,9 +643,15 @@ uint32_t ep_rt_config_value_get_sampling_rate (void) { uint32_t value_uint32_t = 0; - gchar *value = g_getenv ("DOTNET_EventPipeCpuSamplingRate"); - if (value) - value_uint32_t = (uint32_t)atoi (value); + gchar *value = g_getenv ("DOTNET_EventPipeThreadSamplingRate"); + if (!value) + value = g_getenv ("COMPlus_EventPipeThreadSamplingRate"); + if (value) { + gchar *endptr = NULL; + guint64 parsed = g_ascii_strtoull (value, &endptr, 10); + if (endptr != value && *endptr == '\0' && value [0] != '-' && parsed <= G_MAXUINT32) + value_uint32_t = (uint32_t)parsed; + } g_free (value); return value_uint32_t; } diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 9578437c5eb42e..6442c23e87d1ac 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -497,7 +497,7 @@ Copyright (c) .NET Foundation. All rights reserved. - + diff --git a/src/native/eventpipe/ep.c b/src/native/eventpipe/ep.c index 5336982ae774b1..9cf4acff6bdfed 100644 --- a/src/native/eventpipe/ep.c +++ b/src/native/eventpipe/ep.c @@ -1497,7 +1497,7 @@ ep_init (void) const uint32_t default_profiler_sample_rate_in_nanoseconds = 5000000; // 5 msec. #endif // PERFTRACING_DISABLE_THREADS - // Allow overriding the sampling rate via DOTNET_EventPipeCpuSamplingRate (in milliseconds). + // Allow overriding the sampling rate via DOTNET_EventPipeThreadSamplingRate (in milliseconds). uint32_t configured_rate_ms = ep_rt_config_value_get_sampling_rate (); if (configured_rate_ms > 0) ep_sample_profiler_set_sampling_rate ((uint64_t)configured_rate_ms * 1000000); From 25cc16d004e3278059f5fb950963bfec3cb9ca55 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 28 Apr 2026 18:16:26 +0200 Subject: [PATCH 9/9] fix --- src/mono/mono/eventpipe/ep-rt-mono.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index e84b25d1a0a11c..a5f3c2626509ed 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -648,7 +648,7 @@ ep_rt_config_value_get_sampling_rate (void) value = g_getenv ("COMPlus_EventPipeThreadSamplingRate"); if (value) { gchar *endptr = NULL; - guint64 parsed = g_ascii_strtoull (value, &endptr, 10); + guint64 parsed = strtoull (value, &endptr, 10); if (endptr != value && *endptr == '\0' && value [0] != '-' && parsed <= G_MAXUINT32) value_uint32_t = (uint32_t)parsed; }