Added portable CPU utilization code. Still need to exchange utilizations between client and server.

This commit is contained in:
sethdelliott 2011-02-24 17:08:54 +00:00
parent 9286415c86
commit 3331e801b9
5 changed files with 36 additions and 1 deletions

View File

@ -149,7 +149,7 @@ struct iperf_test
struct timer *timer;
struct timer *stats_timer;
struct timer *reporter_timer;
double cpu_util; /* cpu utilization of the test */
int num_streams; /* total streams in the test (-P) */

View File

@ -179,6 +179,9 @@ iperf_run_client(struct iperf_test * test)
return (-1);
}
// Begin calculating CPU utilization
cpu_util(NULL);
while (test->state != IPERF_DONE) {
memcpy(&temp_read_set, &test->read_set, sizeof(fd_set));
@ -226,6 +229,7 @@ iperf_run_client(struct iperf_test * test)
/* Send TEST_END if all data has been sent or timer expired */
if (all_data_sent(test) || timer_expired(test->timer)) {
cpu_util(&test->cpu_util);
test->stats_callback(test);
test->state = TEST_END;
if (Nwrite(test->ctrl_sck, &test->state, sizeof(char), Ptcp) < 0) {

View File

@ -168,6 +168,7 @@ iperf_handle_message_server(struct iperf_test *test)
case TEST_START:
break;
case TEST_END:
cpu_util(&test->cpu_util);
test->stats_callback(test);
SLIST_FOREACH(sp, &test->streams, streams) {
FD_CLR(sp->socket, &test->read_set);
@ -276,6 +277,9 @@ iperf_run_server(struct iperf_test *test)
return (-1);
}
// Begin calculating CPU utilization
cpu_util(NULL);
test->state = IPERF_START;
streams_accepted = 0;

View File

@ -154,3 +154,28 @@ timer_remaining(struct timer * tp)
else
return 0;
}
void
cpu_util(double *pcpu)
{
static struct timeval last;
static clock_t clast;
struct timeval temp;
clock_t ctemp;
double timediff;
if (pcpu == NULL) {
gettimeofday(&last, NULL);
clast = clock();
return;
}
gettimeofday(&temp, NULL);
ctemp = clock();
timediff = ((temp.tv_sec * 1000000.0 + temp.tv_usec) -
(last.tv_sec * 1000000.0 + last.tv_usec));
return ((ctemp - clast) / timediff);
}

View File

@ -26,4 +26,6 @@ void free_timer(struct timer *tp);
int timer_expired(struct timer *);
void cpu_util(double *);
#endif