Skip to content

Commit

Permalink
Add textual description of the State in the debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Jul 17, 2024
1 parent 41dba5f commit 218e072
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,8 @@ int
iperf_set_send_state(struct iperf_test *test, signed char state)
{
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: sending and setting State to %d (control socket is %d)\n", state, test->ctrl_sck);
iperf_printf(test, "State change: sending and setting State to %d - %s (control socket is %d)\n",
state, state_to_text(state), test->ctrl_sck);
}

if (test->ctrl_sck >= 0) {
Expand Down Expand Up @@ -4751,13 +4752,19 @@ iperf_got_sigend(struct iperf_test *test)
cpu_util(test->cpu_util);
test->stats_callback(test);
test->state = DISPLAY_RESULTS; /* change local state only */
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state));
}
if (test->on_test_finish)
test->on_test_finish(test);
test->reporter_callback(test);
}

if (test->ctrl_sck >= 0) {
test->state = (test->role == 'c') ? CLIENT_TERMINATE : SERVER_TERMINATE;
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state));
}
(void) Nwrite(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp);
}
i_errno = (test->role == 'c') ? IECLIENTTERM : IESERVERTERM;
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ iperf_handle_message_client(struct iperf_test *test)
}

if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: client received State %d\n", test->state);
iperf_printf(test, "State change: client received State %d - %s\n", test->state, state_to_text(test->state));
}

switch (test->state) {
Expand Down
11 changes: 10 additions & 1 deletion src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ iperf_handle_message_server(struct iperf_test *test)
iperf_err(test, "the client has unexpectedly closed the connection");
i_errno = IECTRLCLOSE;
test->state = IPERF_DONE;
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state));
}
return 0;
} else {
i_errno = IERECVMESSAGE;
Expand All @@ -231,7 +234,7 @@ iperf_handle_message_server(struct iperf_test *test)
}

if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: server received State %d\n", test->state);
iperf_printf(test, "State change: server received State %d - %s\n", test->state, state_to_text(test->state));
}

switch(test->state) {
Expand Down Expand Up @@ -277,6 +280,9 @@ iperf_handle_message_server(struct iperf_test *test)
close(sp->socket);
}
test->state = IPERF_DONE;
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state));
}
break;
default:
i_errno = IEMESSAGE;
Expand Down Expand Up @@ -553,6 +559,9 @@ iperf_run_server(struct iperf_test *test)
last_receive_blocks = 0;

test->state = IPERF_START;
if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state));
}
send_streams_accepted = 0;
rec_streams_accepted = 0;
rcv_timeout_us = (test->settings->rcv_timeout.secs * SEC_TO_US) + test->settings->rcv_timeout.usecs;
Expand Down
3 changes: 2 additions & 1 deletion src/iperf_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "iperf.h"
#include "iperf_api.h"
#include "iperf_tcp.h"
#include "iperf_util.h"
#include "net.h"
#include "cjson.h"

Expand Down Expand Up @@ -69,7 +70,7 @@ iperf_tcp_recv(struct iperf_stream *sp)
}
else {
if (sp->test->debug)
printf("Late receive, state = %d\n", sp->test->state);
printf("Late receive, state = %d - %s\n", sp->test->state, state_to_text(sp->test->state));
}

return r;
Expand Down
26 changes: 26 additions & 0 deletions src/iperf_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,29 @@ getline(char **buf, size_t *bufsiz, FILE *fp)
}

#endif

/* Translate numeric State to text - for debugging pupposes */
char *
state_to_text(signed char state)
{
char *txt;

switch (state) {
case 1: txt = "Starting a Test"; break;
case 2: txt = "Test is Running"; break;
case 4: txt = "Test Ended"; break;
case 9: txt = "Client to Server Parameters Exchange"; break;
case 10: txt = "Creating Streams"; break;
case 11: txt = "Server Terminated"; break;
case 12: txt = "Client Terminated"; break;
case 13: txt = "Exchanging Results"; break;
case 14: txt = "Displaying Results"; break;
case 15: txt = "Starting"; break;
case 16: txt = "Done"; break;
case -1: txt = "Error"; break;
case -2: txt = "Serevr Error"; break;
default: txt = "Unknown State";
}

return txt;
}
2 changes: 2 additions & 0 deletions src/iperf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ extern int daemon(int nochdir, int noclose);
ssize_t getline(char **buf, size_t *bufsiz, FILE *fp);
#endif /* HAVE_GETLINE */

char * state_to_text(signed char state);

#endif

0 comments on commit 218e072

Please sign in to comment.