Skip to content

Commit f806da2

Browse files
cshungnoahfalk
andauthored
Allow user to specify a rundown keyword to override the default. (#101189)
Co-authored-by: Noah Falk <noahfalk@users.noreply.github.com>
1 parent b621129 commit f806da2

File tree

7 files changed

+112
-30
lines changed

7 files changed

+112
-30
lines changed

src/native/eventpipe/ds-eventpipe-protocol.c

+73-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ eventpipe_collect_tracing_command_try_parse_rundown_requested (
4646
uint32_t *buffer_len,
4747
bool *rundown_requested);
4848

49+
static
50+
bool
51+
eventpipe_collect_tracing_command_try_parse_rundown_keyword (
52+
uint8_t **buffer,
53+
uint32_t *buffer_len,
54+
uint64_t *rundown_keyword);
55+
4956
static
5057
bool
5158
eventpipe_collect_tracing_command_try_parse_stackwalk_requested (
@@ -78,6 +85,12 @@ eventpipe_collect_tracing3_command_try_parse_payload (
7885
uint8_t *buffer,
7986
uint16_t buffer_len);
8087

88+
static
89+
uint8_t *
90+
eventpipe_collect_tracing4_command_try_parse_payload (
91+
uint8_t *buffer,
92+
uint16_t buffer_len);
93+
8194
static
8295
bool
8396
eventpipe_protocol_helper_stop_tracing (
@@ -150,6 +163,21 @@ eventpipe_collect_tracing_command_try_parse_rundown_requested (
150163
return ds_ipc_message_try_parse_bool (buffer, buffer_len, rundown_requested);
151164
}
152165

166+
static
167+
inline
168+
bool
169+
eventpipe_collect_tracing_command_try_parse_rundown_keyword (
170+
uint8_t **buffer,
171+
uint32_t *buffer_len,
172+
uint64_t *rundown_keyword)
173+
{
174+
EP_ASSERT (buffer != NULL);
175+
EP_ASSERT (buffer_len != NULL);
176+
EP_ASSERT (rundown_keyword != NULL);
177+
178+
return ds_ipc_message_try_parse_uint64_t (buffer, buffer_len, rundown_keyword);
179+
}
180+
153181
static
154182
inline
155183
bool
@@ -299,6 +327,7 @@ eventpipe_collect_tracing_command_try_parse_payload (
299327
ep_raise_error ();
300328
instance->rundown_requested = true;
301329
instance->stackwalk_requested = true;
330+
instance->rundown_keyword = ep_default_rundown_keyword;
302331

303332
ep_on_exit:
304333
return (uint8_t *)instance;
@@ -330,6 +359,9 @@ eventpipe_collect_tracing2_command_try_parse_payload (
330359
!eventpipe_collect_tracing_command_try_parse_rundown_requested (&buffer_cursor, &buffer_cursor_len, &instance->rundown_requested) ||
331360
!eventpipe_collect_tracing_command_try_parse_config (&buffer_cursor, &buffer_cursor_len, &instance->provider_configs))
332361
ep_raise_error ();
362+
363+
instance->rundown_keyword = instance->rundown_requested ? ep_default_rundown_keyword : 0;
364+
333365
instance->stackwalk_requested = true;
334366

335367
ep_on_exit:
@@ -364,6 +396,42 @@ eventpipe_collect_tracing3_command_try_parse_payload (
364396
!eventpipe_collect_tracing_command_try_parse_config (&buffer_cursor, &buffer_cursor_len, &instance->provider_configs))
365397
ep_raise_error ();
366398

399+
instance->rundown_keyword = instance->rundown_requested ? ep_default_rundown_keyword : 0;
400+
401+
ep_on_exit:
402+
return (uint8_t *)instance;
403+
404+
ep_on_error:
405+
ds_eventpipe_collect_tracing_command_payload_free (instance);
406+
instance = NULL;
407+
ep_exit_error_handler ();
408+
}
409+
410+
static
411+
uint8_t *
412+
eventpipe_collect_tracing4_command_try_parse_payload (
413+
uint8_t *buffer,
414+
uint16_t buffer_len)
415+
{
416+
EP_ASSERT (buffer != NULL);
417+
418+
uint8_t * buffer_cursor = buffer;
419+
uint32_t buffer_cursor_len = buffer_len;
420+
421+
EventPipeCollectTracingCommandPayload *instance = ds_eventpipe_collect_tracing_command_payload_alloc ();
422+
ep_raise_error_if_nok (instance != NULL);
423+
424+
instance->incoming_buffer = buffer;
425+
426+
if (!eventpipe_collect_tracing_command_try_parse_circular_buffer_size (&buffer_cursor, &buffer_cursor_len, &instance->circular_buffer_size_in_mb ) ||
427+
!eventpipe_collect_tracing_command_try_parse_serialization_format (&buffer_cursor, &buffer_cursor_len, &instance->serialization_format) ||
428+
!eventpipe_collect_tracing_command_try_parse_rundown_keyword (&buffer_cursor, &buffer_cursor_len, &instance->rundown_keyword) ||
429+
!eventpipe_collect_tracing_command_try_parse_stackwalk_requested (&buffer_cursor, &buffer_cursor_len, &instance->stackwalk_requested) ||
430+
!eventpipe_collect_tracing_command_try_parse_config (&buffer_cursor, &buffer_cursor_len, &instance->provider_configs))
431+
ep_raise_error ();
432+
433+
instance->rundown_requested = instance->rundown_keyword != 0;
434+
367435
ep_on_exit:
368436
return (uint8_t *)instance;
369437

@@ -471,7 +539,7 @@ eventpipe_protocol_helper_collect_tracing (
471539
dn_vector_size (payload->provider_configs),
472540
EP_SESSION_TYPE_IPCSTREAM,
473541
payload->serialization_format,
474-
payload->rundown_requested,
542+
payload->rundown_keyword,
475543
payload->stackwalk_requested,
476544
ds_ipc_stream_get_stream_ref (stream),
477545
NULL,
@@ -544,6 +612,10 @@ ds_eventpipe_protocol_helper_handle_ipc_message (
544612
payload = (EventPipeCollectTracingCommandPayload *)ds_ipc_message_try_parse_payload (message, eventpipe_collect_tracing3_command_try_parse_payload);
545613
result = eventpipe_protocol_helper_collect_tracing (payload, stream);
546614
break;
615+
case EP_COMMANDID_COLLECT_TRACING_4:
616+
payload = (EventPipeCollectTracingCommandPayload *)ds_ipc_message_try_parse_payload (message, eventpipe_collect_tracing4_command_try_parse_payload);
617+
result = eventpipe_protocol_helper_collect_tracing (payload, stream);
618+
break;
547619
case EP_COMMANDID_STOP_TRACING:
548620
result = eventpipe_protocol_helper_stop_tracing (message, stream);
549621
break;

src/native/eventpipe/ds-eventpipe-protocol.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// Command = 0x0202
2121
// Command = 0x0203
2222
// Command = 0x0204
23+
// Command = 0x0205
2324
#if defined(DS_INLINE_GETTER_SETTER) || defined(DS_IMPL_EVENTPIPE_PROTOCOL_GETTER_SETTER)
2425
struct _EventPipeCollectTracingCommandPayload {
2526
#else
@@ -40,6 +41,7 @@ struct _EventPipeCollectTracingCommandPayload_Internal {
4041
EventPipeSerializationFormat serialization_format;
4142
bool rundown_requested;
4243
bool stackwalk_requested;
44+
uint64_t rundown_keyword;
4345
};
4446

4547
#if !defined(DS_INLINE_GETTER_SETTER) && !defined(DS_IMPL_EVENTPIPE_PROTOCOL_GETTER_SETTER)

src/native/eventpipe/ds-types.h

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ typedef enum {
104104
EP_COMMANDID_COLLECT_TRACING = 0x02,
105105
EP_COMMANDID_COLLECT_TRACING_2 = 0x03,
106106
EP_COMMANDID_COLLECT_TRACING_3 = 0x04,
107+
EP_COMMANDID_COLLECT_TRACING_4 = 0x05,
107108
// future
108109
} EventPipeCommandId;
109110

src/native/eventpipe/ep-session.c

+3-13
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ ep_session_alloc (
133133
IpcStream *stream,
134134
EventPipeSessionType session_type,
135135
EventPipeSerializationFormat format,
136-
bool rundown_requested,
136+
uint64_t rundown_keyword,
137137
bool stackwalk_requested,
138138
uint32_t circular_buffer_size_in_mb,
139139
const EventPipeProviderConfiguration *providers,
@@ -164,7 +164,7 @@ ep_session_alloc (
164164
instance->rundown_enabled = 0;
165165
instance->session_type = session_type;
166166
instance->format = format;
167-
instance->rundown_requested = rundown_requested;
167+
instance->rundown_keyword = rundown_keyword;
168168
instance->synchronous_callback = sync_callback;
169169
instance->callback_additional_data = callback_additional_data;
170170

@@ -317,17 +317,7 @@ ep_session_enable_rundown (EventPipeSession *session)
317317
ep_requires_lock_held ();
318318

319319
bool result = false;
320-
321-
//! This is CoreCLR specific keywords for native ETW events (ending up in event pipe).
322-
//! The keywords below seems to correspond to:
323-
//! GCKeyword (0x00000001)
324-
//! LoaderKeyword (0x00000008)
325-
//! JitKeyword (0x00000010)
326-
//! NgenKeyword (0x00000020)
327-
//! unused_keyword (0x00000100)
328-
//! JittedMethodILToNativeMapKeyword (0x00020000)
329-
//! ThreadTransferKeyword (0x80000000)
330-
const uint64_t keywords = 0x80020139;
320+
const uint64_t keywords = ep_session_get_rundown_keyword (session);
331321
const EventPipeEventLevel verbose_logging_level = EP_EVENT_LEVEL_VERBOSE;
332322

333323
EventPipeProviderConfiguration rundown_provider;

src/native/eventpipe/ep-session.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct _EventPipeSession_Internal {
5353
// irrelevant.
5454
EventPipeSerializationFormat format;
5555
// For determininig if a particular session needs rundown events.
56-
bool rundown_requested;
56+
uint64_t rundown_keyword;
5757
// Note - access to this field is NOT synchronized
5858
// This functionality is a workaround because we couldn't safely enable/disable the session where we wanted to due to lock-leveling.
5959
// we expect to remove it in the future once that limitation is resolved other scenarios are discouraged from using this given that
@@ -79,7 +79,7 @@ EP_DEFINE_GETTER(EventPipeSession *, session, uint32_t, index)
7979
EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeSessionProviderList *, providers)
8080
EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeBufferManager *, buffer_manager)
8181
EP_DEFINE_GETTER_REF(EventPipeSession *, session, volatile uint32_t *, rundown_enabled)
82-
EP_DEFINE_GETTER(EventPipeSession *, session, bool, rundown_requested)
82+
EP_DEFINE_GETTER(EventPipeSession *, session, uint64_t, rundown_keyword)
8383
EP_DEFINE_GETTER(EventPipeSession *, session, ep_timestamp_t, session_start_time)
8484
EP_DEFINE_GETTER(EventPipeSession *, session, ep_timestamp_t, session_start_timestamp)
8585
EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeFile *, file)
@@ -92,7 +92,7 @@ ep_session_alloc (
9292
IpcStream *stream,
9393
EventPipeSessionType session_type,
9494
EventPipeSerializationFormat format,
95-
bool rundown_requested,
95+
uint64_t rundown_keyword,
9696
bool stackwalk_requested,
9797
uint32_t circular_buffer_size_in_mb,
9898
const EventPipeProviderConfiguration *providers,

src/native/eventpipe/ep.c

+20-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
#include "ep-session.h"
1616
#include "ep-sample-profiler.h"
1717

18+
//! This is CoreCLR specific keywords for native ETW events (ending up in event pipe).
19+
//! The keywords below seems to correspond to:
20+
//! GCKeyword (0x00000001)
21+
//! LoaderKeyword (0x00000008)
22+
//! JitKeyword (0x00000010)
23+
//! NgenKeyword (0x00000020)
24+
//! unused_keyword (0x00000100)
25+
//! JittedMethodILToNativeMapKeyword (0x00020000)
26+
//! ThreadTransferKeyword (0x80000000)
27+
uint64_t ep_default_rundown_keyword = 0x80020139;
28+
1829
static bool _ep_can_start_threads = false;
1930

2031
static dn_vector_t *_ep_deferred_enable_session_ids = NULL;
@@ -494,7 +505,7 @@ enable (
494505
options->stream,
495506
options->session_type,
496507
options->format,
497-
options->rundown_requested,
508+
options->rundown_keyword,
498509
options->stackwalk_requested,
499510
options->circular_buffer_size_in_mb,
500511
options->providers,
@@ -589,7 +600,7 @@ disable_holding_lock (
589600
ep_session_disable (session); // WriteAllBuffersToFile, and remove providers.
590601

591602
// Do rundown before fully stopping the session unless rundown wasn't requested
592-
if (ep_session_get_rundown_requested (session) && _ep_can_start_threads) {
603+
if ((ep_session_get_rundown_keyword (session) != 0) && _ep_can_start_threads) {
593604
ep_session_enable_rundown (session); // Set Rundown provider.
594605
EventPipeThread *const thread = ep_thread_get_or_create ();
595606
if (thread != NULL) {
@@ -908,7 +919,7 @@ enable_default_session_via_env_variables (void)
908919
ep_config,
909920
ep_rt_config_value_get_output_streaming () ? EP_SESSION_TYPE_FILESTREAM : EP_SESSION_TYPE_FILE,
910921
EP_SERIALIZATION_FORMAT_NETTRACE_V4,
911-
true,
922+
ep_default_rundown_keyword,
912923
NULL,
913924
NULL,
914925
NULL);
@@ -959,7 +970,7 @@ ep_enable (
959970
uint32_t providers_len,
960971
EventPipeSessionType session_type,
961972
EventPipeSerializationFormat format,
962-
bool rundown_requested,
973+
uint64_t rundown_keyword,
963974
IpcStream *stream,
964975
EventPipeSessionSynchronousCallback sync_callback,
965976
void *callback_additional_data)
@@ -975,7 +986,7 @@ ep_enable (
975986
providers_len,
976987
session_type,
977988
format,
978-
rundown_requested,
989+
rundown_keyword,
979990
true, // stackwalk_requested
980991
stream,
981992
sync_callback,
@@ -995,7 +1006,7 @@ ep_enable_2 (
9951006
const ep_char8_t *providers_config,
9961007
EventPipeSessionType session_type,
9971008
EventPipeSerializationFormat format,
998-
bool rundown_requested,
1009+
uint64_t rundown_keyword,
9991010
IpcStream *stream,
10001011
EventPipeSessionSynchronousCallback sync_callback,
10011012
void *callback_additional_data)
@@ -1073,7 +1084,7 @@ ep_enable_2 (
10731084
providers_len,
10741085
session_type,
10751086
format,
1076-
rundown_requested,
1087+
rundown_keyword,
10771088
stream,
10781089
sync_callback,
10791090
callback_additional_data);
@@ -1105,7 +1116,7 @@ ep_session_options_init (
11051116
uint32_t providers_len,
11061117
EventPipeSessionType session_type,
11071118
EventPipeSerializationFormat format,
1108-
bool rundown_requested,
1119+
uint64_t rundown_keyword,
11091120
bool stackwalk_requested,
11101121
IpcStream* stream,
11111122
EventPipeSessionSynchronousCallback sync_callback,
@@ -1119,7 +1130,7 @@ ep_session_options_init (
11191130
options->providers_len = providers_len;
11201131
options->session_type = session_type;
11211132
options->format = format;
1122-
options->rundown_requested = rundown_requested;
1133+
options->rundown_keyword = rundown_keyword;
11231134
options->stackwalk_requested = stackwalk_requested;
11241135
options->stream = stream;
11251136
options->sync_callback = sync_callback;

src/native/eventpipe/ep.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ extern volatile EventPipeSession *_ep_sessions [EP_MAX_NUMBER_OF_SESSIONS];
1313
extern volatile uint32_t _ep_number_of_sessions;
1414
extern volatile uint64_t _ep_allow_write;
1515

16+
/*
17+
* Global constants
18+
*/
19+
20+
extern uint64_t ep_default_rundown_keyword;
21+
1622
/*
1723
* Globals and volatile access functions.
1824
*/
@@ -119,7 +125,7 @@ typedef struct EventPipeSessionOptions {
119125
uint32_t providers_len;
120126
EventPipeSessionType session_type;
121127
EventPipeSerializationFormat format;
122-
bool rundown_requested;
128+
uint64_t rundown_keyword;
123129
bool stackwalk_requested;
124130
} EventPipeSessionOptions;
125131

@@ -132,7 +138,7 @@ ep_session_options_init (
132138
uint32_t providers_len,
133139
EventPipeSessionType session_type,
134140
EventPipeSerializationFormat format,
135-
bool rundown_requested,
141+
uint64_t rundown_keyword,
136142
bool stackwalk_requested,
137143
IpcStream *stream,
138144
EventPipeSessionSynchronousCallback sync_callback,
@@ -164,7 +170,7 @@ ep_enable (
164170
uint32_t providers_len,
165171
EventPipeSessionType session_type,
166172
EventPipeSerializationFormat format,
167-
bool rundown_requested,
173+
uint64_t rundown_keyword,
168174
IpcStream *stream,
169175
EventPipeSessionSynchronousCallback sync_callback,
170176
void *callback_additional_data);
@@ -176,7 +182,7 @@ ep_enable_2 (
176182
const ep_char8_t *providers,
177183
EventPipeSessionType session_type,
178184
EventPipeSerializationFormat format,
179-
bool rundown_requested,
185+
uint64_t rundown_keyword,
180186
IpcStream *stream,
181187
EventPipeSessionSynchronousCallback sync_callback,
182188
void *callback_additional_data);

0 commit comments

Comments
 (0)