Added CPU utilization exchange and display (use verbose mode [-V]).

This commit is contained in:
sethdelliott 2011-03-02 21:32:04 +00:00
parent 3331e801b9
commit ad426c6fd4
3 changed files with 46 additions and 3 deletions

View File

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

View File

@ -734,6 +734,16 @@ iperf_exchange_results(struct iperf_test *test)
/* Prepare results string and send to server */
results = NULL;
size = 0;
snprintf(buf, 128, "-C %f\n", test->cpu_util);
size += strlen(buf);
if ((results = malloc(size+1)) == NULL) {
i_errno = IEPACKAGERESULTS;
return (-1);
}
*results = '\0';
strncat(results, buf, size+1);
SLIST_FOREACH(sp, &test->streams, streams) {
bytes_transferred = (test->reverse ? sp->result->bytes_received : sp->result->bytes_sent);
snprintf(buf, 128, "%d:%llu,%lf,%d,%d\n", sp->id, bytes_transferred,sp->jitter,
@ -743,8 +753,10 @@ iperf_exchange_results(struct iperf_test *test)
i_errno = IEPACKAGERESULTS;
return (-1);
}
/*
if (sp == SLIST_FIRST(&test->streams))
*results = '\0';
*/
strncat(results, buf, size+1);
}
size++;
@ -807,6 +819,16 @@ iperf_exchange_results(struct iperf_test *test)
/* Prepare results string and send to client */
results = NULL;
size = 0;
snprintf(buf, 128, "-C %f\n", test->cpu_util);
size += strlen(buf);
if ((results = malloc(size+1)) == NULL) {
i_errno = IEPACKAGERESULTS;
return (-1);
}
*results = '\0';
strncat(results, buf, size+1);
SLIST_FOREACH(sp, &test->streams, streams) {
bytes_transferred = (test->reverse ? sp->result->bytes_sent : sp->result->bytes_received);
snprintf(buf, 128, "%d:%llu,%lf,%d,%d\n", sp->id, bytes_transferred, sp->jitter,
@ -816,8 +838,10 @@ iperf_exchange_results(struct iperf_test *test)
i_errno = IEPACKAGERESULTS;
return (-1);
}
/*
if (sp == SLIST_FIRST(&test->streams))
*results = '\0';
*/
strncat(results, buf, size+1);
}
size++;
@ -845,10 +869,22 @@ parse_results(struct iperf_test *test, char *results)
int sid, cerror, pcount;
double jitter;
char *strp;
char *tok;
iperf_size_t bytes_transferred;
struct iperf_stream *sp;
for (strp = results; *strp; strp = strchr(strp, '\n')+1) {
/* Isolate the first line */
strp = strchr(results, '\n');
*strp = '\0';
strp++;
for (tok = strtok(results, " "); tok; tok = strtok(NULL, " ")) {
if (strcmp(tok, "-C") == 0) {
test->remote_cpu_util = atof(strtok(NULL, " "));
}
}
for (strp; *strp; strp = strchr(strp, '\n')+1) {
sscanf(strp, "%d:%llu,%lf,%d,%d\n", &sid, &bytes_transferred, &jitter,
&cerror, &pcount);
SLIST_FOREACH(sp, &test->streams, streams)
@ -1263,6 +1299,11 @@ iperf_reporter_callback(struct iperf_test * test)
lost_packets, total_packets, (double) (100.0 * lost_packets / total_packets));
}
}
if (test->verbose) {
printf("Host CPU Utilization: %.1f%%\n", test->cpu_util);
printf("Remote CPU Utilization: %.1f%%\n", test->remote_cpu_util);
}
break;
}

View File

@ -176,6 +176,6 @@ cpu_util(double *pcpu)
timediff = ((temp.tv_sec * 1000000.0 + temp.tv_usec) -
(last.tv_sec * 1000000.0 + last.tv_usec));
return ((ctemp - clast) / timediff);
*pcpu = ((ctemp - clast) / timediff) * 100;
}