[Task-ID: ODUHIGH-485] Memory Leak Detector Tool
[o-du/l2.git] / tools / Memory_Leak_Detector / README
1 Overview:
2 This tool is used to identify memory leaks and invalid memory-handling operations present in ODU-High code. It helps in resolving segmentation fault and undefinded behaviour occuring due to memory corruption.
3  
4 Execution Steps
5 1. Enable the platform flag in makefile of ODU-H binary.
6    a. vim l2/build/odu/makefile
7    b. Update the following line to enable flag "ODU_MEMORY_DEBUG_LOG"
8          PLTFRM_FLAGS= -UMSPD -DODU -DINTEL_FAPI -DODU_MEMORY_DEBUG_LOG
9  
10 2. Enable the CLA use-case in ODU-H flow i.e. add the trigger to bring the cell down.
11    (This is a hack to help us execute the complete scenario from Cell up to Down so that we can capture the memory status between them)
12    a. vim l2/src/du_app/du_egtp.c
13       In function egtpRecvMsg(), disable the infinite loop (while loop) of receiver EGTP thread.
14      
15    b. vim l2/src/du_app/du_f1ap_msg_hdl.c
16       At the end of BuildAndSendUeContextModRsp() i.e. after sending UE Context Modification Response, add following line :
17         BuildAndSendDUConfigUpdate(SERV_CELL_TO_DELETE);
18         
19 2. Compile and generate all the three binaries : ODU, CU_STUB and RIC_STUB
20  
21 3. Execute the RIC_STUB and CU_STUB binaries first. Then execute ODU and capture its console logs.
22    
23 4. Once CELL down is complete at ODU, stop/kill the ODU binary and save the log file.
24  
25 5. Download this log file in your local system. Here we will segregate the logs for memory allocation and memory free.
26    
27    a. Download Text Editor tool "TextAnalysisTool.NET.exe" placed at : 
28       https://radisyscorp.sharepoint.com/sites/ODU/Shared%20Documents/General/Tools/TextAnalysisTool.NET.exe
29    b. Execute the tool and open the log file in this tool(File->Open)
30    c. Filter out the ALLOC and FREE log prints by following steps:
31         i. Filters -> Add New Filters. In the Pop-up window, enter "ALLOC". Check the box to enable "Case-sensitive". Press OK to add this filter. 
32         ii. Repeat this step for "FREE" keyword
33         iii. Go to "View -> Show only Filtered Lines". 
34         iv. Now enable ALLOC filters by clicking on the checkbox. The result will show only those lines from log_file 
35              that contain substring "ALLOC". Copy all the filtered lines in excel sheet 1.
36         v. Uncheck filter for ALLOC and check the filter for FREE. The newly filtered lines show logs for memory free. 
37             Copy these lines to excel sheet 2.
38        
39    d. We need to filter out only memory size and address from filtered data copied to excel sheet
40         i. In excel, go to "Data ->  Text to Columns". A pop-up window will show.
41           Step 1 : Choose "Delimited" , CLick Next>
42           Step 2 : Enable following Delimiters 
43                     Tabs, Semicolon, Comma
44           Step 3 : Click Finish
45         ii. Repeat above steps for both sheets
46         iii. Delete columns C and D to remove unwanted text. Now, the allocation/free type, size and address will be in columns B, C and D. 
47                Copy all rows containing data of these columns (Ctrl+shift+Down arrow).
48        
49 6. Now we will pass the filtered data (from excel sheet) into Memory_Leak_Detetctor
50    a. Remove/delete following output files, if present from previous executions : "freeoutput.txt" and "allocoutput.txt"
51    b. Clean alloc.txt file for any prevoius entries. Now paste here, columns B, C and D copied from excel sheet 1.
52    c. Remove any double spaces in alloc.txt using vi editor command (:%s/  / /g). Use this command twice.
53    d. Follow above two steps for file "free.txt". 
54    e. Execute ./a.out . Output files "freeoutput.txt" and "allocoutput.txt" are generated.
55     
56 7. Ideally, "freeoutput.txt" and "allocoutput.txt"  should be empty. 
57    a. Any entry in freeoutput.txt shows a memory block which is freed without any prior allocation.
58    b. Any entry in allocoutput.txt shows a memory leak i.e. a memory block which was allocated but not freed.
59     
60 NOTE : Some static memory blocks are allocated when the stack is intitialized. These are freed only when the binary is 
61        stopped/killed. Since we are executing our binary up to cell down, these initially alloacted memory are not yet
62        freed and will be visible in allocoutput.txt. We can ignored these.
63      
64        However, "freeoutput.txt" must be empty.
65