added interval_results to linked list
Этот коммит содержится в:
родитель
5ebed4362f
Коммит
b406b735e8
116
src/iperf_api.c
116
src/iperf_api.c
@ -43,6 +43,29 @@ static struct option longopts[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void add_interval_list(struct iperf_stream_result *rp, struct iperf_interval_results temp)
|
||||||
|
{
|
||||||
|
|
||||||
|
struct iperf_interval_results *n;
|
||||||
|
|
||||||
|
struct iperf_interval_results *ip = (struct iperf_interval_results *) malloc(sizeof(struct iperf_interval_results));
|
||||||
|
ip->bytes_transferred = temp.bytes_transferred;
|
||||||
|
ip->interval_duration = temp.interval_duration;
|
||||||
|
|
||||||
|
if(!rp->interval_results)
|
||||||
|
{
|
||||||
|
rp->interval_results = ip;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = rp->interval_results;
|
||||||
|
while(n->next)
|
||||||
|
n = n->next;
|
||||||
|
|
||||||
|
n->next = ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void send_result_to_client(struct iperf_stream *sp)
|
void send_result_to_client(struct iperf_stream *sp)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
@ -498,16 +521,48 @@ void iperf_free_test(struct iperf_test *test)
|
|||||||
|
|
||||||
void *iperf_stats_callback(struct iperf_test *test)
|
void *iperf_stats_callback(struct iperf_test *test)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
struct iperf_stream *sp = test->streams;
|
struct iperf_stream *sp = test->streams;
|
||||||
|
struct iperf_stream_result *rp = test->streams->result;
|
||||||
|
struct iperf_interval_results *ip, temp;
|
||||||
|
|
||||||
while(sp)
|
for(i=0; i< test->num_streams; i++)
|
||||||
{
|
{
|
||||||
if(test->role == 'c')
|
rp = sp->result;
|
||||||
sp->result->interval_results->bytes_transferred = sp->result->bytes_sent - sp->result->interval_results->bytes_transferred;
|
|
||||||
else
|
|
||||||
sp->result->interval_results->bytes_transferred = sp->result->bytes_received - sp->result->interval_results->bytes_transferred;
|
|
||||||
|
|
||||||
sp->result->interval_results->interval_duration+= test->stats_interval;
|
if(!rp->interval_results)
|
||||||
|
{
|
||||||
|
printf(" 1st time \n");
|
||||||
|
if(test ->role == 'c')
|
||||||
|
temp.bytes_transferred = rp->bytes_sent;
|
||||||
|
else
|
||||||
|
temp.bytes_transferred = rp->bytes_received;
|
||||||
|
|
||||||
|
temp.interval_duration = test->stats_interval;
|
||||||
|
|
||||||
|
printf("\tnew = %llu \t total bytes = %llu \n", temp.bytes_transferred, sp->result->bytes_sent);
|
||||||
|
|
||||||
|
add_interval_list(rp, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ip = sp->result->interval_results;
|
||||||
|
|
||||||
|
while(ip->next!= NULL)
|
||||||
|
ip = ip->next;
|
||||||
|
|
||||||
|
if(test ->role == 'c')
|
||||||
|
temp.bytes_transferred = rp->bytes_sent - ip->bytes_transferred;
|
||||||
|
else
|
||||||
|
temp.bytes_transferred = rp->bytes_received - ip->bytes_transferred;
|
||||||
|
|
||||||
|
temp.interval_duration = test->stats_interval + ip->interval_duration;
|
||||||
|
|
||||||
|
printf("\tnew = %llu \t total bytes = %llu and duration = %d\n", temp.bytes_transferred, sp->result->bytes_sent, temp.interval_duration);
|
||||||
|
|
||||||
|
add_interval_list(rp, temp);
|
||||||
|
}
|
||||||
|
|
||||||
sp= sp->next;
|
sp= sp->next;
|
||||||
}
|
}
|
||||||
@ -522,29 +577,29 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
struct iperf_stream *sp = test->streams;
|
struct iperf_stream *sp = test->streams;
|
||||||
iperf_size_t bytes=0;
|
iperf_size_t bytes=0;
|
||||||
double start_time, end_time;
|
double start_time, end_time;
|
||||||
|
// need to reassign this
|
||||||
char *message = (char *) malloc(300);
|
char *message = (char *) malloc(300);
|
||||||
char *message_final = (char *) malloc(test->num_streams * 50 + 200);
|
char *message_final = (char *) malloc(test->num_streams * 50 + 200);
|
||||||
|
|
||||||
start_time = sp->result->interval_results->interval_duration - test->stats_interval;
|
struct iperf_interval_results *ip = test->streams->result->interval_results;
|
||||||
end_time = sp->result->interval_results->interval_duration;
|
|
||||||
|
|
||||||
if(test->default_settings->state == TEST_RUNNING)
|
if(test->default_settings->state == TEST_RUNNING)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
while(sp)
|
while(sp)
|
||||||
{
|
{
|
||||||
if(test->protocol == Ptcp)
|
if(test->protocol == Ptcp)
|
||||||
{
|
{
|
||||||
|
while(ip->next!= NULL)
|
||||||
|
ip = ip->next;
|
||||||
|
|
||||||
sprintf(message,report_bw_header);
|
sprintf(message,report_bw_header);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
|
|
||||||
bytes+= sp->result->interval_results->bytes_transferred;
|
bytes+= ip->bytes_transferred;
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) (sp->result->interval_results->bytes_transferred), test->unit_format);
|
unit_snprintf(ubuf, UNIT_LEN, (double) (ip->bytes_transferred), test->unit_format);
|
||||||
unit_snprintf(nbuf, UNIT_LEN, (double) ( sp->result->interval_results->bytes_transferred / test->stats_interval), test->unit_format);
|
unit_snprintf(nbuf, UNIT_LEN, (double) (ip->bytes_transferred / test->stats_interval), test->unit_format);
|
||||||
|
|
||||||
sprintf(message, report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
sprintf(message, report_bw_format, sp->socket, (double)ip->interval_duration - test->stats_interval, (double)ip->interval_duration, ubuf, nbuf);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,41 +617,52 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
|
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) ( bytes), test->unit_format);
|
unit_snprintf(ubuf, UNIT_LEN, (double) ( bytes), test->unit_format);
|
||||||
unit_snprintf(nbuf, UNIT_LEN, (double) ( bytes / test->stats_interval), test->unit_format);
|
unit_snprintf(nbuf, UNIT_LEN, (double) ( bytes / test->stats_interval), test->unit_format);
|
||||||
sprintf(message, report_sum_bw_format, start_time, end_time, ubuf, nbuf);
|
sprintf(message, report_sum_bw_format, (double)ip->interval_duration - test->stats_interval, (double)ip->interval_duration, ubuf, nbuf);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
|
|
||||||
}
|
}
|
||||||
// PRINT TOTAL
|
|
||||||
|
|
||||||
if(test->default_settings->state == RESULT_REQUEST)
|
if(test->default_settings->state == RESULT_REQUEST)
|
||||||
{
|
{
|
||||||
bytes =0;
|
|
||||||
sp= test->streams;
|
sp= test->streams;
|
||||||
|
|
||||||
while(sp)
|
while(sp)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(test->protocol == Ptcp)
|
if(test->protocol == Ptcp)
|
||||||
{
|
{
|
||||||
if(sp->settings->state == STREAM_END)
|
if(sp->settings->state == STREAM_END)
|
||||||
{
|
{
|
||||||
|
if(test->role == 'c')
|
||||||
bytes+= sp->result->bytes_sent;
|
bytes+= sp->result->bytes_sent;
|
||||||
|
else
|
||||||
|
bytes+= sp->result->bytes_received;
|
||||||
|
|
||||||
gettimeofday( &sp->result->end_time, NULL);
|
gettimeofday( &sp->result->end_time, NULL);
|
||||||
|
|
||||||
sprintf(message,report_bw_header);
|
sprintf(message,report_bw_header);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
|
|
||||||
|
|
||||||
start_time = timeval_diff(&sp->result->start_time, &sp->result->start_time);
|
start_time = timeval_diff(&sp->result->start_time, &sp->result->start_time);
|
||||||
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
|
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
|
||||||
|
|
||||||
|
if(test->role == 'c')
|
||||||
|
{
|
||||||
unit_snprintf(ubuf, UNIT_LEN, (double) (sp->result->bytes_sent), test->unit_format);
|
unit_snprintf(ubuf, UNIT_LEN, (double) (sp->result->bytes_sent), test->unit_format);
|
||||||
unit_snprintf(nbuf, UNIT_LEN, (double) (sp->result->bytes_sent / end_time), test->unit_format);
|
unit_snprintf(nbuf, UNIT_LEN, (double) (sp->result->bytes_sent / end_time), test->unit_format);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unit_snprintf(ubuf, UNIT_LEN, (double) (sp->result->bytes_received), test->unit_format);
|
||||||
|
unit_snprintf(nbuf, UNIT_LEN, (double) (sp->result->bytes_received / end_time), test->unit_format);
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(message, report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
sprintf(message, report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else //UDP
|
||||||
{
|
{
|
||||||
if(sp->settings->state == STREAM_END)
|
if(sp->settings->state == STREAM_END)
|
||||||
{
|
{
|
||||||
@ -620,7 +686,6 @@ char *iperf_reporter_callback(struct iperf_test *test)
|
|||||||
|
|
||||||
sprintf(message, report_sum_bw_format, start_time, end_time, ubuf, nbuf);
|
sprintf(message, report_sum_bw_format, start_time, end_time, ubuf, nbuf);
|
||||||
strcat(message_final, message);
|
strcat(message_final, message);
|
||||||
|
|
||||||
// -m option
|
// -m option
|
||||||
if((test->print_mss != 0) && (test->role == 'c'))
|
if((test->print_mss != 0) && (test->role == 'c'))
|
||||||
{
|
{
|
||||||
@ -687,9 +752,6 @@ struct iperf_stream *iperf_new_stream(struct iperf_test *testp)
|
|||||||
memcpy(sp->settings, testp->default_settings, sizeof(struct iperf_settings));
|
memcpy(sp->settings, testp->default_settings, sizeof(struct iperf_settings));
|
||||||
|
|
||||||
sp->result = (struct iperf_stream_result *) malloc(sizeof(struct iperf_stream_result));
|
sp->result = (struct iperf_stream_result *) malloc(sizeof(struct iperf_stream_result));
|
||||||
//memset(&sp->result, 0, sizeof(struct iperf_stream_result));
|
|
||||||
|
|
||||||
sp->result->interval_results = (struct iperf_interval_results *) malloc(sizeof(struct iperf_interval_results));
|
|
||||||
|
|
||||||
sp->socket = -1;
|
sp->socket = -1;
|
||||||
|
|
||||||
@ -697,9 +759,6 @@ struct iperf_stream *iperf_new_stream(struct iperf_test *testp)
|
|||||||
sp->result->bytes_sent = 0;
|
sp->result->bytes_sent = 0;
|
||||||
gettimeofday(&sp->result->start_time, NULL);
|
gettimeofday(&sp->result->start_time, NULL);
|
||||||
|
|
||||||
sp->result->interval_results->bytes_transferred = 0;
|
|
||||||
sp->result->interval_results->interval_duration = 0;
|
|
||||||
|
|
||||||
sp->settings->state = STREAM_BEGIN;
|
sp->settings->state = STREAM_BEGIN;
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
@ -980,7 +1039,6 @@ void iperf_run_server(struct iperf_test *test)
|
|||||||
|
|
||||||
if( message == ALL_STREAMS_END )
|
if( message == ALL_STREAMS_END )
|
||||||
{
|
{
|
||||||
n->settings->state = ALL_STREAMS_END;
|
|
||||||
test->default_settings->state = RESULT_REQUEST;
|
test->default_settings->state = RESULT_REQUEST;
|
||||||
|
|
||||||
read = test->reporter_callback(test);
|
read = test->reporter_callback(test);
|
||||||
|
@ -4,8 +4,9 @@ struct iperf_interval_results
|
|||||||
{
|
{
|
||||||
iperf_size_t bytes_transferred;
|
iperf_size_t bytes_transferred;
|
||||||
int interval_duration;
|
int interval_duration;
|
||||||
void * custom_data;
|
|
||||||
struct iperf_interval_results *next;
|
struct iperf_interval_results *next;
|
||||||
|
|
||||||
|
void * custom_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct iperf_stream_result
|
struct iperf_stream_result
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user