From 2a32f5154665137b9da95c0a3d2276cb744b6e10 Mon Sep 17 00:00:00 2001 From: David Mason Date: Wed, 30 Aug 2023 00:22:04 -0700 Subject: [PATCH 01/10] add rundown check --- src/native/eventpipe/ep-session.c | 6 ++++++ src/native/eventpipe/ep-session.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 959214d137596..dc7500deacf3c 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -348,6 +348,7 @@ ep_session_enable_rundown (EventPipeSession *session) ep_raise_error_if_nok (ep_session_add_session_provider (session, session_provider)); } + ep_session_set_rundown_thread_id (session, ep_thread_get_os_thread_id (ep_thread_get ())); ep_session_set_rundown_enabled (session, true); result = true; @@ -521,6 +522,11 @@ ep_session_write_event ( // Filter events specific to "this" session based on precomputed flag on provider/events. if (ep_event_is_enabled_by_mask (ep_event, ep_session_get_mask (session))) { + if (ep_session_get_rundown_enabled (session) && (ep_session_get_rundown_thread_id (session) != ep_thread_get_os_thread_id (ep_thread_get ()))) { + EP_ASSERT (ep_session_get_rundown_thread_id (session) != 0); + return false; + } + if (session->synchronous_callback) { session->synchronous_callback ( ep_event_get_provider (ep_event), diff --git a/src/native/eventpipe/ep-session.h b/src/native/eventpipe/ep-session.h index 6b26dc055e092..2a5dfec3b5288 100644 --- a/src/native/eventpipe/ep-session.h +++ b/src/native/eventpipe/ep-session.h @@ -44,6 +44,8 @@ struct _EventPipeSession_Internal { uint32_t index; // True if rundown is enabled. volatile uint32_t rundown_enabled; + // ID of the thread performing rundown. Used to filter non rundown events + uint64_t rundown_thread_id; // Data members used when an streaming thread is used. volatile uint32_t streaming_enabled; // The type of the session. @@ -75,6 +77,8 @@ EP_DEFINE_GETTER(EventPipeSession *, session, uint32_t, index) EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeSessionProviderList *, providers) EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeBufferManager *, buffer_manager) EP_DEFINE_GETTER_REF(EventPipeSession *, session, volatile uint32_t *, rundown_enabled) +EP_DEFINE_GETTER(EventPipeSession *, session, uint64_t, rundown_thread_id) +EP_DEFINE_SETTER(EventPipeSession *, session, uint64_t, rundown_thread_id) 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) From 6d7d21fb8ad5872b3343dcc9f84de4a2795deaa0 Mon Sep 17 00:00:00 2001 From: David Mason Date: Thu, 31 Aug 2023 02:14:24 -0700 Subject: [PATCH 02/10] Update ep-session.c --- src/native/eventpipe/ep-session.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index dc7500deacf3c..3cabf0eaf7bf7 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -164,6 +164,7 @@ ep_session_alloc ( instance->session_type = session_type; instance->format = format; instance->rundown_requested = rundown_requested; + instance->rundown_thread_id = 0; instance->synchronous_callback = sync_callback; instance->callback_additional_data = callback_additional_data; From afffac4f66ed7f52a65a929ae1ac2e939f5667bb Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 1 Sep 2023 01:18:09 -0700 Subject: [PATCH 03/10] Check for rundown provider --- src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h | 2 ++ src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h | 2 ++ src/mono/mono/eventpipe/ep-rt-types-mono.h | 2 ++ src/native/eventpipe/ep-session.c | 5 +++++ 4 files changed, 11 insertions(+) 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 82ca6a7cbbd11..29d01dbca71bc 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h @@ -27,6 +27,8 @@ #define EP_ASSERT(expr) #endif +#define EP_FAILFAST(msg) + #undef EP_UNREACHABLE #define EP_UNREACHABLE(msg) do { UNREACHABLE_MSG(msg); } while (0) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h index 9661e9a4ae2c3..5d73c88c9ff1d 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h @@ -20,6 +20,8 @@ #define EP_ASSERT(expr) #endif +#define EP_FAILFAST(msg) EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_FAILFAST, msg) + #undef EP_UNREACHABLE #define EP_UNREACHABLE(msg) do { UNREACHABLE_MSG(msg); } while (0) diff --git a/src/mono/mono/eventpipe/ep-rt-types-mono.h b/src/mono/mono/eventpipe/ep-rt-types-mono.h index 129d3d509eadb..6636ff45c60f1 100644 --- a/src/mono/mono/eventpipe/ep-rt-types-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-types-mono.h @@ -29,6 +29,8 @@ #undef EP_UNLIKELY #define EP_UNLIKELY(expr) G_UNLIKELY(expr) +#define EP_FAILFAST(msg) + struct _rt_mono_event_internal_t { gpointer event; }; diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 3cabf0eaf7bf7..c2dfe330f0fcd 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -525,6 +525,11 @@ ep_session_write_event ( if (ep_event_is_enabled_by_mask (ep_event, ep_session_get_mask (session))) { if (ep_session_get_rundown_enabled (session) && (ep_session_get_rundown_thread_id (session) != ep_thread_get_os_thread_id (ep_thread_get ()))) { EP_ASSERT (ep_session_get_rundown_thread_id (session) != 0); + EventPipeProvider *provider = ep_event_get_provider (ep_event); + const ep_char8_t *provider_name = ep_provider_get_provider_name(provider); + if (ep_rt_utf8_string_compare_ignore_case (provider_name, "Microsoft-Windows-DotNETRuntimeRundown") != 0) { + EP_FAILFAST(L"Saw non rundown provider"); + } return false; } From 31944a8bf9a67a0ab3ba8ad4d6b19e8ec72f32a1 Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 1 Sep 2023 01:20:47 -0700 Subject: [PATCH 04/10] Fix --- src/native/eventpipe/ep-session.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index c2dfe330f0fcd..6dd0dc1e73a24 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -525,12 +525,15 @@ ep_session_write_event ( if (ep_event_is_enabled_by_mask (ep_event, ep_session_get_mask (session))) { if (ep_session_get_rundown_enabled (session) && (ep_session_get_rundown_thread_id (session) != ep_thread_get_os_thread_id (ep_thread_get ()))) { EP_ASSERT (ep_session_get_rundown_thread_id (session) != 0); + return false; + } + + if (ep_session_get_rundown_enabled (session) && (ep_session_get_rundown_thread_id (session) == ep_thread_get_os_thread_id (ep_thread_get ()))) { EventPipeProvider *provider = ep_event_get_provider (ep_event); const ep_char8_t *provider_name = ep_provider_get_provider_name(provider); if (ep_rt_utf8_string_compare_ignore_case (provider_name, "Microsoft-Windows-DotNETRuntimeRundown") != 0) { EP_FAILFAST(L"Saw non rundown provider"); } - return false; } if (session->synchronous_callback) { From 86341bb428b0232bde8e52fbb6f789c50781be32 Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 1 Sep 2023 09:05:23 -0700 Subject: [PATCH 05/10] Update src/mono/mono/eventpipe/ep-rt-types-mono.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aleksey Kliger (λgeek) --- src/mono/mono/eventpipe/ep-rt-types-mono.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/eventpipe/ep-rt-types-mono.h b/src/mono/mono/eventpipe/ep-rt-types-mono.h index 6636ff45c60f1..7c3e3baa07208 100644 --- a/src/mono/mono/eventpipe/ep-rt-types-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-types-mono.h @@ -29,7 +29,7 @@ #undef EP_UNLIKELY #define EP_UNLIKELY(expr) G_UNLIKELY(expr) -#define EP_FAILFAST(msg) +#define EP_FAILFAST(msg) g_error(msg) struct _rt_mono_event_internal_t { gpointer event; From 4697860785a614c5ca85ce5a61c056eb692a4116 Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 1 Sep 2023 09:14:11 -0700 Subject: [PATCH 06/10] Fix cross plat build --- src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h | 7 ++++++- src/native/eventpipe/ep-session.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h index 5d73c88c9ff1d..9878a00ed5cfa 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h @@ -20,7 +20,12 @@ #define EP_ASSERT(expr) #endif -#define EP_FAILFAST(msg) EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_FAILFAST, msg) +#define EP_FAILFAST(msg) \ + do \ + { \ + SString converter(SString::Literal, msg); \ + EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_FAILFAST, converter.GetUnicode()); \ + } while(FALSE) #undef EP_UNREACHABLE #define EP_UNREACHABLE(msg) do { UNREACHABLE_MSG(msg); } while (0) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 6dd0dc1e73a24..3c6284471d12c 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -532,7 +532,7 @@ ep_session_write_event ( EventPipeProvider *provider = ep_event_get_provider (ep_event); const ep_char8_t *provider_name = ep_provider_get_provider_name(provider); if (ep_rt_utf8_string_compare_ignore_case (provider_name, "Microsoft-Windows-DotNETRuntimeRundown") != 0) { - EP_FAILFAST(L"Saw non rundown provider"); + EP_FAILFAST("Saw non rundown provider"); } } From 91cffc3885f977bbdb21a56615ffc69ea185efee Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 8 Sep 2023 14:42:28 -0700 Subject: [PATCH 07/10] Revert previous changes --- .../nativeaot/Runtime/eventpipe/ep-rt-types-aot.h | 2 -- src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h | 7 ------- src/mono/mono/eventpipe/ep-rt-types-mono.h | 2 -- src/native/eventpipe/ep-session.c | 9 --------- 4 files changed, 20 deletions(-) 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 29d01dbca71bc..82ca6a7cbbd11 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h @@ -27,8 +27,6 @@ #define EP_ASSERT(expr) #endif -#define EP_FAILFAST(msg) - #undef EP_UNREACHABLE #define EP_UNREACHABLE(msg) do { UNREACHABLE_MSG(msg); } while (0) diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h index 9878a00ed5cfa..9661e9a4ae2c3 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-types-coreclr.h @@ -20,13 +20,6 @@ #define EP_ASSERT(expr) #endif -#define EP_FAILFAST(msg) \ - do \ - { \ - SString converter(SString::Literal, msg); \ - EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_FAILFAST, converter.GetUnicode()); \ - } while(FALSE) - #undef EP_UNREACHABLE #define EP_UNREACHABLE(msg) do { UNREACHABLE_MSG(msg); } while (0) diff --git a/src/mono/mono/eventpipe/ep-rt-types-mono.h b/src/mono/mono/eventpipe/ep-rt-types-mono.h index 7c3e3baa07208..129d3d509eadb 100644 --- a/src/mono/mono/eventpipe/ep-rt-types-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-types-mono.h @@ -29,8 +29,6 @@ #undef EP_UNLIKELY #define EP_UNLIKELY(expr) G_UNLIKELY(expr) -#define EP_FAILFAST(msg) g_error(msg) - struct _rt_mono_event_internal_t { gpointer event; }; diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 3c6284471d12c..dc7500deacf3c 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -164,7 +164,6 @@ ep_session_alloc ( instance->session_type = session_type; instance->format = format; instance->rundown_requested = rundown_requested; - instance->rundown_thread_id = 0; instance->synchronous_callback = sync_callback; instance->callback_additional_data = callback_additional_data; @@ -528,14 +527,6 @@ ep_session_write_event ( return false; } - if (ep_session_get_rundown_enabled (session) && (ep_session_get_rundown_thread_id (session) == ep_thread_get_os_thread_id (ep_thread_get ()))) { - EventPipeProvider *provider = ep_event_get_provider (ep_event); - const ep_char8_t *provider_name = ep_provider_get_provider_name(provider); - if (ep_rt_utf8_string_compare_ignore_case (provider_name, "Microsoft-Windows-DotNETRuntimeRundown") != 0) { - EP_FAILFAST("Saw non rundown provider"); - } - } - if (session->synchronous_callback) { session->synchronous_callback ( ep_event_get_provider (ep_event), From 8b35065e126a6e34e33ba6b3880c04267a6a932f Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 8 Sep 2023 14:44:57 -0700 Subject: [PATCH 08/10] Remove public provider from rundown session --- src/native/eventpipe/ep-session.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index dc7500deacf3c..d39728b5ccf23 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -332,7 +332,6 @@ ep_session_enable_rundown (EventPipeSession *session) EventPipeProviderConfiguration rundown_providers [2]; uint32_t rundown_providers_len = (uint32_t)ARRAY_SIZE (rundown_providers); - ep_provider_config_init (&rundown_providers [0], ep_config_get_public_provider_name_utf8 (), keywords, verbose_logging_level, NULL); // Public provider. ep_provider_config_init (&rundown_providers [1], ep_config_get_rundown_provider_name_utf8 (), keywords, verbose_logging_level, NULL); // Rundown provider. // Update provider list with rundown configuration. From fdbe005678f6115cccc40d2cdc78684912436bca Mon Sep 17 00:00:00 2001 From: David Mason Date: Fri, 8 Sep 2023 14:47:10 -0700 Subject: [PATCH 09/10] Finish reverting --- src/native/eventpipe/ep-session.c | 6 ------ src/native/eventpipe/ep-session.h | 4 ---- 2 files changed, 10 deletions(-) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index d39728b5ccf23..4dd7cc0b0120c 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -347,7 +347,6 @@ ep_session_enable_rundown (EventPipeSession *session) ep_raise_error_if_nok (ep_session_add_session_provider (session, session_provider)); } - ep_session_set_rundown_thread_id (session, ep_thread_get_os_thread_id (ep_thread_get ())); ep_session_set_rundown_enabled (session, true); result = true; @@ -521,11 +520,6 @@ ep_session_write_event ( // Filter events specific to "this" session based on precomputed flag on provider/events. if (ep_event_is_enabled_by_mask (ep_event, ep_session_get_mask (session))) { - if (ep_session_get_rundown_enabled (session) && (ep_session_get_rundown_thread_id (session) != ep_thread_get_os_thread_id (ep_thread_get ()))) { - EP_ASSERT (ep_session_get_rundown_thread_id (session) != 0); - return false; - } - if (session->synchronous_callback) { session->synchronous_callback ( ep_event_get_provider (ep_event), diff --git a/src/native/eventpipe/ep-session.h b/src/native/eventpipe/ep-session.h index 2a5dfec3b5288..6b26dc055e092 100644 --- a/src/native/eventpipe/ep-session.h +++ b/src/native/eventpipe/ep-session.h @@ -44,8 +44,6 @@ struct _EventPipeSession_Internal { uint32_t index; // True if rundown is enabled. volatile uint32_t rundown_enabled; - // ID of the thread performing rundown. Used to filter non rundown events - uint64_t rundown_thread_id; // Data members used when an streaming thread is used. volatile uint32_t streaming_enabled; // The type of the session. @@ -77,8 +75,6 @@ EP_DEFINE_GETTER(EventPipeSession *, session, uint32_t, index) EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeSessionProviderList *, providers) EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeBufferManager *, buffer_manager) EP_DEFINE_GETTER_REF(EventPipeSession *, session, volatile uint32_t *, rundown_enabled) -EP_DEFINE_GETTER(EventPipeSession *, session, uint64_t, rundown_thread_id) -EP_DEFINE_SETTER(EventPipeSession *, session, uint64_t, rundown_thread_id) 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) From 7a848ea8294be4110dcbb1e48342946c36024e76 Mon Sep 17 00:00:00 2001 From: David Mason Date: Tue, 12 Sep 2023 14:48:05 -0700 Subject: [PATCH 10/10] Update ep-session.c --- src/native/eventpipe/ep-session.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 4dd7cc0b0120c..ee134be65059d 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -329,23 +329,16 @@ ep_session_enable_rundown (EventPipeSession *session) const uint64_t keywords = 0x80020139; const EventPipeEventLevel verbose_logging_level = EP_EVENT_LEVEL_VERBOSE; - EventPipeProviderConfiguration rundown_providers [2]; - uint32_t rundown_providers_len = (uint32_t)ARRAY_SIZE (rundown_providers); + EventPipeProviderConfiguration rundown_provider; + ep_provider_config_init (&rundown_provider, ep_config_get_rundown_provider_name_utf8 (), keywords, verbose_logging_level, NULL); // Rundown provider. - ep_provider_config_init (&rundown_providers [1], ep_config_get_rundown_provider_name_utf8 (), keywords, verbose_logging_level, NULL); // Rundown provider. + EventPipeSessionProvider *session_provider = ep_session_provider_alloc ( + ep_provider_config_get_provider_name (&rundown_provider), + ep_provider_config_get_keywords (&rundown_provider), + ep_provider_config_get_logging_level (&rundown_provider), + ep_provider_config_get_filter_data (&rundown_provider)); - // Update provider list with rundown configuration. - for (uint32_t i = 0; i < rundown_providers_len; ++i) { - const EventPipeProviderConfiguration *config = &rundown_providers [i]; - - EventPipeSessionProvider *session_provider = ep_session_provider_alloc ( - ep_provider_config_get_provider_name (config), - ep_provider_config_get_keywords (config), - ep_provider_config_get_logging_level (config), - ep_provider_config_get_filter_data (config)); - - ep_raise_error_if_nok (ep_session_add_session_provider (session, session_provider)); - } + ep_raise_error_if_nok (ep_session_add_session_provider (session, session_provider)); ep_session_set_rundown_enabled (session, true); result = true;