From 5a10c0e8e7e065c55334632457726f6ec023322e Mon Sep 17 00:00:00 2001 From: Adam Feuer Date: Mon, 24 Feb 2020 17:00:08 -0800 Subject: [PATCH] tcpblaster reporting and docs improvements - changed incorrect Kb to correct KB in program output - added readme Squashed commit of the following: commit b81821fd788eb08ffdf5a3084ab3d128788b75da Author: Adam Feuer Date: Mon Feb 24 16:58:29 2020 -0800 formatting improvements commit a70e7109dd90522e6d7f680790d80c9328a8ba9c Author: Adam Feuer Date: Mon Feb 24 16:58:13 2020 -0800 formatting improvements commit c11a5b3c8ee38fe080d121db87b7d26c0baf9f93 Author: Adam Feuer Date: Sun Feb 23 17:03:22 2020 -0800 remove printf debugging statement commit 94bcaa89d2df326ed2b560e935d344932c46607d Merge: fddb3ee4 d6604922 Author: Adam Feuer Date: Sun Feb 23 16:58:35 2020 -0800 Merge branch 'master' into feature/tcpblaster-improvements commit fddb3ee4ee9ba185f0f4e01c205620bbcb02e40e Author: Adam Feuer Date: Sat Feb 22 16:29:51 2020 -0800 fixed typo commit d398d6f3803d81e849814548be9671ac33f08168 Author: Adam Feuer Date: Sat Feb 22 16:29:04 2020 -0800 logging now has timestamp; improved configuration --- examples/tcpblaster/Kconfig | 9 +++++- examples/tcpblaster/Makefile | 2 +- examples/tcpblaster/README.txt | 40 +++++++++++++++++++++++++ examples/tcpblaster/tcpblaster.h | 6 ++++ examples/tcpblaster/tcpblaster_client.c | 19 ++++++++---- examples/tcpblaster/tcpblaster_server.c | 18 +++++++---- 6 files changed, 80 insertions(+), 14 deletions(-) create mode 100755 examples/tcpblaster/README.txt diff --git a/examples/tcpblaster/Kconfig b/examples/tcpblaster/Kconfig index c002ef7f6..470487c64 100644 --- a/examples/tcpblaster/Kconfig +++ b/examples/tcpblaster/Kconfig @@ -17,7 +17,14 @@ config EXAMPLES_TCPBLASTER_SENDSIZE int "Payload size" default 4096 ---help--- - This setting determines size of each test packet sent to the server. + This setting determines size of each TCP send that is sent to the server. + +config EXAMPLES_TCPBLASTER_GROUPSIZE + int "Group size" + default 50 + ---help--- + This setting determines how many TCP sends are sent to the server before printing statistics + and starting again. config EXAMPLES_TCPBLASTER_PROGNAME1 string "Target1 program name" diff --git a/examples/tcpblaster/Makefile b/examples/tcpblaster/Makefile index 099c2b91e..fe09cbc4c 100644 --- a/examples/tcpblaster/Makefile +++ b/examples/tcpblaster/Makefile @@ -11,7 +11,7 @@ # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in +# notice, this list of conditions and the following dsclaimer in # the documentation and/or other materials provided with the # distribution. # 3. Neither the name NuttX nor the names of its contributors may be diff --git a/examples/tcpblaster/README.txt b/examples/tcpblaster/README.txt new file mode 100755 index 000000000..86ff00ac6 --- /dev/null +++ b/examples/tcpblaster/README.txt @@ -0,0 +1,40 @@ +tcpblaster Performance Test Example +=================================== + +To set up, do `make menuconfig` and select the Apps > Examples > tcpblaster. By default, nuttx will the be the client +which sends data; and the host computer (Linux, macOS, or Windows) will be the server. + +Set up networking so the nuttx computer can ping the host, and the host can ping nuttx. Now you are ready to run the +test. + +On host: + + $ ./tcpserver + Binding to IPv4 Address: 00000000 + server: Accepting connections on port 5471 + +On nuttx: + + nsh> tcpclient + Connecting to IPv4 Address: 0100000a + client: Connected + [2014-07-31 00:16:15.000] 0: Sent 200 4096-byte buffers: 800.0 KB (avg 4.0 KB) in 0.18 seconds ( 4444.4 KB/second) + +Now on the host you should see something like: + + $ ./tcpserver + Binding to IPv4 Address: 00000000 + server: Accepting connections on port 5471 + server: Connection accepted -- receiving + [2020-02-22 16:17:07.000] 0: Received 200 buffers: 502.9 KB (buffer average size: 2.5 KB) in 0.12 seconds ( 4194.8 KB/second) + [2020-02-22 16:17:07.000] 1: Received 200 buffers: 393.1 KB (buffer average size: 2.0 KB) in 0.09 seconds ( 4299.4 KB/second) + + +This will tell you the link speed in KB/sec – kilobytes per second. If you want kilobits, multiply by 8. + +You can use the `make menuconfig` to reverse the setup, and have nuttx be the server, and the host be the client. If you +do that, start the server first (nuttx), then start the client (host). + + + + diff --git a/examples/tcpblaster/tcpblaster.h b/examples/tcpblaster/tcpblaster.h index eafdf448f..7925d6a44 100644 --- a/examples/tcpblaster/tcpblaster.h +++ b/examples/tcpblaster/tcpblaster.h @@ -115,6 +115,12 @@ # define SENDSIZE 4096 #endif +#ifdef CONFIG_EXAMPLES_TCPBLASTER_GROUPSIZE +# define GROUPSIZE CONFIG_EXAMPLES_TCPBLASTER_GROUPSIZE +#else +# define GROUPSIZE 50 +#endif + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/examples/tcpblaster/tcpblaster_client.c b/examples/tcpblaster/tcpblaster_client.c index 4d89853d0..701eabe7c 100644 --- a/examples/tcpblaster/tcpblaster_client.c +++ b/examples/tcpblaster/tcpblaster_client.c @@ -70,13 +70,18 @@ void tcpblaster_client(void) FAR char *outbuf; unsigned long sendtotal; unsigned long totallost; + int groupcount; int sendcount; int partials; int sockfd; int nbytessent; int ch; int i; + char timebuff[100]; + + setbuf(stdout, NULL); + /* Allocate buffers */ outbuf = (FAR char *)malloc(SENDSIZE); @@ -142,6 +147,7 @@ void tcpblaster_client(void) /* Then send messages forever */ + groupcount = 0; sendcount = 0; sendtotal = 0; partials = 0; @@ -200,7 +206,7 @@ void tcpblaster_client(void) sendtotal += nbytessent; - if (++sendcount >= 50) + if (++sendcount >= GROUPSIZE) { struct timespec elapsed; struct timespec curr; @@ -221,12 +227,12 @@ void tcpblaster_client(void) elapsed.tv_nsec = curr.tv_nsec + borrow; } - fkbrecvd = (float)sendtotal / 1024.0; + strftime(timebuff, 100, "%Y-%m-%d %H:%M:%S.000", localtime (&curr)); + + fkbrecvd = (float)sendtotal / 1024.0; felapsed = (float)elapsed.tv_sec + (float)elapsed.tv_nsec / 1000000000.0; - printf("Sent %d buffers: %7.1f Kb (avg %5.1f Kb) in " - "%6.2f Sec (%7.1f Kb/Sec)\n", - sendcount, fkbrecvd, fkbrecvd / sendcount, felapsed, - fkbrecvd / felapsed); + printf("[%s] %d: Sent %d %d-byte buffers: %7.1f KB (avg %5.1f KB) in %6.2f seconds (%7.1f KB/second)\n", + timebuff, groupcount, sendcount, SENDSIZE, fkbrecvd, fkbrecvd/sendcount, felapsed, fkbrecvd/felapsed); if (partials > 0) { @@ -241,6 +247,7 @@ void tcpblaster_client(void) sendtotal = 0; partials = 0; totallost = 0; + groupcount++; clock_gettime(CLOCK_REALTIME, &start); } diff --git a/examples/tcpblaster/tcpblaster_server.c b/examples/tcpblaster/tcpblaster_server.c index 39b8dd15a..6f9f75345 100644 --- a/examples/tcpblaster/tcpblaster_server.c +++ b/examples/tcpblaster/tcpblaster_server.c @@ -72,12 +72,16 @@ void tcpblaster_server(void) struct timespec start; unsigned long recvtotal; socklen_t addrlen; - FAR char *buffer; + char *buffer; + int groupcount; int recvcount; int listensd; int acceptsd; int nbytesread; int optval; + char timebuff[100]; + + setbuf(stdout, NULL); /* Allocate a BIG buffer */ @@ -184,6 +188,7 @@ void tcpblaster_server(void) recvcount = 0; recvtotal = 0; + groupcount = 0; clock_gettime(CLOCK_REALTIME, &start); @@ -227,7 +232,7 @@ void tcpblaster_server(void) recvtotal += nbytesread; - if (++recvcount >= 50) + if (++recvcount >= GROUPSIZE) { struct timespec elapsed; struct timespec curr; @@ -248,15 +253,16 @@ void tcpblaster_server(void) elapsed.tv_nsec = curr.tv_nsec + borrow; } + strftime(timebuff, 100, "%Y-%m-%d %H:%M:%S.000", localtime (&curr)); + fkbsent = (float)recvtotal / 1024.0; felapsed = (float)elapsed.tv_sec + (float)elapsed.tv_nsec / 1000000000.0; - printf("Received %d buffers: %7.1f Kb (avg %5.1f Kb) in " - "%6.2f Sec (%7.1f Kb/Sec)\n", - recvcount, fkbsent, fkbsent / recvcount, felapsed, - fkbsent / felapsed); + printf("[%s] %d: Received %d buffers: %7.1f KB (buffer average size: %5.1f KB) in %6.2f seconds (%7.1f KB/second)\n", + timebuff, groupcount, recvcount, fkbsent, fkbsent/recvcount, felapsed, fkbsent/felapsed); recvcount = 0; recvtotal = 0; + groupcount++; clock_gettime(CLOCK_REALTIME, &start); }