Show user/system CPU usage as well as total.
Этот коммит содержится в:
родитель
fba44572d7
Коммит
056361fc5d
@ -179,8 +179,8 @@ struct iperf_test
|
||||
Timer *stats_timer;
|
||||
Timer *reporter_timer;
|
||||
|
||||
double cpu_util; /* cpu utilization of the test */
|
||||
double remote_cpu_util; /* cpu utilization for the remote host/client */
|
||||
double cpu_util[3]; /* cpu utilization of the test - total, user, system */
|
||||
double remote_cpu_util[3]; /* cpu utilization for the remote host/client - total, user, system */
|
||||
|
||||
int num_streams; /* total streams in the test (-P) */
|
||||
|
||||
|
@ -1102,7 +1102,9 @@ send_results(struct iperf_test *test)
|
||||
i_errno = IEPACKAGERESULTS;
|
||||
r = -1;
|
||||
} else {
|
||||
cJSON_AddFloatToObject(j, "cpu_util", test->cpu_util);
|
||||
cJSON_AddFloatToObject(j, "cpu_util_total", test->cpu_util[0]);
|
||||
cJSON_AddFloatToObject(j, "cpu_util_user", test->cpu_util[1]);
|
||||
cJSON_AddFloatToObject(j, "cpu_util_system", test->cpu_util[2]);
|
||||
if ( ! test->sender )
|
||||
sender_has_retransmits = -1;
|
||||
else
|
||||
@ -1148,7 +1150,9 @@ get_results(struct iperf_test *test)
|
||||
{
|
||||
int r = 0;
|
||||
cJSON *j;
|
||||
cJSON *j_cpu_util;
|
||||
cJSON *j_cpu_util_total;
|
||||
cJSON *j_cpu_util_user;
|
||||
cJSON *j_cpu_util_system;
|
||||
cJSON *j_sender_has_retransmits;
|
||||
int result_has_retransmits;
|
||||
cJSON *j_streams;
|
||||
@ -1171,13 +1175,17 @@ get_results(struct iperf_test *test)
|
||||
i_errno = IERECVRESULTS;
|
||||
r = -1;
|
||||
} else {
|
||||
j_cpu_util = cJSON_GetObjectItem(j, "cpu_util");
|
||||
j_cpu_util_total = cJSON_GetObjectItem(j, "cpu_util_total");
|
||||
j_cpu_util_user = cJSON_GetObjectItem(j, "cpu_util_user");
|
||||
j_cpu_util_system = cJSON_GetObjectItem(j, "cpu_util_system");
|
||||
j_sender_has_retransmits = cJSON_GetObjectItem(j, "sender_has_retransmits");
|
||||
if (j_cpu_util == NULL || j_sender_has_retransmits == NULL) {
|
||||
if (j_cpu_util_total == NULL || j_cpu_util_user == NULL || j_cpu_util_system == NULL || j_sender_has_retransmits == NULL) {
|
||||
i_errno = IERECVRESULTS;
|
||||
r = -1;
|
||||
} else {
|
||||
test->remote_cpu_util = j_cpu_util->valuefloat;
|
||||
test->remote_cpu_util[0] = j_cpu_util_total->valuefloat;
|
||||
test->remote_cpu_util[1] = j_cpu_util_user->valuefloat;
|
||||
test->remote_cpu_util[2] = j_cpu_util_system->valuefloat;
|
||||
result_has_retransmits = j_sender_has_retransmits->valueint;
|
||||
if (! test->sender)
|
||||
test->sender_has_retransmits = result_has_retransmits;
|
||||
@ -1833,9 +1841,9 @@ iperf_print_results(struct iperf_test *test)
|
||||
}
|
||||
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(test->json_end, "cpu_utilization_percent", iperf_json_printf("host: %f remote: %f", (double) test->cpu_util, (double) test->remote_cpu_util));
|
||||
cJSON_AddItemToObject(test->json_end, "cpu_utilization_percent", iperf_json_printf("host_total: %f host_user: %f host_system: %f remote_total: %f remote_user: %f remote_system: %f", (double) test->cpu_util[0], (double) test->cpu_util[1], (double) test->cpu_util[2], (double) test->remote_cpu_util[0], (double) test->remote_cpu_util[1], (double) test->remote_cpu_util[2]));
|
||||
else if (test->verbose)
|
||||
iprintf(test, report_cpu, report_local, test->sender?report_sender:report_receiver, test->cpu_util, report_remote, test->sender?report_receiver:report_sender, test->remote_cpu_util);
|
||||
iprintf(test, report_cpu, report_local, test->sender?report_sender:report_receiver, test->cpu_util[0], test->cpu_util[1], test->cpu_util[2], report_remote, test->sender?report_receiver:report_sender, test->remote_cpu_util[0], test->remote_cpu_util[1], test->remote_cpu_util[2]);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -438,7 +438,7 @@ iperf_run_client(struct iperf_test * test)
|
||||
continue; /* not done */
|
||||
}
|
||||
/* Yes, done! Send TEST_END. */
|
||||
cpu_util(&test->cpu_util);
|
||||
cpu_util(test->cpu_util);
|
||||
test->stats_callback(test);
|
||||
if (iperf_set_send_state(test, TEST_END) != 0)
|
||||
return -1;
|
||||
|
@ -181,7 +181,7 @@ iperf_handle_message_server(struct iperf_test *test)
|
||||
case TEST_START:
|
||||
break;
|
||||
case TEST_END:
|
||||
cpu_util(&test->cpu_util);
|
||||
cpu_util(test->cpu_util);
|
||||
test->stats_callback(test);
|
||||
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||
FD_CLR(sp->socket, &test->read_set);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
@ -157,27 +158,39 @@ delay(int us)
|
||||
|
||||
|
||||
void
|
||||
cpu_util(double *pcpu)
|
||||
cpu_util(double pcpu[3])
|
||||
{
|
||||
static struct timeval last;
|
||||
static clock_t clast;
|
||||
static struct rusage rlast;
|
||||
struct timeval temp;
|
||||
clock_t ctemp;
|
||||
struct rusage rtemp;
|
||||
double timediff;
|
||||
double userdiff;
|
||||
double systemdiff;
|
||||
|
||||
if (pcpu == NULL) {
|
||||
gettimeofday(&last, NULL);
|
||||
clast = clock();
|
||||
getrusage(RUSAGE_SELF, &rlast);
|
||||
return;
|
||||
}
|
||||
|
||||
gettimeofday(&temp, NULL);
|
||||
ctemp = clock();
|
||||
getrusage(RUSAGE_SELF, &rtemp);
|
||||
|
||||
timediff = ((temp.tv_sec * 1000000.0 + temp.tv_usec) -
|
||||
(last.tv_sec * 1000000.0 + last.tv_usec));
|
||||
(last.tv_sec * 1000000.0 + last.tv_usec));
|
||||
userdiff = ((rtemp.ru_utime.tv_sec * 1000000.0 + rtemp.ru_utime.tv_usec) -
|
||||
(rlast.ru_utime.tv_sec * 1000000.0 + rlast.ru_utime.tv_usec));
|
||||
systemdiff = ((rtemp.ru_stime.tv_sec * 1000000.0 + rtemp.ru_stime.tv_usec) -
|
||||
(rlast.ru_stime.tv_sec * 1000000.0 + rlast.ru_stime.tv_usec));
|
||||
|
||||
*pcpu = ((ctemp - clast) / timediff) * 100;
|
||||
pcpu[0] = ((ctemp - clast) / timediff) * 100;
|
||||
pcpu[1] = (userdiff / timediff) * 100;
|
||||
pcpu[2] = (systemdiff / timediff) * 100;
|
||||
}
|
||||
|
||||
char*
|
||||
|
@ -24,7 +24,7 @@ double timeval_diff(struct timeval *tv0, struct timeval *tv1);
|
||||
|
||||
int delay(int64_t ns);
|
||||
|
||||
void cpu_util(double *);
|
||||
void cpu_util(double pcpu[3]);
|
||||
|
||||
char* get_system_info(void);
|
||||
|
||||
|
@ -279,7 +279,7 @@ const char reportCSV_peer[] =
|
||||
"%s,%u,%s,%u";
|
||||
|
||||
const char report_cpu[] =
|
||||
"CPU Utilization: %s/%s %.1f%%, %s/%s %.1f%%\n";
|
||||
"CPU Utilization: %s/%s %.1f%% (%.1f%%u/%.1f%%s), %s/%s %.1f%% (%.1f%%u/%.1f%%s)\n";
|
||||
|
||||
const char report_local[] = "local";
|
||||
const char report_remote[] = "remote";
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user