@@ -142,7 +142,7 @@ static struct aws_h2_sm_connection *s_get_best_sm_connection_from_set(struct aws
142142
143143/* helper function for building the transaction: Try to assign connection for a pending stream acquisition */
144144/* *_synced should only be called with LOCK HELD or from another synced function */
145- static void s_sm_try_assign_connection_to_pending_stream_acquisition (
145+ static void s_sm_try_assign_connection_to_pending_stream_acquisition_synced (
146146 struct aws_http2_stream_manager * stream_manager ,
147147 struct aws_h2_sm_pending_stream_acquisition * pending_stream_acquisition ) {
148148
@@ -344,7 +344,7 @@ static void s_aws_http2_stream_manager_build_transaction_synced(struct aws_http2
344344 aws_linked_list_pop_front (& stream_manager -> synced_data .pending_stream_acquisitions );
345345 struct aws_h2_sm_pending_stream_acquisition * pending_stream_acquisition =
346346 AWS_CONTAINER_OF (node , struct aws_h2_sm_pending_stream_acquisition , node );
347- s_sm_try_assign_connection_to_pending_stream_acquisition (stream_manager , pending_stream_acquisition );
347+ s_sm_try_assign_connection_to_pending_stream_acquisition_synced (stream_manager , pending_stream_acquisition );
348348 if (pending_stream_acquisition -> sm_connection == NULL ) {
349349 /* Cannot find any connection, push it back to the front and break the loop */
350350 aws_linked_list_push_front (& stream_manager -> synced_data .pending_stream_acquisitions , node );
@@ -994,3 +994,34 @@ void aws_http2_stream_manager_acquire_stream(
994994 } /* END CRITICAL SECTION */
995995 s_aws_http2_stream_manager_execute_transaction (& work );
996996}
997+
998+ static size_t s_get_available_streams_num_from_connection_set (const struct aws_random_access_set * set ) {
999+ size_t all_available_streams_num = 0 ;
1000+ size_t ideal_connection_num = aws_random_access_set_get_size (set );
1001+ for (size_t i = 0 ; i < ideal_connection_num ; i ++ ) {
1002+ struct aws_h2_sm_connection * sm_connection = NULL ;
1003+ AWS_FATAL_ASSERT (aws_random_access_set_random_get_ptr_index (set , (void * * )& sm_connection , i ) == AWS_OP_SUCCESS );
1004+ uint32_t available_streams = sm_connection -> max_concurrent_streams - sm_connection -> num_streams_assigned ;
1005+ all_available_streams_num += (size_t )available_streams ;
1006+ }
1007+ return all_available_streams_num ;
1008+ }
1009+
1010+ void aws_http2_stream_manager_fetch_metrics (
1011+ const struct aws_http2_stream_manager * stream_manager ,
1012+ struct aws_http_manager_metrics * out_metrics ) {
1013+ AWS_PRECONDITION (stream_manager );
1014+ AWS_PRECONDITION (out_metrics );
1015+ { /* BEGIN CRITICAL SECTION */
1016+ s_lock_synced_data ((struct aws_http2_stream_manager * )(void * )stream_manager );
1017+ size_t all_available_streams_num = 0 ;
1018+ all_available_streams_num +=
1019+ s_get_available_streams_num_from_connection_set (& stream_manager -> synced_data .ideal_available_set );
1020+ all_available_streams_num +=
1021+ s_get_available_streams_num_from_connection_set (& stream_manager -> synced_data .nonideal_available_set );
1022+ out_metrics -> pending_concurrency_acquires =
1023+ stream_manager -> synced_data .internal_refcount_stats [AWS_SMCT_PENDING_ACQUISITION ];
1024+ out_metrics -> available_concurrency = all_available_streams_num ;
1025+ s_unlock_synced_data ((struct aws_http2_stream_manager * )(void * )stream_manager );
1026+ } /* END CRITICAL SECTION */
1027+ }
0 commit comments