全志平台Tina系统内存调试的方法(valgrind、pmap、手工释放内存)

2024-02-02 14:57:40 浏览数 (2)

全志平台Tina系统内存调试的方法(valgrind、pmap、手工释放内存)

以R18 yocto为例

valgrind

valgrind是个开源的工具,可以用来检查内存泄露等,全志平台上有移植,官网地址:

http://valgrind.org/downloads/current.html#current

valgrind使用方法:

1.在.bb文件里把 valgrind配置上:

yocto/sources/meta-tina/recipes-core/images$ git diff . diff --git a/recipes-core/images/image-tulip-mozart-chromium.bb b/recipes-core/i index b7663b1..940c7ef 100644 --- a/recipes-core/images/image-tulip-mozart-chromium.bb b/recipes-core/images/image-tulip-mozart-chromium.bb @@ -23,6 23,7 @@ base_install = " fake-hwclock crash-handler opkg valgrind "

2.把yocto/build/conf/local.conf下的BB_NO_NETWORK设置为0

BB_NO_NETWORK = "0"

3.设备端命令行:

valgrind --log-file=/tmp/valgrind.log --tool=memcheck --leak-check=full SampleApp /etc/avs/AlexaClientSDKConfig.json /etc/avs/ DEBUG9

sample-wakeup /etc/avs/config.json

即把命令sample-wakeup /etc/avs/config.json放到valgrind里跑

不过跑的时候发现这个demo在valgrind里跑会一直over run报错:

info: AlsaUtils.cpp(fetch,140): hw:sndac1082003b,0, overrun occurred info: AlsaUtils.cpp(fetch,140): hw:audiocodec,0, overrun occurred error: InterleavedConvertor.cpp(convert,111): input param error, data: 0x66be800, samples: 0

应该是因为valgrind本身也吃内存拖慢了进程造成的

pmap

pmap查看进程的内存映像信息(report memory map of a process)

1.ps查看进程号

2.pmap -d 1437

......

0000007fa0dfc000 24 r---- 00000000000bd000 0b3:00005 libsampleapp.so 0000007fa0e02000 4 rw--- 00000000000c3000 0b3:00005 libsampleapp.so 0000007fa0e03000 4 rw--- 0000000000000000 000:00000 [ anon ] 0000007fa0e04000 116 r-x-- 0000000000000000 0b3:00005 ld-2.26.so 0000007fa0e23000 32 rw-s- 0000000000000000 000:00006 pcmC1D0p 0000007fa0e2b000 4 rw-s- 0000000000000000 000:00005 [ shmid=0xf0000 ] 0000007fa0e2c000 8 rw--- 0000000000000000 000:00000 [ anon ] 0000007fa0e2e000 4 r---- 0000000000000000 000:00000 [ anon ] 0000007fa0e2f000 4 r-x-- 0000000000000000 000:00000 [ anon ] 0000007fa0e30000 4 r---- 000000000001c000 0b3:00005 ld-2.26.so 0000007fa0e31000 4 rw--- 000000000001d000 0b3:00005 ld-2.26.so 0000007fa0e32000 4 rw--- 0000000000000000 000:00000 [ anon ] 0000007fcb296000 132 rw--- 0000000000000000 000:00000 [ stack ] mapped: 2546816K writeable/private: 489532K shared: 100K 最后一行的值 mapped:表示该进程映射的虚拟地址空间大小,也就是该进程预先分配的虚拟内存大小,即ps出的vsz writeable/private:表示进程所占用的私有地址空间大小,也就是该进程实际使用的内存大小 shared:表示进程和其他进程共享的内存大小

手工释放内存

echo 3 > /proc/sys/vm/drop_caches

0 人点赞