(十三)valgrind在ARM上交叉编译和内存泄漏检测

valgrind是一款用于内存调试、内存泄漏检测以及性能分析的软件开发工具。

1、下载valgrind-3.17.0

2、交叉编译

修改configure: armv7*) 改成 armv7*|arm)

./configure --host=aarch64-linux  \
CC=/gzy_mnt/aarch64-linux-gds/bin/aarch64-linux-gnu-gcc  \
CPP=/gzy_mnt/aarch64-linux-gds/bin/aarch64-linux-gnu-cpp \
CXX=/gzy_mnt/aarch64-linux-gds/bin/aarch64-linux-gnu-g++ \
--prefix=/gzy_mnt/valgrind 

然后进行make -j8编译和安装make install。

/gzy_mnt/valgrind目录下生成好的bin、include、lib、libexec、share目录

3、运行

/gzy_mnt是挂载在arm板子上的共享目录。我们对NanoDet的MNN进行内存泄露检测。在目录/gzy_mnt/valgrind下执行:

./valgrind --leak-check=full /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection /gzy_mnt/club

Memcheck是默认工具。--leak-check选项打开详细的内存泄漏检测器。程序运行速度会比正常情况慢很多,并且会占用更多内存。Memcheck将发出有关内存错误和检测到的泄漏的消息。格式如下:

valgrind toolparamters appname appargs

一开始是valgrind信息“==2130==”表示进程号

==2130== Memcheck, a memory error detector
==2130== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2130== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==2130== Command: /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection /gzy_mnt/club
==2130==

程序访问非法地址的内存,无效写入

