From cc14d20c407892def189808c5d426e27f05f3221 Mon Sep 17 00:00:00 2001 From: Lakshan Fernando Date: Fri, 28 Jul 2023 15:41:11 -0700 Subject: [PATCH] Tag events with thread specific information (#89516) * Tagging events with thread specific information * FB * Update src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp Co-authored-by: Elinor Fung * Remove stale comments --------- Co-authored-by: Elinor Fung --- .../nativeaot/Runtime/eventpipe/ep-rt-aot.cpp | 14 ++++++- .../nativeaot/Runtime/eventpipe/ep-rt-aot.h | 38 +++++-------------- .../Runtime/eventpipe/ep-rt-config-aot.h | 2 + .../Runtime/eventpipe/ep-rt-types-aot.h | 6 +-- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp index 617f146e743..119c779f873 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp @@ -20,6 +20,9 @@ #include #include "gcenv.h" +#include "thread.h" +#include "threadstore.h" +#include "threadstore.inl" #ifndef DIRECTORY_SEPARATOR_CHAR #ifdef TARGET_UNIX @@ -56,7 +59,7 @@ ep_rt_aot_walk_managed_stack_for_thread ( ep_rt_thread_handle_t thread, EventPipeStackContents *stack_contents) { - PalDebugBreak(); + // NativeAOT does not support getting the call stack return false; } @@ -826,6 +829,15 @@ void ep_rt_aot_create_activity_id (uint8_t *activity_id, uint32_t activity_id_le #endif } +ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void) +{ + return ThreadStore::GetCurrentThreadIfAvailable(); +} + +ep_rt_thread_id_t ep_rt_aot_thread_get_id (ep_rt_thread_handle_t thread_handle) +{ + return thread_handle->GetPalThreadIdForLogging(); +} #ifdef EP_CHECKED_BUILD diff --git a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h index e6bfb1dcb31..81295594c0c 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h @@ -491,7 +491,7 @@ ep_rt_config_value_get_enable_stackwalk (void) if (RhConfig::Environment::TryGetBooleanValue("EventPipeEnableStackwalk", &value)) return value; - return true; + return false; } /* @@ -1550,10 +1550,9 @@ ep_rt_thread_handle_t ep_rt_thread_get_handle (void) { STATIC_CONTRACT_NOTHROW; - // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // TODO: Implement thread creation/management if needed - // return GetThreadNULLOk (); - return NULL; + + extern ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void); + return ep_rt_aot_thread_get_handle(); } static @@ -1562,13 +1561,9 @@ ep_rt_thread_id_t ep_rt_thread_get_id (ep_rt_thread_handle_t thread_handle) { STATIC_CONTRACT_NOTHROW; - EP_ASSERT (thread_handle != NULL); - // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // TODO: Implement thread creation/management if needed - // return ep_rt_uint64_t_to_thread_id_t (thread_handle->GetOSThreadId64 ()); - // PalDebugBreak(); - return 0; + extern ep_rt_thread_id_t ep_rt_aot_thread_get_id (ep_rt_thread_handle_t thread_handle); + return ep_rt_aot_thread_get_id(thread_handle); } static @@ -1605,11 +1600,7 @@ ep_rt_thread_activity_id_handle_t ep_rt_thread_get_activity_id_handle (void) { STATIC_CONTRACT_NOTHROW; - // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // TODO: Implement thread creation/management if needed - // return GetThread (); - // PalDebugBreak(); - return NULL; + return ep_rt_thread_get_or_create(); } static @@ -1617,13 +1608,7 @@ inline const uint8_t * ep_rt_thread_get_activity_id_cref (ep_rt_thread_activity_id_handle_t activity_id_handle) { - STATIC_CONTRACT_NOTHROW; - EP_ASSERT (activity_id_handle != NULL); - - // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // TODO: Implement thread creation/management if needed - // return reinterpret_cast(activity_id_handle->GetActivityId ()); - // PalDebugBreak(); + EP_UNREACHABLE ("EP_THREAD_INCLUDE_ACTIVITY_ID should have been defined on NativeAOT"); return NULL; } @@ -1640,7 +1625,7 @@ ep_rt_thread_get_activity_id ( EP_ASSERT (activity_id != NULL); EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - memcpy (activity_id, ep_rt_thread_get_activity_id_cref (activity_id_handle), EP_ACTIVITY_ID_SIZE); + memcpy (activity_id, ep_thread_get_activity_id_cref (activity_id_handle), EP_ACTIVITY_ID_SIZE); } static @@ -1656,10 +1641,7 @@ ep_rt_thread_set_activity_id ( EP_ASSERT (activity_id != NULL); EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE); - // shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase - // TODO: Implement thread creation/management if needed - // activity_id_handle->SetActivityId (reinterpret_cast(activity_id)); - // PalDebugBreak(); + memcpy (ep_thread_get_activity_id_ref (activity_id_handle), activity_id, EP_ACTIVITY_ID_SIZE); } #undef EP_YIELD_WHILE 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 335b8ce5677..5bbf54a1298 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h @@ -4,4 +4,6 @@ #ifndef EVENTPIPE_RT_CONFIG_AOT_H #define EVENTPIPE_RT_CONFIG_AOT_H +#define EP_THREAD_INCLUDE_ACTIVITY_ID + #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 c6899ba2792..82ca6a7cbbd 100644 --- a/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h +++ b/src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h @@ -78,14 +78,10 @@ typedef struct _rt_aot_lock_internal_t ep_rt_spin_lock_handle_t; typedef class Thread * ep_rt_thread_handle_t; #undef ep_rt_thread_activity_id_handle_t -typedef class Thread * ep_rt_thread_activity_id_handle_t; +typedef EventPipeThread * ep_rt_thread_activity_id_handle_t; #undef ep_rt_thread_id_t -// #ifndef TARGET_UNIX -// typedef DWORD ep_rt_thread_id_t; -// #else typedef size_t ep_rt_thread_id_t; -//#endif #undef ep_rt_thread_start_func typedef size_t (__stdcall *ep_rt_thread_start_func)(void *lpThreadParameter); -- GitLab