From 86ee71917ab6637ae05f65701ef0d10ee30d9fac Mon Sep 17 00:00:00 2001 From: David Mason Date: Thu, 2 Mar 2023 15:02:42 -0800 Subject: [PATCH 1/2] EventPipe env var to disable stack collection (#82470) --- src/coreclr/inc/clrconfigvalues.h | 1 + src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h | 9 +++++++++ src/mono/mono/eventpipe/ep-rt-mono.h | 15 +++++++++++++++ src/native/eventpipe/ep-buffer-manager.c | 2 +- src/native/eventpipe/ep-rt.h | 4 ++++ src/native/eventpipe/ep-session.c | 1 + src/native/eventpipe/ep-session.h | 3 +++ 7 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index ce7d1836a363e..5a9c3d60984bd 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -690,6 +690,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeRundown, W("EventPipeRundown"), 1, "E RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"), 1024, "The EventPipe circular buffer size in megabytes.") 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"), 0, "Enable/disable streaming for trace file set in COMPlus_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.") #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/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 620fe62f30268..7b6614e4423c0 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -1670,6 +1670,15 @@ ep_rt_config_value_get_use_portable_thread_pool (void) return ThreadpoolMgr::UsePortableThreadPool (); } +static +inline +bool +ep_rt_config_value_get_enable_stackwalk (void) +{ + STATIC_CONTRACT_NOTHROW; + return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeEnableStackwalk) != 0; +} + /* * EventPipeSampleProfiler. */ diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index dc07922690cce..73cce439bdc7f 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -1026,6 +1026,21 @@ ep_rt_config_value_get_rundown (void) return value_uint32_t; } +static +inline +bool +ep_rt_config_value_get_enable_stackwalk (void) +{ + uint32_t value_uint32_t = 1; + gchar *value = g_getenv ("DOTNET_EventPipeEnableStackwalk"); + if (!value) + value = g_getenv ("COMPlus_EventPipeEnableStackwalk"); + if (value) + value_uint32_t = (uint32_t)atoi (value); + g_free (value); + return value_uint32_t != 0; +} + /* * EventPipeSampleProfiler. */ diff --git a/src/native/eventpipe/ep-buffer-manager.c b/src/native/eventpipe/ep-buffer-manager.c index c1cb584a5d89c..7d5b54037b602 100644 --- a/src/native/eventpipe/ep-buffer-manager.c +++ b/src/native/eventpipe/ep-buffer-manager.c @@ -971,7 +971,7 @@ ep_buffer_manager_write_event ( event_thread = thread; current_stack_contents = ep_stack_contents_init (&stack_contents); - if (stack == NULL && ep_event_get_need_stack (ep_event) && !ep_session_get_rundown_enabled (session)) { + if (stack == NULL && ep_session_get_enable_stackwalk (session) && ep_event_get_need_stack (ep_event) && !ep_session_get_rundown_enabled (session)) { ep_walk_managed_stack_for_current_thread (current_stack_contents); stack = current_stack_contents; } diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 96ab9b9466380..0723c49f145cc 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -406,6 +406,10 @@ static bool ep_rt_config_value_get_use_portable_thread_pool (void); +inline +bool +ep_rt_config_value_get_enable_stackwalk (void); + /* * EventPipeSampleProfiler. */ diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 9a8c43b983416..7ef2c620130b1 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -206,6 +206,7 @@ ep_session_alloc ( instance->session_start_time = ep_system_timestamp_get (); instance->session_start_timestamp = ep_perf_timestamp_get (); instance->paused = false; + instance->enable_stackwalk = ep_rt_config_value_get_enable_stackwalk (); ep_on_exit: ep_requires_lock_held (); diff --git a/src/native/eventpipe/ep-session.h b/src/native/eventpipe/ep-session.h index a38adc4e73cc0..36879e2bbc8aa 100644 --- a/src/native/eventpipe/ep-session.h +++ b/src/native/eventpipe/ep-session.h @@ -59,6 +59,8 @@ struct _EventPipeSession_Internal { // we expect to remove it in the future once that limitation is resolved other scenarios are discouraged from using this given that // we plan to make it go away bool paused; + // Set via environment variable to enable or disable stack collection globally + bool enable_stackwalk; }; #if !defined(EP_INLINE_GETTER_SETTER) && !defined(EP_IMPL_SESSION_GETTER_SETTER) @@ -75,6 +77,7 @@ EP_DEFINE_GETTER(EventPipeSession *, session, bool, rundown_requested) EP_DEFINE_GETTER(EventPipeSession *, session, ep_timestamp_t, session_start_time) EP_DEFINE_GETTER(EventPipeSession *, session, ep_timestamp_t, session_start_timestamp) EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeFile *, file) +EP_DEFINE_GETTER(EventPipeSession *, session, bool, enable_stackwalk) EventPipeSession * ep_session_alloc ( From 5840f96dd5a6df9a6ee12cbf29a9ee9957b22d7f Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 3 Mar 2023 01:19:44 -0800 Subject: [PATCH 2/2] Add static to declaration --- src/native/eventpipe/ep-rt.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 0723c49f145cc..9d76dc7b17914 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -406,6 +406,7 @@ static bool ep_rt_config_value_get_use_portable_thread_pool (void); +static inline bool ep_rt_config_value_get_enable_stackwalk (void);