==2130== Invalid write of size 8
==2130== at 0x6806FE0: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000360 is on thread 1's stack
==2130== 16 bytes below stack pointer
==2130==
==2130== Invalid read of size 8
==2130== at 0x68077F0: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000360 is on thread 1's stack
==2130== 16 bytes below stack pointer
==2130==
==2130== Invalid write of size 8
==2130== at 0x6807920: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000360 is on thread 1's stack
==2130== 16 bytes below stack pointer
==2130==
==2130== Invalid write of size 8
==2130== at 0x6807924: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000350 is on thread 1's stack
==2130== 32 bytes below stack pointer
==2130==
==2130== Invalid write of size 8
==2130== at 0x6807928: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000340 is on thread 1's stack
==2130== 48 bytes below stack pointer
==2130==
==2130== Invalid write of size 8
==2130== at 0x680792C: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000330 is on thread 1's stack
==2130== 64 bytes below stack pointer
==2130==
==2130== Invalid read of size 8
==2130== at 0x6807DE0: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000360 is on thread 1's stack
==2130== 16 bytes below stack pointer
==2130==
==2130== Invalid read of size 8
==2130== at 0x6807DE4: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000350 is on thread 1's stack
==2130== 32 bytes below stack pointer
==2130==
==2130== Invalid read of size 8
==2130== at 0x6807DE8: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000340 is on thread 1's stack
==2130== 48 bytes below stack pointer
==2130==
==2130== Invalid read of size 8
==2130== at 0x6807DEC: ??? (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== Address 0x1fff000330 is on thread 1's stack
==2130== 64 bytes below stack pointer
==2130==

堆区情况:

==2130== HEAP SUMMARY:
==2130== in use at exit: 56,224 bytes in 658 blocks
==2130== total heap usage: 59,896 allocs, 59,238 frees, 27,306,731 bytes allocated
==2130==
==2130== 608 (144 direct, 464 indirect) bytes in 2 blocks are definitely lost in loss record 409 of 422
==2130== at 0x48497E0: operator new(unsigned long) (vg_replace_malloc.c:417)
==2130== by 0x66EC66F: MNN::Tensor::create(std::vector<int, std::allocator > const&, halide_type_t, void*, MNN::Tensor::DimensionType) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2C27: MNN::CV::ImageProcess::createImageTensor(halide_type_t, int, int, int, void*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2CCF: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, void*, int, int, int, int, halide_type_t) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F323B: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, MNN::Tensor*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x418BEB: NanoDet::detect(cv::Mat&, std::vector<BoxInfo, std::allocator >&) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x40CFE7: golf::GolfDetection::globalRun(cv::Mat, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x41B2BB: image_demo_union(golf::GolfDetection&, golf::GolfDetection&, char const*) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x406D13: main (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130==
==2130== 608 (144 direct, 464 indirect) bytes in 2 blocks are definitely lost in loss record 410 of 422
==2130== at 0x48497E0: operator new(unsigned long) (vg_replace_malloc.c:417)
==2130== by 0x66EC66F: MNN::Tensor::create(std::vector<int, std::allocator > const&, halide_type_t, void*, MNN::Tensor::DimensionType) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2C27: MNN::CV::ImageProcess::createImageTensor(halide_type_t, int, int, int, void*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2CF3: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, void*, int, int, int, int, halide_type_t) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F323B: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, MNN::Tensor*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x418BEB: NanoDet::detect(cv::Mat&, std::vector<BoxInfo, std::allocator >&) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x40CFE7: golf::GolfDetection::globalRun(cv::Mat, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x41B2BB: image_demo_union(golf::GolfDetection&, golf::GolfDetection&, char const*) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x406D13: main (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130==
==2130== 608 (144 direct, 464 indirect) bytes in 2 blocks are definitely lost in loss record 411 of 422
==2130== at 0x48497E0: operator new(unsigned long) (vg_replace_malloc.c:417)
==2130== by 0x66EC66F: MNN::Tensor::create(std::vector<int, std::allocator > const&, halide_type_t, void*, MNN::Tensor::DimensionType) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2C27: MNN::CV::ImageProcess::createImageTensor(halide_type_t, int, int, int, void*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2CCF: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, void*, int, int, int, int, halide_type_t) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F323B: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, MNN::Tensor*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x418BEB: NanoDet::detect(cv::Mat&, std::vector<BoxInfo, std::allocator >&) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x40D463: golf::GolfDetection::localBallRun(cv::Mat, float, float, ShootType, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x41B59B: image_demo_union(golf::GolfDetection&, golf::GolfDetection&, char const*) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x406D13: main (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130==
==2130== 608 (144 direct, 464 indirect) bytes in 2 blocks are definitely lost in loss record 412 of 422
==2130== at 0x48497E0: operator new(unsigned long) (vg_replace_malloc.c:417)
==2130== by 0x66EC66F: MNN::Tensor::create(std::vector<int, std::allocator > const&, halide_type_t, void*, MNN::Tensor::DimensionType) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2C27: MNN::CV::ImageProcess::createImageTensor(halide_type_t, int, int, int, void*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F2CF3: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, void*, int, int, int, int, halide_type_t) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66F323B: MNN::CV::ImageProcess::convert(unsigned char const*, int, int, int, MNN::Tensor*) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x418BEB: NanoDet::detect(cv::Mat&, std::vector<BoxInfo, std::allocator >&) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x40D463: golf::GolfDetection::localBallRun(cv::Mat, float, float, ShootType, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x41B59B: image_demo_union(golf::GolfDetection&, golf::GolfDetection&, char const*) (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130== by 0x406D13: main (in /gzy_mnt/gdsplusv2/demo/clublocal/golfDetection)
==2130==
==2130== 912 bytes in 3 blocks are possibly lost in loss record 415 of 422
==2130== at 0x484E024: calloc (vg_replace_malloc.c:1117)
==2130== by 0x400FA8F: allocate_dtv (in /lib/ld-2.28.so)
==2130== by 0x4010347: _dl_allocate_tls (in /lib/ld-2.28.so)
==2130== by 0x48720FB: pthread_create@@GLIBC_2.17 (in /lib/libpthread-2.28.so)
==2130== by 0x697D863: std:thread:_M_start_thread(std::unique_ptr<std:thread:_State, std::default_deletestd:thread:_State >, void (*)()) (in /lib/libstdc++.so.6.0.25)
==2130== by 0x67D0CF3: MNN::ThreadPool::ThreadPool(int) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x67D0F37: MNN::ThreadPool::init(int) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x67805DB: MNN::CPURuntime::CPURuntime(MNN::Backend::Info const&) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x6780733: MNN::CPURuntimeCreator::onCreate(MNN::Backend::Info const&) const (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66E277F: MNN::RuntimeFactory::create(MNN::Backend::Info const&) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66D5DBB: MNN::Interpreter::createRuntime(std::vector<MNN::ScheduleConfig, std::allocatorMNN::ScheduleConfig > const&) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130== by 0x66D6E53: MNN::Interpreter::createMultiPathSession(std::vector<MNN::ScheduleConfig, std::allocatorMNN::ScheduleConfig > const&) (in /gzy_mnt/gdsplusv2/lib/libMNN.so)
==2130==

内存泄漏消息如下所示:有几种泄漏; 两个最重要的类别是,肯定泄露(definitely lost),可能已经泄露(possibly lost)

==2130== LEAK SUMMARY:
==2130== definitely lost: 576 bytes in 8 blocks
==2130== indirectly lost: 1,856 bytes in 16 blocks
==2130== possibly lost: 912 bytes in 3 blocks
==2130== still reachable: 52,880 bytes in 631 blocks
==2130== suppressed: 0 bytes in 0 blocks
==2130== Reachable blocks (those to which a pointer was found) are not shown.
==2130== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2130==
==2130== For lists of detected and suppressed errors, rerun with: -s
==2130== ERROR SUMMARY: 228733 errors from 15 contexts (suppressed: 0 from 0)

MNN在1.2.0版本有严重内存泄漏,在1.2.9版本进行测试,MNN修复部分问题,例如在ImageProcess转化的内存泄漏已经修改掉。

详细见:严重内存泄漏 · Issue #1018 · alibaba/MNN · GitHub

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值