xiaoqizhan opened a new pull request, #18468: URL: https://github.com/apache/nuttx/pull/18468
For the memdump command, when CONFIG_MM_BACKTRACE >= 0 is enabled, it currently only supports dumping all leaked memory nodes and memory usage for a specific PID. It does not support dumping memory usage of all processes in one go. In some scenarios, it is necessary to dump memory usage of all processes at once. For example, when the memory pressure monitoring system detects that memory falls below a certain threshold, it needs to obtain the memory usage of all processes. Similarly, in some automation scripts, it is necessary to periodically collect memory data of each process for memory leak analysis. *Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary This change extends the functionality of the memdump command to support dumping memory usage of all processes at once. Previously, when CONFIG_MM_BACKTRACE >= 0 was enabled, the memdump command only supported dumping leaked memory nodes and memory usage of a specific PID, but not all processes in one operation. The enhancement addresses practical use cases such as: Obtaining full process memory usage when the memory pressure monitoring system detects memory below a certain threshold; Collecting periodic memory data of all processes in automation scripts for memory leak analysis. New subcommands are added: memdump a / memdump allpid: Dump memory usage of all processes; memdump allpid [seqmin] [seqmax]: Dump memory usage of processes within the specified seq range. This feature is only active when CONFIG_MM_BACKTRACE >= 0; it is not available if CONFIG_MM_BACKTRACE < 0. ## Impact User Impact New subcommands (allpid/a) are added to the memdump command, which are fully backward-compatible (existing memdump functionalities for leaked nodes and specific PID remain unchanged); Users need to ensure CONFIG_MM_BACKTRACE >= 0 (e.g., 0, 3,) to access the new features; the new commands are invisible when CONFIG_MM_BACKTRACE < 0. Compatibility No breaking changes to existing code or build process; The new logic is wrapped under the existing CONFIG_MM_BACKTRACE macro, so no additional configuration dependencies are introduced. Documentation Relevant documentation (e.g., command usage docs) needs to be updated to include the new memdump subcommands and their usage constraints (macro dependency). ## Testing Build Configuration: Test 1: CONFIG_MM_BACKTRACE = 0 Test 2: CONFIG_MM_BACKTRACE = 3 Test 3: CONFIG_MM_BACKTRACE = -1 (negative value for negative case verification) Test Steps & Results 1. Positive Case (CONFIG_MM_BACKTRACE >= 0) Step 1: Configure CONFIG_MM_BACKTRACE = 0 in the build config, compile and flash the firmware to the target board. Step 2: Execute memdump a (alias for memdump allpid) on the target shell; verify the output format and content: plaintext pid: 853, used: 0, nused: 0 pid: 22, used: 104336, nused: 77 pid: 23, used: 340856, nused: 160 pid: 24, used: 0, nused: 0 Step 3: Execute memdump allpid 0 1000; verify processes with seq in 0-1000 range are output (consistent with the above format, filtered by seq range Step 4: Repeat Step 1-3 with CONFIG_MM_BACKTRACE = 3; confirm the same output behavior (new commands work normally). 2. Negative Case (CONFIG_MM_BACKTRACE < 0) Step 1: Configure CONFIG_MM_BACKTRACE = -1, recompile and flash firmware. Step 2: Execute memdump a / memdump allpid on the target shell; verify the commands are not recognized (no response for new subcommands), and only original memdump functionalities are retained. 3. Regression Test Verify existing memdump features (dump leaked memory nodes, specific PID memory usage) work as expected after the change, with no regression. Test Logs (Key Snippets) bash 运行 # Log for CONFIG_MM_BACKTRACE=0 + memdump allpid root@board:/# memdump allpid pid: 22, used: 104336, nused: 77 pid: 23, used: 340856, nused: 160 # Log for CONFIG_MM_BACKTRACE=0 + memdump allpid 0 1000 root@board:/# memdump allpid 0 1000 pid: 22, used: 0, nused: 0 pid: 23, used: 340856, nused: 160 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
