1tcp_mem_stats.c : FreeRTOS+TCP Memory Statistics
2
3This module can be used in any project on any platform that uses FreeRTOS+TCP.
4
5It creates an overview of the memory usage of FreeRTOS+TCP.
6It reports the static use of RAM, and also the dynamic usage ( heap ).
7It relates these numbers to the macro's defined `FreeRTOSIPConfig.h`.
8
9It writes CSV records to the logging with configPRINTF().
10
11The resulting log can be filtered by e.g.:
12
13	cat logging.txt | grep ".*TCPMemStat," | sed "s/.*TCPMemStat,//"
14
15The resulting text can be imported into any spreadsheet at cell "A1" ( top-left ):
16
17    ipconfig item,Value,PerUnit,Total
18    NUM_NETWORK_BUFFER_DESCRIPTORS,12,60,=B13*C13,Descriptors only
19    TCP_WIN_SEG_COUNT,32,64,=B14*C14
20    EVENT_QUEUE_LENGTH,17,8,=B15*C15
21    IP_TASK_STACK_SIZE_WORDS,300,4,=B16*C16
22
23When the CSV-records are imported at another row or column than "A1", the formulas will be incorrect.
24
25How to include 'tcp_mem_stats' into a project:
26
27● Add tools/tcp_sources/tcp_mem_stats.c to the sources
28● Add the following lines to FreeRTOSIPConfig.h :
29	#define ipconfigUSE_TCP_MEM_STATS					( 1 )
30	#define ipconfigTCP_MEM_STATS_MAX_ALLOCATION		( 128 )
31	#include "tools/tcp_sources/include/tcp_mem_stats.h"
32
33Later on, the module can disabled by setting `#define ipconfigUSE_TCP_MEM_STATS 0`.
34
35`ipconfigTCP_MEM_STATS_MAX_ALLOCATION` is the maximum number of objects that can be followed at any time.
36A socket that has 2 stream buffers counts as 3 objects ( needing 3 x 16 = 48 bytes to store their properties ).
37
38The **summary** at the bottom will only be written when `iptraceMEM_STATS_CLOSE()` is called.
39The application is responsible for calling `iptraceMEM_STATS_CLOSE()`.
40The summary at the bottom looks like this:
41
42	Totals,,,=MAX(D25:D31),,=MIN(F25:F31),=MAX(G25:G31)
43	Maximum RAM usage:,,,=SUM(D20;D32)
44
45The spreadsheet can be edited further to make estimations with different macro values.
46