Skip to content

Commit

Permalink
throw in max and avg rtt as well
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Aug 30, 2024
1 parent 1c1a9ba commit 48fc6c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
44 changes: 40 additions & 4 deletions reliable.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ struct reliable_endpoint_t
double time;
float rtt;
float rtt_min;
float rtt_max;
float rtt_avg;
float jitter;
float packet_loss;
float sent_bandwidth_kbps;
Expand Down Expand Up @@ -1343,21 +1345,43 @@ void reliable_endpoint_update( struct reliable_endpoint_t * endpoint, double tim

endpoint->time = time;

// calculate min rtt
// calculate min and max rtt
{
float min_rtt = 10000.0f;
float max_rtt = 0.0f;
float sum_rtt = 0.0f;
int count = 0;
for ( int i = 0; i < endpoint->config.rtt_history_size; i++ )
{
if ( endpoint->rtt_history_buffer[i] >= 0.0f && endpoint->rtt_history_buffer[i] < min_rtt )
const float rtt = endpoint->rtt_history_buffer[i];
if ( rtt >= 0.0f )
{
min_rtt = endpoint->rtt_history_buffer[i];
if ( rtt < min_rtt )
{
min_rtt = rtt;
}
if ( rtt > max_rtt )
{
max_rtt = rtt;
}
sum_rtt += rtt;
count++;
}
}
if ( min_rtt == 10000.0f )
{
min_rtt = 0.0f;
}
endpoint->rtt_min = min_rtt;
endpoint->rtt_max = max_rtt;
if ( count > 0 )
{
endpoint->rtt_avg = sum_rtt / (float)count;
}
else
{
endpoint->rtt_avg = 0.0f;
}
}

// calculate jitter
Expand Down Expand Up @@ -1544,6 +1568,18 @@ float reliable_endpoint_rtt_min( struct reliable_endpoint_t * endpoint )
return endpoint->rtt_min;
}

float reliable_endpoint_rtt_max( struct reliable_endpoint_t * endpoint )
{
reliable_assert( endpoint );
return endpoint->rtt_max;
}

float reliable_endpoint_rtt_avg( struct reliable_endpoint_t * endpoint )
{
reliable_assert( endpoint );
return endpoint->rtt_avg;
}

float reliable_endpoint_jitter( struct reliable_endpoint_t * endpoint )
{
reliable_assert( endpoint );
Expand Down Expand Up @@ -2454,7 +2490,7 @@ void test_fragment_cleanup()

void reliable_test()
{
//while ( 1 )
// while ( 1 )
{
RUN_TEST( test_endian );
RUN_TEST( test_sequence_buffer );
Expand Down
4 changes: 4 additions & 0 deletions reliable.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ float reliable_endpoint_rtt( struct reliable_endpoint_t * endpoint );

float reliable_endpoint_rtt_min( struct reliable_endpoint_t * endpoint );

float reliable_endpoint_rtt_max( struct reliable_endpoint_t * endpoint );

float reliable_endpoint_rtt_avg( struct reliable_endpoint_t * endpoint );

float reliable_endpoint_jitter( struct reliable_endpoint_t * endpoint );

float reliable_endpoint_packet_loss( struct reliable_endpoint_t * endpoint );
Expand Down

0 comments on commit 48fc6c7

Please sign in to comment.