Tag events with thread specific information (#89516)
authorLakshan Fernando <lakshanf@hotmail.com>
Fri, 28 Jul 2023 22:41:11 +0000 (15:41 -0700)
committerGitHub <noreply@github.com>
Fri, 28 Jul 2023 22:41:11 +0000 (15:41 -0700)
* Tagging events with thread specific information

* FB

* Update src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp

Co-authored-by: Elinor Fung <elfung@microsoft.com>
* Remove stale comments

---------

Co-authored-by: Elinor Fung <elfung@microsoft.com>
src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp
src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h
src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h
src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h

index 617f146..119c779 100644 (file)
@@ -20,6 +20,9 @@
 #include <minipal/random.h>
 
 #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
 
index e6bfb1d..8129559 100644 (file)
@@ -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<const uint8_t *>(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<LPCGUID>(activity_id));
-    // PalDebugBreak();
+    memcpy (ep_thread_get_activity_id_ref (activity_id_handle), activity_id, EP_ACTIVITY_ID_SIZE);
 }
 
 #undef EP_YIELD_WHILE
index 335b8ce..5bbf54a 100644 (file)
@@ -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 */
index c6899ba..82ca6a7 100644 (file)
@@ -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);