Memory Usage
Command Function
Collects performance data about memory allocation and release, and checks whether any allocated memory space has not been released.
Syntax
1 | devkit doctor memalloc [-h] [-l {0,1,2,3}] [--package] [-o <file>] [-d <sec>] [-i <sec>] [-t n] [-z <byte>] [-Z <byte>] [-p PID] [workload ...] |
- The tool can collect data of a specified application. Replace [workload workload...] in the command with the application path and application parameter.
- This command is unavailable on SUSE Linux.
- This function is implemented based on the eBPF capability. The root user is used for data collection. For details about how to check whether the environment meets the requirements, see Checking the eBPF Environment.
Parameter Description
Parameter |
Option |
Description |
|---|---|---|
-h/--help |
- |
Obtains help information. This parameter is optional. |
-l/--log-level |
0/1/2/3 |
Log level, which defaults to 2. This parameter is optional.
NOTE:
The default level is 2 (WARNING).
|
--package |
- |
Indicates whether to import data to the database and generate compressed packages in the specified output path. This parameter is optional. |
-o/--output |
- |
Report package name and output path. If you enter a name only, the report package is generated in the current directory by default. This option must be used together with --package. |
-d/--duration |
- |
Collection duration, in seconds. By default collection does not stop until the application stops running. You can press Ctrl+C to stop the collection and start analysis. This parameter is optional. |
-i/--interval |
- |
Collection interval, in seconds. This parameter is optional. The default value is 1 second. The value ranges from 1 to 60 seconds and cannot exceed the collection duration. |
-t/--top |
- |
Maximum number of stacks to be displayed in the report, which defaults to 5 (if the value is less than 5, the actual number of stacks will be displayed). The value ranges from 5 to 15. The report content is sorted by stack size. This parameter is optional. |
-z/--min-size |
- |
Minimum memory usage collected each time, in bytes. The value must be greater than or equal to 1. This parameter is optional. |
-Z/--max-size |
- |
Maximum memory usage collected each time, in bytes. The value must be greater than or equal to 2. This parameter is optional. |
-p/--pid |
- |
ID of the process to be collected, which defaults to -1, indicating that the kernel-mode memory usage is collected. This parameter is optional. |
Example
1 | devkit doctor memalloc -d 5 --package /opt/testdemo/mem_leak |
Command output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | Executing "/opt/testdemo/mem_leak" and tracing the resulting process. Attaching to App, fork pid = 3725254, Ctrl+C to quit. Memory Allocate Summary Report-1 Time:2025/08/18 15:57:21 ================================================================================ No stacks with outstanding allocations. Memory Allocate Summary Report-2 Time:2025/08/18 15:57:22 ================================================================================ Top 1 stacks with outstanding allocations: Top 1 Stack ———————————————————————————————————————————————————————————————————— stack_name mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] stack_id 13704 alloc_size 8192B alloc_count 1 alloc_distribution 8KB-16KB 1 alloc_pid 3725254 stack_info: 0x00000000004007e0 mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] 0x0000000000400848 child+0x3c [/opt/testdemo/mem_leak] [mem_leak.c:21] 0x0000ffffaf45ce4c [unknown] [/usr/lib64/libc.so.6] [unknown] 0x0000ffffaf4c3b0c [unknown] [/usr/lib64/libc.so.6] [unknown] Memory Allocate Summary Report-3 Time:2025/08/18 15:57:23 ================================================================================ Top 1 stacks with outstanding allocations: Top 1 Stack ———————————————————————————————————————————————————————————————————— stack_name mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] stack_id 13704 alloc_size 16384B alloc_count 2 alloc_distribution 8KB-16KB 2 alloc_pid 3725254 stack_info: 0x00000000004007e0 mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] 0x0000000000400848 child+0x3c [/opt/testdemo/mem_leak] [mem_leak.c:21] 0x0000ffffaf45ce4c [unknown] [/usr/lib64/libc.so.6] [unknown] 0x0000ffffaf4c3b0c [unknown] [/usr/lib64/libc.so.6] [unknown] Memory Allocate Summary Report-4 Time:2025/08/18 15:57:24 ================================================================================ Top 1 stacks with outstanding allocations: Top 1 Stack ———————————————————————————————————————————————————————————————————— stack_name mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] stack_id 13704 alloc_size 24576B alloc_count 3 alloc_distribution 8KB-16KB 3 alloc_pid 3725254 stack_info: 0x00000000004007e0 mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] 0x0000000000400848 child+0x3c [/opt/testdemo/mem_leak] [mem_leak.c:21] 0x0000ffffaf45ce4c [unknown] [/usr/lib64/libc.so.6] [unknown] 0x0000ffffaf4c3b0c [unknown] [/usr/lib64/libc.so.6] [unknown] Memory Allocate Summary Report-5 Time:2025/08/18 15:57:25 ================================================================================ Top 1 stacks with outstanding allocations: Top 1 Stack ———————————————————————————————————————————————————————————————————— stack_name mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] stack_id 13704 alloc_size 32768B alloc_count 4 alloc_distribution 8KB-16KB 4 alloc_pid 3725254 stack_info: 0x00000000004007e0 mem_leak+0x1c [/opt/testdemo/mem_leak] [mem_leak.c:9] 0x0000000000400848 child+0x3c [/opt/testdemo/mem_leak] [mem_leak.c:21] 0x0000ffffaf45ce4c [unknown] [/usr/lib64/libc.so.6] [unknown] 0x0000ffffaf4c3b0c [unknown] [/usr/lib64/libc.so.6] [unknown] The report /root/memalloc-20250818-155719.tar is generated successfully. To view summary report. you can run: devkit report -i /root/memalloc-20250818-155719.tar To view detail report. you can import the report to the WebUI or IDE to view details. |
Parameter |
Description |
|---|---|
Top 1 stacks with outstanding allocations |
Information about top N stacks. Only one stack is displayed in the command output because there is only one stack in the demo. |
stack_name |
Stack name of the application. |
stack_id |
Stack ID. |
alloc_size |
Size of memory that has been allocated but not yet released. |
alloc_count |
Number of memory allocations. |
alloc_distribution |
Size and number of memory blocks. |
alloc_pid |
Process ID. |
stack_info |
Detailed stack information, including the call stack address, call stack name, module, and code line number. |
In the command output, the value of alloc_size increases over time, a memory leak may occur. If "[mem_leak.c:9]" is displayed in the stack_name and stack_info parts, a memory leak occurs in the 9th line of the mem_leak.c file. After making the necessary modifications, you can use the tool to verify whether the issue has been resolved.
Use the --package parameter to generate a TAR package. You can import the TAR package to the WebUI to view the graphical information. For details about how to import a TAR package, see Task Management.