admin管理员组

文章数量:1130349

1.安装

sudo apt install valgrind # 如果找不到,先运行 sudo apt update

2.运行程序

//程序不带参数运行
valgrind --tool=memcheck --leak-check=full --log-file=/home/administrator/workspace/planning/mem_debug.txt ./output/bin/control

//程序带参数运行
valgrind --tool=memcheck --leak-check=full --log-file=/home/administrator/workspace/control/mem_debug.txt ./output/bin/control  --control_conf_file=/home/administrator/workspace/control/output/conf/control/control_conf_RX.pb.txt --vehicle_config_path=/home/administrator/.airs/data/conf/RX-001/vehicle_param.pb.txt --control_calibration_file=/home/administrator/.airs/data/conf/RX-001/calibration_table.pb.txt 

待程序启动后,检查终端中打印的调试信息,看是否出现”malloc/new“等类似的关键字,则相关信息一般都和内存分配有关,再结合代码仔细排查

3、程序结束

  • 一般程序是开启线程循环执行,不会自动结束,若直接在terminal使用ctrl+c或kill -9 <pid> 结束程序,valgrind来不及统计内存泄露相关信息,无法得到完成报告;

  • 可使用如下命令结束程序,可获得完整的valgrind报告:

    # 使用top 或 ps 命令获取程序pid
    kill -TERM <pid>

4. 参考文档

Using Valgrind to Find Memory Leaks - Cprogramming

Valgrind参数配置详解_听雨时节的博客-CSDN博客_valgrind 参数

 使用 Valgrind 检测 C++ 内存泄漏 | Senlin's Blog

【Linux】Valgrind工具集详解_熠熠微光的博客-CSDN博客_linux valgrind

DEBUG神器valgrind之memcheck报告分析_学之之博未若知之之要知之之要未若行之之实的博客-CSDN博客

1.安装

sudo apt install valgrind # 如果找不到,先运行 sudo apt update

2.运行程序

//程序不带参数运行
valgrind --tool=memcheck --leak-check=full --log-file=/home/administrator/workspace/planning/mem_debug.txt ./output/bin/control

//程序带参数运行
valgrind --tool=memcheck --leak-check=full --log-file=/home/administrator/workspace/control/mem_debug.txt ./output/bin/control  --control_conf_file=/home/administrator/workspace/control/output/conf/control/control_conf_RX.pb.txt --vehicle_config_path=/home/administrator/.airs/data/conf/RX-001/vehicle_param.pb.txt --control_calibration_file=/home/administrator/.airs/data/conf/RX-001/calibration_table.pb.txt 

待程序启动后,检查终端中打印的调试信息,看是否出现”malloc/new“等类似的关键字,则相关信息一般都和内存分配有关,再结合代码仔细排查

3、程序结束

  • 一般程序是开启线程循环执行,不会自动结束,若直接在terminal使用ctrl+c或kill -9 <pid> 结束程序,valgrind来不及统计内存泄露相关信息,无法得到完成报告;

  • 可使用如下命令结束程序,可获得完整的valgrind报告:

    # 使用top 或 ps 命令获取程序pid
    kill -TERM <pid>

4. 参考文档

Using Valgrind to Find Memory Leaks - Cprogramming

Valgrind参数配置详解_听雨时节的博客-CSDN博客_valgrind 参数

 使用 Valgrind 检测 C++ 内存泄漏 | Senlin's Blog

【Linux】Valgrind工具集详解_熠熠微光的博客-CSDN博客_linux valgrind

DEBUG神器valgrind之memcheck报告分析_学之之博未若知之之要知之之要未若行之之实的博客-CSDN博客

本文标签: 内存教程Valgrindleakmemory