From ef73cd93d5ab98b516d9ba68a6a6220f62010174 Mon Sep 17 00:00:00 2001 From: Johan Lorensson Date: Thu, 14 Jan 2021 09:24:51 +0100 Subject: [PATCH] Add support for local array types in EventPipe C library. (#46924) --- .../vm/eventing/eventpipe/ds-rt-coreclr.h | 13 +++++ .../vm/eventing/eventpipe/ep-rt-coreclr.h | 55 +++++++++++++++++++ src/mono/mono/eventpipe/ds-rt-mono.h | 13 +++++ src/mono/mono/eventpipe/ep-rt-mono.h | 37 +++++++++++++ src/native/eventpipe/ds-ipc.c | 19 ++++--- src/native/eventpipe/ds-rt.h | 9 +++ src/native/eventpipe/ep-buffer-manager.c | 27 +++++---- src/native/eventpipe/ep-rt.h | 20 +++++++ src/native/eventpipe/ep-session.c | 6 +- 9 files changed, 173 insertions(+), 26 deletions(-) diff --git a/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h index fd60215abc95c..3068dd42adfef 100644 --- a/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h @@ -57,6 +57,9 @@ #define DS_RT_DEFINE_ARRAY(array_name, array_type, iterator_type, item_type) \ EP_RT_DEFINE_ARRAY_PREFIX(ds, array_name, array_type, iterator_type, item_type) +#define DS_RT_DEFINE_LOCAL_ARRAY(array_name, array_type, iterator_type, item_type) \ + EP_RT_DEFINE_LOCAL_ARRAY_PREFIX(ds, array_name, array_type, iterator_type, item_type) + #define DS_RT_DEFINE_ARRAY_ITERATOR(array_name, array_type, iterator_type, item_type) \ EP_RT_DEFINE_ARRAY_ITERATOR_PREFIX(ds, array_name, array_type, iterator_type, item_type) @@ -229,8 +232,13 @@ ds_rt_transport_get_default_name ( */ DS_RT_DEFINE_ARRAY (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) +DS_RT_DEFINE_LOCAL_ARRAY (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) DS_RT_DEFINE_ARRAY_ITERATOR (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) +#undef DS_RT_DECLARE_LOCAL_IPC_POLL_HANDLE_ARRAY +#define DS_RT_DECLARE_LOCAL_IPC_POLL_HANDLE_ARRAY(var_name) \ + EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, ds_rt_ipc_poll_handle_array_t) + /* * DiagnosticsPort. */ @@ -239,9 +247,14 @@ DS_RT_DEFINE_ARRAY (port_array, ds_rt_port_array_t, ds_rt_port_array_iterator_t, DS_RT_DEFINE_ARRAY_ITERATOR (port_array, ds_rt_port_array_t, ds_rt_port_array_iterator_t, DiagnosticsPort *) DS_RT_DEFINE_ARRAY (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) +DS_RT_DEFINE_LOCAL_ARRAY (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) DS_RT_DEFINE_ARRAY_ITERATOR (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) DS_RT_DEFINE_ARRAY_REVERSE_ITERATOR (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_reverse_iterator_t, ep_char8_t *) +#undef DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY +#define DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY(var_name) \ + EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, ds_rt_port_config_array_t) + /* * DiagnosticsProfiler. */ diff --git a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h index 794601266a609..fa579c3683359 100644 --- a/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h +++ b/src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h @@ -362,6 +362,21 @@ _rt_coreclr_array_alloc_capacity ( ep_array->array->AllocNoThrow (capacity); } +template +static +inline +void +_rt_coreclr_array_init_capacity ( + ARRAY_TYPE *ep_array, + size_t capacity) +{ + STATIC_CONTRACT_NOTHROW; + EP_ASSERT (ep_array != NULL); + + if (ep_array->array) + ep_array->array->AllocNoThrow (capacity); +} + template static inline @@ -919,9 +934,29 @@ _rt_coreclr_hash_map_iterator_value (CONST_ITERATOR_TYPE *iterator) return _rt_coreclr_array_is_valid (ep_array); \ } +#define EP_RT_DEFINE_LOCAL_ARRAY_PREFIX(prefix_name, array_name, array_type, iterator_type, item_type) \ + static inline void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, init) (array_type *ep_array) { \ + STATIC_CONTRACT_NOTHROW; \ + } \ + static inline void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, init_capacity) (array_type *ep_array, size_t capacity) { \ + STATIC_CONTRACT_NOTHROW; \ + _rt_coreclr_array_init_capacity(ep_array, capacity); \ + } \ + static inline void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, fini) (array_type *ep_array) { \ + STATIC_CONTRACT_NOTHROW; \ + } + #define EP_RT_DEFINE_ARRAY(array_name, array_type, iterator_type, item_type) \ EP_RT_DEFINE_ARRAY_PREFIX(ep, array_name, array_type, iterator_type, item_type) +#define EP_RT_DEFINE_LOCAL_ARRAY(array_name, array_type, iterator_type, item_type) \ + EP_RT_DEFINE_LOCAL_ARRAY_PREFIX(ep, array_name, array_type, iterator_type, item_type) + +#define EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, var_type) \ + var_type::array_type_t _local_ ##var_name; \ + var_type var_name; \ + var_name.array = &_local_ ##var_name + #define EP_RT_DEFINE_ARRAY_ITERATOR_PREFIX(prefix_name, array_name, array_type, iterator_type, item_type) \ static inline iterator_type EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, iterator_begin) (const array_type *ep_array) \ { \ @@ -1429,15 +1464,25 @@ ep_rt_provider_invoke_callback ( */ EP_RT_DEFINE_ARRAY (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) +EP_RT_DEFINE_LOCAL_ARRAY (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) EP_RT_DEFINE_ARRAY_ITERATOR (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) +#undef EP_RT_DECLARE_LOCAL_BUFFER_ARRAY +#define EP_RT_DECLARE_LOCAL_BUFFER_ARRAY(var_name) \ + EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, ep_rt_buffer_array_t) + /* * EventPipeBufferList. */ EP_RT_DEFINE_ARRAY (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) +EP_RT_DEFINE_LOCAL_ARRAY (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) EP_RT_DEFINE_ARRAY_ITERATOR (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) +#undef EP_RT_DECLARE_LOCAL_BUFFER_LIST_ARRAY +#define EP_RT_DECLARE_LOCAL_BUFFER_LIST_ARRAY(var_name) \ + EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, ep_rt_buffer_list_array_t) + /* * EventPipeEvent. */ @@ -1594,8 +1639,13 @@ EP_RT_DEFINE_LIST (thread_list, ep_rt_thread_list_t, EventPipeThread *) EP_RT_DEFINE_LIST_ITERATOR (thread_list, ep_rt_thread_list_t, ep_rt_thread_list_iterator_t, EventPipeThread *) EP_RT_DEFINE_ARRAY (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) +EP_RT_DEFINE_LOCAL_ARRAY (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) EP_RT_DEFINE_ARRAY_ITERATOR (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) +#undef EP_RT_DECLARE_LOCAL_THREAD_ARRAY +#define EP_RT_DECLARE_LOCAL_THREAD_ARRAY(var_name) \ + EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, ep_rt_thread_array_t) + /* * EventPipeThreadSessionState. */ @@ -1604,8 +1654,13 @@ EP_RT_DEFINE_LIST (thread_session_state_list, ep_rt_thread_session_state_list_t, EP_RT_DEFINE_LIST_ITERATOR (thread_session_state_list, ep_rt_thread_session_state_list_t, ep_rt_thread_session_state_list_iterator_t, EventPipeThreadSessionState *) EP_RT_DEFINE_ARRAY (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) +EP_RT_DEFINE_LOCAL_ARRAY (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) EP_RT_DEFINE_ARRAY_ITERATOR (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) +#undef EP_RT_DECLARE_LOCAL_THREAD_SESSION_STATE_ARRAY +#define EP_RT_DECLARE_LOCAL_THREAD_SESSION_STATE_ARRAY(var_name) \ + EP_RT_DECLARE_LOCAL_ARRAY_VARIABLE(var_name, ep_rt_thread_session_state_array_t) + static EventPipeSessionProvider * ep_rt_session_provider_list_find_by_name ( diff --git a/src/mono/mono/eventpipe/ds-rt-mono.h b/src/mono/mono/eventpipe/ds-rt-mono.h index a6a5149057c08..20f8250e4d078 100644 --- a/src/mono/mono/eventpipe/ds-rt-mono.h +++ b/src/mono/mono/eventpipe/ds-rt-mono.h @@ -60,6 +60,9 @@ #define DS_RT_DEFINE_ARRAY(array_name, array_type, iterator_type, item_type) \ EP_RT_DEFINE_ARRAY_PREFIX(ds, array_name, array_type, iterator_type, item_type) +#define DS_RT_DEFINE_LOCAL_ARRAY(array_name, array_type, iterator_type, item_type) \ + EP_RT_DEFINE_LOCAL_ARRAY_PREFIX(ds, array_name, array_type, iterator_type, item_type) + #define DS_RT_DEFINE_ARRAY_ITERATOR(array_name, array_type, iterator_type, item_type) \ EP_RT_DEFINE_ARRAY_ITERATOR_PREFIX(ds, array_name, array_type, iterator_type, item_type) @@ -185,8 +188,13 @@ ds_rt_transport_get_default_name ( */ DS_RT_DEFINE_ARRAY (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) +DS_RT_DEFINE_LOCAL_ARRAY (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) DS_RT_DEFINE_ARRAY_ITERATOR (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) +#undef DS_RT_DECLARE_LOCAL_IPC_POLL_HANDLE_ARRAY +#define DS_RT_DECLARE_LOCAL_IPC_POLL_HANDLE_ARRAY(var_name) \ + ds_rt_ipc_poll_handle_array_t var_name + /* * DiagnosticsPort. */ @@ -195,9 +203,14 @@ DS_RT_DEFINE_ARRAY (port_array, ds_rt_port_array_t, ds_rt_port_array_iterator_t, DS_RT_DEFINE_ARRAY_ITERATOR (port_array, ds_rt_port_array_t, ds_rt_port_array_iterator_t, DiagnosticsPort *) DS_RT_DEFINE_ARRAY (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) +DS_RT_DEFINE_LOCAL_ARRAY (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) DS_RT_DEFINE_ARRAY_ITERATOR (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) DS_RT_DEFINE_ARRAY_REVERSE_ITERATOR (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_reverse_iterator_t, ep_char8_t *) +#undef DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY +#define DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY(var_name) \ + ds_rt_port_config_array_t var_name + /* * DiagnosticsProfiler. */ diff --git a/src/mono/mono/eventpipe/ep-rt-mono.h b/src/mono/mono/eventpipe/ep-rt-mono.h index 9390c7e129400..90758c9c3de1c 100644 --- a/src/mono/mono/eventpipe/ep-rt-mono.h +++ b/src/mono/mono/eventpipe/ep-rt-mono.h @@ -180,9 +180,26 @@ prefix_name ## _rt_ ## type_name ## _ ## func_name } \ static inline bool EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, is_valid) (const array_type *ep_array) { return (ep_array != NULL && ep_array->array != NULL); } +#define EP_RT_DEFINE_LOCAL_ARRAY_PREFIX(prefix_name, array_name, array_type, iterator_type, item_type) \ + static inline void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, init) (array_type *ep_array) { \ + EP_ASSERT (ep_array != NULL); \ + ep_array->array = g_array_new (FALSE, FALSE, sizeof (item_type)); \ + } \ + static inline void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, init_capacity) (array_type *ep_array, size_t capacity) { \ + EP_ASSERT (ep_array != NULL); \ + ep_array->array = g_array_sized_new (FALSE, FALSE, sizeof (item_type), capacity); \ + } \ + static inline void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, fini) (array_type *ep_array) { \ + EP_ASSERT (ep_array != NULL); \ + g_array_free (ep_array->array, TRUE); \ + } + #define EP_RT_DEFINE_ARRAY(array_name, array_type, iterator_type, item_type) \ EP_RT_DEFINE_ARRAY_PREFIX(ep, array_name, array_type, iterator_type, item_type) +#define EP_RT_DEFINE_LOCAL_ARRAY(array_name, array_type, iterator_type, item_type) \ + EP_RT_DEFINE_LOCAL_ARRAY_PREFIX(ep, array_name, array_type, iterator_type, item_type) + #define EP_RT_DEFINE_ARRAY_ITERATOR_PREFIX(prefix_name, array_name, array_type, iterator_type, item_type) \ static inline iterator_type EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, iterator_begin) (const array_type *ep_array) { \ EP_ASSERT (ep_array != NULL); \ @@ -892,15 +909,25 @@ ep_rt_provider_invoke_callback ( */ EP_RT_DEFINE_ARRAY (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) +EP_RT_DEFINE_LOCAL_ARRAY (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) EP_RT_DEFINE_ARRAY_ITERATOR (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) +#undef EP_RT_DECLARE_LOCAL_BUFFER_ARRAY +#define EP_RT_DECLARE_LOCAL_BUFFER_ARRAY(var_name) \ + ep_rt_buffer_array_t var_name + /* * EventPipeBufferList. */ EP_RT_DEFINE_ARRAY (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) +EP_RT_DEFINE_LOCAL_ARRAY (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) EP_RT_DEFINE_ARRAY_ITERATOR (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) +#undef EP_RT_DECLARE_LOCAL_BUFFER_LIST_ARRAY +#define EP_RT_DECLARE_LOCAL_BUFFER_LIST_ARRAY(var_name) \ + ep_rt_buffer_list_array_t var_name + /* * EventPipeEvent. */ @@ -1047,8 +1074,13 @@ EP_RT_DEFINE_LIST (thread_list, ep_rt_thread_list_t, EventPipeThread *) EP_RT_DEFINE_LIST_ITERATOR (thread_list, ep_rt_thread_list_t, ep_rt_thread_list_iterator_t, EventPipeThread *) EP_RT_DEFINE_ARRAY (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) +EP_RT_DEFINE_LOCAL_ARRAY (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) EP_RT_DEFINE_ARRAY_ITERATOR (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) +#undef EP_RT_DECLARE_LOCAL_THREAD_ARRAY +#define EP_RT_DECLARE_LOCAL_THREAD_ARRAY(var_name) \ + ep_rt_thread_array_t var_name + /* * EventPipeThreadSessionState. */ @@ -1057,8 +1089,13 @@ EP_RT_DEFINE_LIST (thread_session_state_list, ep_rt_thread_session_state_list_t, EP_RT_DEFINE_LIST_ITERATOR (thread_session_state_list, ep_rt_thread_session_state_list_t, ep_rt_thread_session_state_list_iterator_t, EventPipeThreadSessionState *) EP_RT_DEFINE_ARRAY (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) +EP_RT_DEFINE_LOCAL_ARRAY (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) EP_RT_DEFINE_ARRAY_ITERATOR (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) +#undef EP_RT_DECLARE_LOCAL_THREAD_SESSION_STATE_ARRAY +#define EP_RT_DECLARE_LOCAL_THREAD_SESSION_STATE_ARRAY(var_name) \ + ep_rt_thread_session_state_array_t var_name + static inline int diff --git a/src/native/eventpipe/ds-ipc.c b/src/native/eventpipe/ds-ipc.c index 929d919d95b75..1aa2fbd547e45 100644 --- a/src/native/eventpipe/ds-ipc.c +++ b/src/native/eventpipe/ds-ipc.c @@ -235,11 +235,11 @@ ds_ipc_stream_factory_configure (ds_ipc_error_callback_func callback) ep_char8_t *ports = ds_rt_config_value_get_ports (); if (ports) { - ds_rt_port_config_array_t port_configs; - ds_rt_port_config_array_t port_config_parts; + DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY (port_configs); + DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY (port_config_parts); - ds_rt_port_config_array_alloc (&port_configs); - ds_rt_port_config_array_alloc (&port_config_parts); + ds_rt_port_config_array_init (&port_configs); + ds_rt_port_config_array_init (&port_config_parts); if (ds_rt_port_config_array_is_valid (&port_configs) && ds_rt_port_config_array_is_valid (&port_config_parts)) { ipc_stream_factory_split_port_config (ports, ";", &port_configs); @@ -290,8 +290,8 @@ ds_ipc_stream_factory_configure (ds_ipc_error_callback_func callback) result &= false; } - ds_rt_port_config_array_free (&port_config_parts); - ds_rt_port_config_array_free (&port_configs); + ds_rt_port_config_array_fini (&port_config_parts); + ds_rt_port_config_array_fini (&port_configs); } // create the default listen port @@ -329,7 +329,6 @@ ds_ipc_stream_factory_get_next_available_stream (ds_ipc_error_callback_func call DS_LOG_INFO_0 ("ds_ipc_stream_factory_get_next_available_stream - ENTER"); DiagnosticsIpcStream *stream = NULL; - ds_rt_ipc_poll_handle_array_t ipc_poll_handles; DiagnosticsIpcPollHandle ipc_poll_handle; ds_rt_port_array_t *ports = &_ds_port_array; DiagnosticsPort *port = NULL; @@ -338,8 +337,9 @@ ds_ipc_stream_factory_get_next_available_stream (ds_ipc_error_callback_func call bool connect_success = true; uint32_t poll_attempts = 0; - // TODO: Convert to stack instance. - ds_rt_ipc_poll_handle_array_alloc (&ipc_poll_handles); + DS_RT_DECLARE_LOCAL_IPC_POLL_HANDLE_ARRAY (ipc_poll_handles); + + ds_rt_ipc_poll_handle_array_init (&ipc_poll_handles); ep_raise_error_if_nok (ds_rt_ipc_poll_handle_array_is_valid (&ipc_poll_handles)); while (!stream) { @@ -420,6 +420,7 @@ ds_ipc_stream_factory_get_next_available_stream (ds_ipc_error_callback_func call ep_on_exit: DS_LOG_INFO_2 ("ds_ipc_stream_factory_get_next_available_stream - EXIT :: Poll attempt: %d, stream using handle %d.\n", poll_attempts, ds_ipc_stream_get_handle_int32_t (stream)); + ds_rt_ipc_poll_handle_array_fini (&ipc_poll_handles); return stream; ep_on_error: diff --git a/src/native/eventpipe/ds-rt.h b/src/native/eventpipe/ds-rt.h index 8e49a6f681a7d..b1b4dec8d461f 100644 --- a/src/native/eventpipe/ds-rt.h +++ b/src/native/eventpipe/ds-rt.h @@ -26,6 +26,9 @@ #define DS_RT_DECLARE_ARRAY(array_name, array_type, iterator_type, item_type) \ EP_RT_DECLARE_ARRAY_PREFIX(ds, array_name, array_type, iterator_type, item_type) +#define DS_RT_DECLARE_LOCAL_ARRAY(array_name, array_type, iterator_type, item_type) \ + EP_RT_DECLARE_LOCAL_ARRAY_PREFIX(ds, array_name, array_type, iterator_type, item_type) + #define DS_RT_DECLARE_ARRAY_ITERATOR(array_name, array_type, iterator_type, item_type) \ EP_RT_DECLARE_ARRAY_ITERATOR_PREFIX(ds, array_name, array_type, iterator_type, item_type) @@ -95,8 +98,11 @@ ds_rt_transport_get_default_name ( */ DS_RT_DECLARE_ARRAY (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) +DS_RT_DECLARE_LOCAL_ARRAY (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) DS_RT_DECLARE_ARRAY_ITERATOR (ipc_poll_handle_array, ds_rt_ipc_poll_handle_array_t, ds_rt_ipc_poll_handle_array_iterator_t, DiagnosticsIpcPollHandle) +#define DS_RT_DECLARE_LOCAL_IPC_POLL_HANDLE_ARRAY(var_name) ds_rt_redefine + /* * DiagnosticsPort. */ @@ -105,9 +111,12 @@ DS_RT_DECLARE_ARRAY (port_array, ds_rt_port_array_t, ds_rt_port_array_iterator_t DS_RT_DECLARE_ARRAY_ITERATOR (port_array, ds_rt_port_array_t, ds_rt_port_array_iterator_t, DiagnosticsPort *) DS_RT_DECLARE_ARRAY (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) +DS_RT_DECLARE_LOCAL_ARRAY (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) DS_RT_DECLARE_ARRAY_ITERATOR (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_iterator_t, ep_char8_t *) DS_RT_DECLARE_ARRAY_REVERSE_ITERATOR (port_config_array, ds_rt_port_config_array_t, ds_rt_port_config_array_reverse_iterator_t, ep_char8_t *) +#define DS_RT_DECLARE_LOCAL_PORT_CONFIG_ARRAY(var_name) ds_rt_redefine + /* * DiagnosticsProfiler. */ diff --git a/src/native/eventpipe/ep-buffer-manager.c b/src/native/eventpipe/ep-buffer-manager.c index 241783fdc9aec..dd2187519bdf2 100644 --- a/src/native/eventpipe/ep-buffer-manager.c +++ b/src/native/eventpipe/ep-buffer-manager.c @@ -547,12 +547,10 @@ buffer_manager_move_next_event_any_thread ( // at the same time. // Step 1 - while holding m_lock get the oldest buffer from each thread - ep_rt_buffer_array_t buffer_array; - ep_rt_buffer_list_array_t buffer_list_array; - - // TODO: Init on stack instead of alloc? - ep_rt_buffer_array_alloc (&buffer_array); - ep_rt_buffer_list_array_alloc (&buffer_list_array); + EP_RT_DECLARE_LOCAL_BUFFER_ARRAY (buffer_array); + EP_RT_DECLARE_LOCAL_BUFFER_LIST_ARRAY (buffer_list_array); + ep_rt_buffer_array_init (&buffer_array); + ep_rt_buffer_list_array_init (&buffer_list_array); EP_SPIN_LOCK_ENTER (&buffer_manager->rt_lock, section1) EventPipeBufferList *buffer_list; @@ -609,8 +607,8 @@ buffer_manager_move_next_event_any_thread ( ep_on_exit: ep_buffer_manager_requires_lock_not_held (buffer_manager); - ep_rt_buffer_list_array_free (&buffer_list_array); - ep_rt_buffer_array_free (&buffer_array); + ep_rt_buffer_list_array_fini (&buffer_list_array); + ep_rt_buffer_array_fini (&buffer_array); return; ep_on_error: @@ -1004,8 +1002,9 @@ ep_buffer_manager_suspend_write_event ( // All calls to this method must be synchronized by our caller ep_requires_lock_held (); - ep_rt_thread_array_t thread_array; - ep_rt_thread_array_alloc (&thread_array); + EP_RT_DECLARE_LOCAL_THREAD_ARRAY (thread_array); + ep_rt_thread_array_init (&thread_array); + EP_SPIN_LOCK_ENTER (&buffer_manager->rt_lock, section1); EP_ASSERT (ep_buffer_manager_ensure_consistency (buffer_manager)); // Find all threads that have used this buffer manager. @@ -1033,7 +1032,7 @@ ep_buffer_manager_suspend_write_event ( ep_on_exit: ep_requires_lock_held (); - ep_rt_thread_array_free (&thread_array); + ep_rt_thread_array_fini (&thread_array); return; ep_on_error: @@ -1264,8 +1263,8 @@ ep_buffer_manager_deallocate_buffers (EventPipeBufferManager *buffer_manager) { EP_ASSERT (buffer_manager != NULL); - ep_rt_thread_session_state_array_t thread_session_states_to_remove; - ep_rt_thread_session_state_array_alloc (&thread_session_states_to_remove); + EP_RT_DECLARE_LOCAL_THREAD_SESSION_STATE_ARRAY(thread_session_states_to_remove); + ep_rt_thread_session_state_array_init (&thread_session_states_to_remove); // Take the buffer manager manipulation lock EP_SPIN_LOCK_ENTER (&buffer_manager->rt_lock, section1) @@ -1323,7 +1322,7 @@ ep_buffer_manager_deallocate_buffers (EventPipeBufferManager *buffer_manager) } ep_on_exit: - ep_rt_thread_session_state_array_free (&thread_session_states_to_remove); + ep_rt_thread_session_state_array_fini (&thread_session_states_to_remove); return; ep_on_error: diff --git a/src/native/eventpipe/ep-rt.h b/src/native/eventpipe/ep-rt.h index 457688dc25ced..6604ca226e174 100644 --- a/src/native/eventpipe/ep-rt.h +++ b/src/native/eventpipe/ep-rt.h @@ -67,9 +67,17 @@ prefix_name ## _rt_ ## type_name ## _ ## func_name static item_type * EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, data) (const array_type *ep_array); \ static bool EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, is_valid) (const array_type *ep_array); +#define EP_RT_DECLARE_LOCAL_ARRAY_PREFIX(prefix_name, array_name, array_type, iterator_type, item_type) \ + static void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, init) (array_type *ep_array); \ + static void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, init_capacity) (array_type *ep_array, size_t capacity); \ + static void EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, fini) (array_type *ep_array); + #define EP_RT_DECLARE_ARRAY(array_name, array_type, iterator_type, item_type) \ EP_RT_DECLARE_ARRAY_PREFIX(ep, array_name, array_type, iterator_type, item_type) +#define EP_RT_DECLARE_LOCAL_ARRAY(array_name, array_type, iterator_type, item_type) \ + EP_RT_DECLARE_LOCAL_ARRAY_PREFIX(ep, array_name, array_type, iterator_type, item_type) + #define EP_RT_DECLARE_ARRAY_ITERATOR_PREFIX(prefix_name, array_name, array_type, iterator_type, item_type) \ static iterator_type EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, iterator_begin) (const array_type *ep_array); \ static bool EP_RT_BUILD_TYPE_FUNC_NAME(prefix_name, array_name, iterator_end) (const array_type *ep_array, const iterator_type *iterator); \ @@ -236,15 +244,21 @@ ep_rt_provider_invoke_callback ( */ EP_RT_DECLARE_ARRAY (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) +EP_RT_DECLARE_LOCAL_ARRAY (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) EP_RT_DECLARE_ARRAY_ITERATOR (buffer_array, ep_rt_buffer_array_t, ep_rt_buffer_array_iterator_t, EventPipeBuffer *) +#define EP_RT_DECLARE_LOCAL_BUFFER_ARRAY(var_name) ds_rt_redefine + /* * EventPipeBufferList. */ EP_RT_DECLARE_ARRAY (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) +EP_RT_DECLARE_LOCAL_ARRAY (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) EP_RT_DECLARE_ARRAY_ITERATOR (buffer_list_array, ep_rt_buffer_list_array_t, ep_rt_buffer_list_array_iterator_t, EventPipeBufferList *) +#define EP_RT_DECLARE_LOCAL_BUFFER_LIST_ARRAY(var_name) ds_rt_redefine + /* * EventPipeEvent. */ @@ -342,8 +356,11 @@ EP_RT_DECLARE_LIST (thread_list, ep_rt_thread_list_t, EventPipeThread *) EP_RT_DECLARE_LIST_ITERATOR (thread_list, ep_rt_thread_list_t, ep_rt_thread_list_iterator_t, EventPipeThread *) EP_RT_DECLARE_ARRAY (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) +EP_RT_DECLARE_LOCAL_ARRAY (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) EP_RT_DECLARE_ARRAY_ITERATOR (thread_array, ep_rt_thread_array_t, ep_rt_thread_array_iterator_t, EventPipeThread *) +#define EP_RT_DECLARE_LOCAL_THREAD_ARRAY(var_name) ds_rt_redefine + /* * EventPipeThreadSessionState. */ @@ -352,8 +369,11 @@ EP_RT_DECLARE_LIST (thread_session_state_list, ep_rt_thread_session_state_list_t EP_RT_DECLARE_LIST_ITERATOR (thread_session_state_list, ep_rt_thread_session_state_list_t, ep_rt_thread_session_state_list_iterator_t, EventPipeThreadSessionState *) EP_RT_DECLARE_ARRAY (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) +EP_RT_DECLARE_LOCAL_ARRAY (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) EP_RT_DECLARE_ARRAY_ITERATOR (thread_session_state_array, ep_rt_thread_session_state_array_t, ep_rt_thread_session_state_array_iterator_t, EventPipeThreadSessionState *) +#define EP_RT_DECLARE_LOCAL_THREAD_SESSION_STATE_ARRAY(var_name) ds_rt_redefine + /* * Arrays. */ diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index c176dd4940a96..6f7190a66a70d 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -325,8 +325,8 @@ ep_session_suspend_write_event (EventPipeSession *session) // Need to disable the session before calling this method. EP_ASSERT (!ep_is_session_enabled ((EventPipeSessionID)session)); - ep_rt_thread_array_t threads; - ep_rt_thread_array_alloc (&threads); + EP_RT_DECLARE_LOCAL_THREAD_ARRAY (threads); + ep_rt_thread_array_init (&threads); ep_thread_get_threads (&threads); @@ -344,7 +344,7 @@ ep_session_suspend_write_event (EventPipeSession *session) ep_rt_thread_array_iterator_next (&threads_iterator); } - ep_rt_thread_array_free (&threads); + ep_rt_thread_array_fini (&threads); if (session->buffer_manager) // Convert all buffers to read only to ensure they get flushed