Skip to content

Commit cc14d20

Browse files
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 <elfung@microsoft.com> * Remove stale comments --------- Co-authored-by: Elinor Fung <elfung@microsoft.com>
1 parent 43e47b8 commit cc14d20

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <minipal/random.h>
2121

2222
#include "gcenv.h"
23+
#include "thread.h"
24+
#include "threadstore.h"
25+
#include "threadstore.inl"
2326

2427
#ifndef DIRECTORY_SEPARATOR_CHAR
2528
#ifdef TARGET_UNIX
@@ -56,7 +59,7 @@ ep_rt_aot_walk_managed_stack_for_thread (
5659
ep_rt_thread_handle_t thread,
5760
EventPipeStackContents *stack_contents)
5861
{
59-
PalDebugBreak();
62+
// NativeAOT does not support getting the call stack
6063
return false;
6164
}
6265

@@ -826,6 +829,15 @@ void ep_rt_aot_create_activity_id (uint8_t *activity_id, uint32_t activity_id_le
826829
#endif
827830
}
828831

832+
ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void)
833+
{
834+
return ThreadStore::GetCurrentThreadIfAvailable();
835+
}
836+
837+
ep_rt_thread_id_t ep_rt_aot_thread_get_id (ep_rt_thread_handle_t thread_handle)
838+
{
839+
return thread_handle->GetPalThreadIdForLogging();
840+
}
829841

830842
#ifdef EP_CHECKED_BUILD
831843

src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ ep_rt_config_value_get_enable_stackwalk (void)
491491
if (RhConfig::Environment::TryGetBooleanValue("EventPipeEnableStackwalk", &value))
492492
return value;
493493

494-
return true;
494+
return false;
495495
}
496496

497497
/*
@@ -1550,10 +1550,9 @@ ep_rt_thread_handle_t
15501550
ep_rt_thread_get_handle (void)
15511551
{
15521552
STATIC_CONTRACT_NOTHROW;
1553-
// shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
1554-
// TODO: Implement thread creation/management if needed
1555-
// return GetThreadNULLOk ();
1556-
return NULL;
1553+
1554+
extern ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void);
1555+
return ep_rt_aot_thread_get_handle();
15571556
}
15581557

15591558
static
@@ -1562,13 +1561,9 @@ ep_rt_thread_id_t
15621561
ep_rt_thread_get_id (ep_rt_thread_handle_t thread_handle)
15631562
{
15641563
STATIC_CONTRACT_NOTHROW;
1565-
EP_ASSERT (thread_handle != NULL);
15661564

1567-
// shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
1568-
// TODO: Implement thread creation/management if needed
1569-
// return ep_rt_uint64_t_to_thread_id_t (thread_handle->GetOSThreadId64 ());
1570-
// PalDebugBreak();
1571-
return 0;
1565+
extern ep_rt_thread_id_t ep_rt_aot_thread_get_id (ep_rt_thread_handle_t thread_handle);
1566+
return ep_rt_aot_thread_get_id(thread_handle);
15721567
}
15731568

15741569
static
@@ -1605,25 +1600,15 @@ ep_rt_thread_activity_id_handle_t
16051600
ep_rt_thread_get_activity_id_handle (void)
16061601
{
16071602
STATIC_CONTRACT_NOTHROW;
1608-
// shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
1609-
// TODO: Implement thread creation/management if needed
1610-
// return GetThread ();
1611-
// PalDebugBreak();
1612-
return NULL;
1603+
return ep_rt_thread_get_or_create();
16131604
}
16141605

16151606
static
16161607
inline
16171608
const uint8_t *
16181609
ep_rt_thread_get_activity_id_cref (ep_rt_thread_activity_id_handle_t activity_id_handle)
16191610
{
1620-
STATIC_CONTRACT_NOTHROW;
1621-
EP_ASSERT (activity_id_handle != NULL);
1622-
1623-
// shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
1624-
// TODO: Implement thread creation/management if needed
1625-
// return reinterpret_cast<const uint8_t *>(activity_id_handle->GetActivityId ());
1626-
// PalDebugBreak();
1611+
EP_UNREACHABLE ("EP_THREAD_INCLUDE_ACTIVITY_ID should have been defined on NativeAOT");
16271612
return NULL;
16281613
}
16291614

@@ -1640,7 +1625,7 @@ ep_rt_thread_get_activity_id (
16401625
EP_ASSERT (activity_id != NULL);
16411626
EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE);
16421627

1643-
memcpy (activity_id, ep_rt_thread_get_activity_id_cref (activity_id_handle), EP_ACTIVITY_ID_SIZE);
1628+
memcpy (activity_id, ep_thread_get_activity_id_cref (activity_id_handle), EP_ACTIVITY_ID_SIZE);
16441629
}
16451630

16461631
static
@@ -1656,10 +1641,7 @@ ep_rt_thread_set_activity_id (
16561641
EP_ASSERT (activity_id != NULL);
16571642
EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE);
16581643

1659-
// shipping criteria: no EVENTPIPE-NATIVEAOT-TODO left in the codebase
1660-
// TODO: Implement thread creation/management if needed
1661-
// activity_id_handle->SetActivityId (reinterpret_cast<LPCGUID>(activity_id));
1662-
// PalDebugBreak();
1644+
memcpy (ep_thread_get_activity_id_ref (activity_id_handle), activity_id, EP_ACTIVITY_ID_SIZE);
16631645
}
16641646

16651647
#undef EP_YIELD_WHILE

src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-config-aot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
#ifndef EVENTPIPE_RT_CONFIG_AOT_H
55
#define EVENTPIPE_RT_CONFIG_AOT_H
66

7+
#define EP_THREAD_INCLUDE_ACTIVITY_ID
8+
79
#endif /* EVENTPIPE_RT_CONFIG_AOT_H */

src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-types-aot.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,10 @@ typedef struct _rt_aot_lock_internal_t ep_rt_spin_lock_handle_t;
7878
typedef class Thread * ep_rt_thread_handle_t;
7979

8080
#undef ep_rt_thread_activity_id_handle_t
81-
typedef class Thread * ep_rt_thread_activity_id_handle_t;
81+
typedef EventPipeThread * ep_rt_thread_activity_id_handle_t;
8282

8383
#undef ep_rt_thread_id_t
84-
// #ifndef TARGET_UNIX
85-
// typedef DWORD ep_rt_thread_id_t;
86-
// #else
8784
typedef size_t ep_rt_thread_id_t;
88-
//#endif
8985

9086
#undef ep_rt_thread_start_func
9187
typedef size_t (__stdcall *ep_rt_thread_start_func)(void *lpThreadParameter);

0 commit comments

Comments
 (0)