Skip to content

Commit 81827f3

Browse files
committed
Store thread in SequencePoint Map
In preparation to cleanup ThreadSessionStates, adjust the SequencePoint map of Thread sequence numbers to map the EventPipeThread directly instead of the ThreadSessionState.
1 parent b9f9555 commit 81827f3

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/native/eventpipe/ep-block.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,10 @@ ep_sequence_point_block_init (
906906
const uint32_t thread_count = dn_umap_size (map);
907907
ep_write_buffer_uint32_t (&sequence_point_block->block.write_pointer, thread_count);
908908

909-
DN_UMAP_FOREACH_BEGIN (const EventPipeThreadSessionState *, key, uint32_t, sequence_number, map) {
909+
DN_UMAP_FOREACH_BEGIN (EventPipeThread *, thread, uint32_t, sequence_number, map) {
910910
ep_write_buffer_uint64_t (
911911
&sequence_point_block->block.write_pointer,
912-
ep_thread_get_os_thread_id (ep_thread_session_state_get_thread (key)));
912+
ep_thread_get_os_thread_id (thread));
913913

914914
ep_write_buffer_uint32_t (
915915
&sequence_point_block->block.write_pointer,

src/native/eventpipe/ep-buffer-manager.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ buffer_manager_init_sequence_point_thread_list (
378378
ep_buffer_manager_requires_lock_held (buffer_manager);
379379

380380
DN_LIST_FOREACH_BEGIN (EventPipeThreadSessionState *, thread_session_state, buffer_manager->thread_session_state_list) {
381+
EventPipeThread *thread = ep_thread_session_state_get_thread (thread_session_state);
382+
381383
// The sequence number captured here is not guaranteed to be the most recent sequence number, nor
382384
// is it guaranteed to match the number of events we would observe in the thread's write buffer
383385
// memory. This is only used as a lower bound on the number of events the thread has attempted to
@@ -388,8 +390,8 @@ buffer_manager_init_sequence_point_thread_list (
388390
// underflow.
389391
uint32_t sequence_number = ep_thread_session_state_get_volatile_sequence_number (thread_session_state) - 1;
390392

391-
dn_umap_ptr_uint32_insert (ep_sequence_point_get_thread_sequence_numbers (sequence_point), thread_session_state, sequence_number);
392-
ep_thread_addref (ep_thread_holder_get_thread (ep_thread_session_state_get_thread_holder_ref (thread_session_state)));
393+
dn_umap_ptr_uint32_insert (ep_sequence_point_get_thread_sequence_numbers (sequence_point), thread, sequence_number);
394+
ep_thread_addref (thread);
393395
} DN_LIST_FOREACH_END;
394396

395397
// This needs to come after querying the thread sequence numbers to ensure that any recorded
@@ -1166,17 +1168,18 @@ ep_buffer_manager_write_all_buffers_to_file_v4 (
11661168
EP_SPIN_LOCK_ENTER (&buffer_manager->rt_lock, section2)
11671169
for (dn_list_it_t it = dn_list_begin (buffer_manager->thread_session_state_list); !dn_list_it_end (it); ) {
11681170
EventPipeThreadSessionState *session_state = *dn_list_it_data_t (it, EventPipeThreadSessionState *);
1169-
dn_umap_it_t found = dn_umap_ptr_uint32_find (ep_sequence_point_get_thread_sequence_numbers (sequence_point), session_state);
1171+
EventPipeThread *thread = ep_thread_session_state_get_thread (session_state);
1172+
dn_umap_it_t found = dn_umap_ptr_uint32_find (ep_sequence_point_get_thread_sequence_numbers (sequence_point), thread);
11701173
uint32_t thread_sequence_number = !dn_umap_it_end (found) ? dn_umap_it_value_uint32_t (found) : 0;
11711174
uint32_t last_read_sequence_number = ep_thread_session_state_get_last_read_sequence_number (session_state);
11721175
// Sequence numbers can overflow so we can't use a direct last_read > sequence_number comparison
11731176
// If a thread is able to drop more than 0x80000000 events in between sequence points then we will
11741177
// miscategorize it, but that seems unlikely.
11751178
uint32_t last_read_delta = last_read_sequence_number - thread_sequence_number;
11761179
if (0 < last_read_delta && last_read_delta < 0x80000000) {
1177-
dn_umap_ptr_uint32_insert_or_assign (ep_sequence_point_get_thread_sequence_numbers (sequence_point), session_state, last_read_sequence_number);
1180+
dn_umap_ptr_uint32_insert_or_assign (ep_sequence_point_get_thread_sequence_numbers (sequence_point), thread, last_read_sequence_number);
11781181
if (dn_umap_it_end (found))
1179-
ep_thread_addref (ep_thread_holder_get_thread (ep_thread_session_state_get_thread_holder_ref (session_state)));
1182+
ep_thread_addref (thread);
11801183
}
11811184

11821185
it = dn_list_it_next (it);
@@ -1214,11 +1217,12 @@ ep_buffer_manager_write_all_buffers_to_file_v4 (
12141217
DN_LIST_FOREACH_BEGIN (EventPipeSequencePoint *, current_sequence_point, buffer_manager->sequence_points) {
12151218
// foreach (session_state in session_states_to_delete)
12161219
DN_VECTOR_PTR_FOREACH_BEGIN (EventPipeThreadSessionState *, thread_session_state, &session_states_to_delete) {
1217-
dn_umap_it_t found = dn_umap_ptr_uint32_find (ep_sequence_point_get_thread_sequence_numbers (current_sequence_point), thread_session_state);
1220+
EventPipeThread *thread = ep_thread_session_state_get_thread (thread_session_state);
1221+
dn_umap_it_t found = dn_umap_ptr_uint32_find (ep_sequence_point_get_thread_sequence_numbers (current_sequence_point), thread);
12181222
if (!dn_umap_it_end (found)) {
12191223
dn_umap_erase (found);
12201224
// every entry of this map was holding an extra ref to the thread (see: ep-event-instance.{h|c})
1221-
ep_thread_release (ep_thread_session_state_get_thread (thread_session_state));
1225+
ep_thread_release (thread);
12221226
}
12231227
} DN_VECTOR_PTR_FOREACH_END;
12241228
} DN_LIST_FOREACH_END;

src/native/eventpipe/ep-event-instance.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ sequence_point_fini (EventPipeSequencePoint *sequence_point)
231231

232232
// Each entry in the map owns a ref-count on the corresponding thread
233233
if (dn_umap_size (sequence_point->thread_sequence_numbers) != 0) {
234-
DN_UMAP_FOREACH_KEY_BEGIN (EventPipeThreadSessionState *, key, sequence_point->thread_sequence_numbers) {
235-
ep_thread_release (ep_thread_session_state_get_thread (key));
234+
DN_UMAP_FOREACH_KEY_BEGIN (EventPipeThread *, key, sequence_point->thread_sequence_numbers) {
235+
ep_thread_release (key);
236236
} DN_UMAP_FOREACH_END;
237237
}
238238

0 commit comments

Comments
 (0)