@@ -787,6 +787,7 @@ ep_buffer_manager_alloc (
787787
788788	instance -> session  =  session ;
789789	instance -> size_of_all_buffers  =  0 ;
790+ 	instance -> num_oversized_events_dropped  =  0 ;
790791
791792#ifdef  EP_CHECKED_BUILD 
792793	instance -> num_buffers_allocated  =  0 ;
@@ -887,6 +888,8 @@ ep_buffer_manager_write_event (
887888	bool  alloc_new_buffer  =  false;
888889	EventPipeBuffer  * buffer  =  NULL ;
889890	EventPipeThreadSessionState  * session_state  =  NULL ;
891+ 	EventPipeStackContents  stack_contents ;
892+ 	EventPipeStackContents  * current_stack_contents  =  NULL ;
890893
891894	EP_ASSERT  (buffer_manager  !=  NULL );
892895	EP_ASSERT  (ep_event  !=  NULL );
@@ -897,12 +900,23 @@ ep_buffer_manager_write_event (
897900	// Before we pick a buffer, make sure the event is enabled. 
898901	ep_return_false_if_nok  (ep_event_is_enabled  (ep_event ));
899902
903+ 	// Check that the payload size is less than 64 KB (max size for ETW events) 
904+ 	if  (ep_event_payload_get_size  (payload ) >  64  *  1024 )
905+ 	{
906+ 		ep_rt_atomic_inc_int64_t  (& buffer_manager -> num_oversized_events_dropped );
907+ 		EventPipeThread  * current_thread  =  ep_thread_get ();
908+ 		ep_rt_spin_lock_handle_t  * thread_lock  =  ep_thread_get_rt_lock_ref  (current_thread );
909+ 		EP_SPIN_LOCK_ENTER  (thread_lock , section1 )
910+ 			session_state  =  ep_thread_get_or_create_session_state  (current_thread , session );
911+ 			ep_thread_session_state_increment_sequence_number  (session_state );
912+ 		EP_SPIN_LOCK_EXIT  (thread_lock , section1 )
913+ 		return  false;
914+ 	}
915+ 
900916	// Check to see an event thread was specified. If not, then use the current thread. 
901917	if  (event_thread  ==  NULL )
902918		event_thread  =  thread ;
903919
904- 	EventPipeStackContents  stack_contents ;
905- 	EventPipeStackContents  * current_stack_contents ;
906920	current_stack_contents  =  ep_stack_contents_init  (& stack_contents );
907921	if  (stack  ==  NULL  &&  ep_event_get_need_stack  (ep_event ) &&  !ep_session_get_rundown_enabled  (session )) {
908922		ep_walk_managed_stack_for_current_thread  (current_stack_contents );
@@ -917,9 +931,9 @@ ep_buffer_manager_write_event (
917931	ep_rt_spin_lock_handle_t  * thread_lock ;
918932	thread_lock  =  ep_thread_get_rt_lock_ref  (current_thread );
919933
920- 	EP_SPIN_LOCK_ENTER  (thread_lock , section1 )
934+ 	EP_SPIN_LOCK_ENTER  (thread_lock , section2 )
921935		session_state  =  ep_thread_get_or_create_session_state  (current_thread , session );
922- 		ep_raise_error_if_nok_holding_spin_lock  (session_state  !=  NULL , section1 );
936+ 		ep_raise_error_if_nok_holding_spin_lock  (session_state  !=  NULL , section2 );
923937
924938		buffer  =  ep_thread_session_state_get_write_buffer  (session_state );
925939		if  (!buffer ) {
@@ -931,7 +945,7 @@ ep_buffer_manager_write_event (
931945			else 
932946				alloc_new_buffer  =  true;
933947		}
934- 	EP_SPIN_LOCK_EXIT  (thread_lock , section1 )
948+ 	EP_SPIN_LOCK_EXIT  (thread_lock , section2 )
935949
936950	// alloc_new_buffer is reused below to detect if overflow happened, so cache it here to see if we should 
937951	// signal the reader thread 
@@ -951,23 +965,23 @@ ep_buffer_manager_write_event (
951965			// This lock looks unnecessary for the sequence number, but didn't want to 
952966			// do a broader refactoring to take it out. If it shows up as a perf 
953967			// problem then we should. 
954- 			EP_SPIN_LOCK_ENTER  (thread_lock , section2 )
968+ 			EP_SPIN_LOCK_ENTER  (thread_lock , section3 )
955969				ep_thread_session_state_increment_sequence_number  (session_state );
956- 			EP_SPIN_LOCK_EXIT  (thread_lock , section2 )
970+ 			EP_SPIN_LOCK_EXIT  (thread_lock , section3 )
957971		} else  {
958972			current_thread  =  ep_thread_get  ();
959973			EP_ASSERT  (current_thread  !=  NULL );
960974
961975			thread_lock  =  ep_thread_get_rt_lock_ref  (current_thread );
962- 			EP_SPIN_LOCK_ENTER  (thread_lock , section3 )
976+ 			EP_SPIN_LOCK_ENTER  (thread_lock , section4 )
963977					ep_thread_session_state_set_write_buffer  (session_state , buffer );
964978					// Try to write the event after we allocated a buffer. 
965979					// This is the first time if the thread had no buffers before the call to this function. 
966980					// This is the second time if this thread did have one or more buffers, but they were full. 
967981					alloc_new_buffer  =  !ep_buffer_write_event  (buffer , event_thread , session , ep_event , payload , activity_id , related_activity_id , stack );
968982					EP_ASSERT (!alloc_new_buffer );
969983					ep_thread_session_state_increment_sequence_number  (session_state );
970- 			EP_SPIN_LOCK_EXIT  (thread_lock , section3 )
984+ 			EP_SPIN_LOCK_EXIT  (thread_lock , section4 )
971985		}
972986	}
973987
0 commit comments