# Code Profiling tools

**URL:** <https://forum.legato.io/t/code-profiling-tools/6510>\
**Category:** Uncategorized\
**Created:** [May 22, 2023, 8:14pm UTC](https://forum.legato.io/t/code-profiling-tools/6510 "2023-05-22T20:14:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmark](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@pmark](https://forum.legato.io/u/pmark)\
**Post date:** [May 22, 2023, 8:14pm UTC](https://forum.legato.io/t/code-profiling-tools/6510/1 "2023-05-22T20:14:37Z")

</div>

Is there any documentation on how to use GPROF or VALGRING or similar tool on the WP7702 ?  
I am running 15.1.0.004 Legato 21.05.0  
I am trying to see where my code spends the most time.  
Thanks

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 23, 2023, 12:33am UTC](https://forum.legato.io/t/code-profiling-tools/6510/2 "2023-05-23T00:33:54Z")

</div>

You can see here

> [@How to use Valgrind on WP76 to investigate memory leaks](https://forum.legato.io/t/how-to-use-valgrind-on-wp76-to-investigate-memory-leaks/5217/2):
>
> You can try the procedure below on WP76 R13.3: download the yocto source code open ./meta-swi/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc and add the following line: IMAGE\_INSTALL\_append = " valgrind" make the yocto image there will be error to make the yocto.cwe as it is too big. Instead we need to transfer the binary to module’s RAM area on module, type the following: mkdir /tmp/valgrind on PC: scp ./build\_bin/tmp/work/armv7a-neon-poky-linux-gnueabi/valgrind/3.13.…

> [@Valgrind's memory management: out of memory](https://forum.legato.io/t/valgrinds-memory-management-out-of-memory/5881/2):
>
> I don’t see problem with WP76 R13 with attached binary: [valgrind.rar](https://forum.legato.io/uploads/short-url/twtnwIEWpziYsoczHMPnV6OO5CU.rar) (3.3 MB) mkdir /tmp/valgrind mkdir /tmp/tmp\_lib;mkdir /tmp/tmp\_lib\_wr; cp -rf /lib /tmp/tmp\_lib mount -t overlay overlay /lib -o lowerdir=/lib,upperdir=/tmp/tmp\_lib,workdir=/tmp/tmp\_lib\_wr; Use WINSCP to transfer all the binary to /tmp/valgrind Use WINSCP to transfer ld-linux.so.3 to /lib ( cannot copy directly from /tmp/valgrind to /lib) chmod -R 777 /tmp/valgrind export VALGRIND\_LIB=/tmp/valgrind root@swi-mdm9x28-…

---

<div class="post-metadata">

**Author:** ![pmark](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@pmark](https://forum.legato.io/u/pmark)\
**Post date:** [May 23, 2023, 1:03pm UTC](https://forum.legato.io/t/code-profiling-tools/6510/3 "2023-05-23T13:03:33Z")

</div>

Thanks  
Did as described it’s a newer version ? but get a permission denied when try to run?

pm@pmFX30S:/media/psf/Home/mango/valgrind21/valgrind$ scp ./3.15.0-r0/image/usbin/\* [root@192.168.2.2](mailto:root@192.168.2.2):/tmp/valgrind  
callgrind\_annotate 100% 44KB 1.9MB/s 00:00  
callgrind\_control 100% 12KB 1.7MB/s 00:00  
cg\_annotate 100% 33KB 2.5MB/s 00:00  
cg\_diff 100% 10KB 1.4MB/s 00:00  
cg\_merge 100% 176KB 3.5MB/s 00:00  
ms\_print 100% 24KB 1.9MB/s 00:00  
valgrind 100% 94KB 3.4MB/s 00:00  
valgrind-di-server 100% 104KB 3.5MB/s 00:00  
valgrind-listener 100% 29KB 3.0MB/s 00:00  
vgdb 100% 148KB 3.7MB/s 00:00  
pm@pmFX30S:/media/psf/Home/mango/valgrind21/valgrind$ scp ./3.15.0-r0/image/usr/lib/valgrind/memcheck-arm-linux [root@192.168.2.2](mailto:root@192.168.2.2):/tmp/valgrind  
memcheck-arm-linux 100% 12MB 4.2MB/s 00:02  
pm@pmFX30S:/media/psf/Home/mango/valgrind21/valgrind$ scp ./3.15.0-r0/image/usr/lib/valgrind/callgrind-arm-linux [root@192.168.2.2](mailto:root@192.168.2.2):/tmp/valgrind  
callgrind-arm-linux 100% 11MB 4.1MB/s 00:02

root@fx30s:/tmp/valgrind# /tmp/valgrind/valgrind  
-sh: /tmp/valgrind/valgrind: Permission denied  
root@fx30s:/tmp/valgrind# ls -l  
-rwxrwxrwx 1 root root 11529460 May 23 08:56 callgrind-arm-linux  
-rwxrwxrwx 1 root root 44737 May 23 08:55 callgrind\_annotate  
-rwxrwxrwx 1 root root 12673 May 23 08:55 callgrind\_control  
-rwxrwxrwx 1 root root 33535 May 23 08:55 cg\_annotate  
-rwxrwxrwx 1 root root 10418 May 23 08:55 cg\_diff  
-rwxrwxrwx 1 root root 180064 May 23 08:55 cg\_merge  
-rwxrwxrwx 1 root root 12747592 May 23 08:56 memcheck-arm-linux  
-rwxrwxrwx 1 root root 24398 May 23 08:55 ms\_print  
-rwxrwxrwx 1 root root 96576 May 23 08:55 valgrind  
-rwxrwxrwx 1 root root 106468 May 23 08:55 valgrind-di-server  
-rwxrwxrwx 1 root root 29564 May 23 08:55 valgrind-listener  
-rwxrwxrwx 1 root root 151320 May 23 08:55 vgdb

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [May 23, 2023, 1:16pm UTC](https://forum.legato.io/t/code-profiling-tools/6510/4 "2023-05-23T13:16:56Z")

</div>

How about “chmod 777 /tmp/valgrind/valgrind”?  
Not sure if you need to rebuild according to your FW version R15.

BTW, I can run on wp77 firmware R14.1.  
[https://source.sierrawireless.com/resources/airprime/software/wp77xx/wp77xx-firmware-release-14,-d-,1/#sthash.drUWPqGm.dpbs](https://source.sierrawireless.com/resources/airprime/software/wp77xx/wp77xx-firmware-release-14,-d-,1/#sthash.drUWPqGm.dpbs)

```auto

root@fx30:~# mkdir /tmp/valgrind
root@fx30:~# mkdir /tmp/tmp_lib;mkdir /tmp/tmp_lib_wr;
root@fx30:~# cp -rf /lib /tmp/tmp_lib
root@fx30:~# mount -t overlay overlay /lib -o lowerdir=/lib,upperdir=/tmp/tmp_li
b,workdir=/tmp/tmp_lib_wr;
root@fx30:~# chmod -R 777 /tmp/valgrind
root@fx30:~# export VALGRIND_LIB=/tmp/valgrind
root@fx30:~# cd /tmp/valgrind/
root@fx30:/tmp/valgrind# ./valgrind --leak-check=full --show-leak-kinds=all --v
erbose ./vgdb
==2716== Memcheck, a memory error detector
==2716== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2716== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==2716== Command: ./vgdb
==2716==
--2716-- Valgrind options:
--2716-- --leak-check=full
--2716-- --show-leak-kinds=all
--2716-- --verbose
--2716-- Contents of /proc/version:
--2716-- Linux version 3.18.140 (oe-user@oe-host) () #1 PREEMPT Fri May 14 11:13:23 UTC 2021
--2716--
--2716-- Arch and hwcaps: ARM, LittleEndian, ARMv7-neon-vfp
--2716-- Page sizes: currently 4096, max supported 4096
--2716-- Valgrind library directory: /tmp/valgrind
--2716-- Reading syms from /tmp/valgrind/vgdb
--2716-- Reading syms from /lib/ld-2.27.so
--2716-- Reading syms from /tmp/valgrind/memcheck-arm-linux
--2716-- object doesn't have a dynamic symbol table
--2716-- Scheduler: using generic scheduler lock implementation.
--2716-- Reading suppressions file: /tmp/valgrind/default.supp
==2716== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-2716-by-root-on-???
==2716== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-2716-by-root-on-???
==2716== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-2716-by-root-on-???
==2716==
==2716== TO CONTROL THIS PROCESS USING vgdb (which you probably
==2716== don't want to do, unless you know exactly what you're doing,
==2716== or are doing some strange experiment):
==2716== /tmp/valgrind/../../bin/vgdb --pid=2716 ...command...
==2716==
==2716== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==2716== /path/to/gdb ./vgdb
==2716== and then give GDB the following command
==2716== target remote | /tmp/valgrind/../../bin/vgdb --pid=2716
==2716== --pid is optional if only one valgrind process is running
==2716==
--2716-- REDIR: 0x401a781 (ld-linux.so.3:strlen) redirected to 0x5805721c (???)
--2716-- REDIR: 0x401b300 (ld-linux.so.3:memcpy) redirected to 0x58057248 (???)
--2716-- REDIR: 0x401a071 (ld-linux.so.3:strcmp) redirected to 0x58057354 (???)
--2716-- Reading syms from /tmp/valgrind/vgpreload_core-arm-linux.so
--2716-- Reading syms from /lib/libpthread-2.27.so
--2716-- Considering /lib/libpthread-2.27.so ..
--2716-- .. CRC mismatch (computed 625f8b61 wanted 7bccdfac)
--2716-- object doesn't have a symbol table
--2716-- Reading EXIDX entries: 83 available
==2716== Warning: whilst reading EXIDX: Implausible EXIDX last entry size 4294967199; using 1 instead.
--2716-- Reading EXIDX entries: 69 attempted, 69 successful
--2716-- Reading syms from /lib/libc-2.27.so
--2716-- Considering /lib/libc-2.27.so ..
--2716-- .. CRC mismatch (computed ffa2c805 wanted add05a1e)
--2716-- object doesn't have a symbol table
--2716-- Reading EXIDX entries: 726 available
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryExtract: bytecode can't be represented
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: ExtabEntryDecode: failed with error code: -10
==2716== Warning: whilst reading EXIDX: Implausible EXIDX last entry size 4294964239; using 1 instead.
--2716-- Reading EXIDX entries: 527 attempted, 421 successful
==2716== Conditional jump or move depends on uninitialised value(s)
==2716== at 0x48E0B00: strlen (in /lib/libc-2.27.so)
==2716==
==2716== Use of uninitialised value of size 4
==2716== at 0x48E033C: strcpy (in /lib/libc-2.27.so)
==2716==
Using vgdb standalone implies to give -D or -l or a COMMAND
args error. Try `vgdb --help` for more information
==2716==
==2716== HEAP SUMMARY:
==2716== in use at exit: 0 bytes in 0 blocks
==2716== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==2716==
==2716== All heap blocks were freed -- no leaks are possible
==2716==
==2716== Use --track-origins=yes to see where uninitialised values come from
==2716== ERROR SUMMARY: 12 errors from 2 contexts (suppressed: 3 from 3)
==2716==
==2716== 1 errors in context 1 of 2:
==2716== Conditional jump or move depends on uninitialised value(s)
==2716== at 0x48E0B00: strlen (in /lib/libc-2.27.so)
==2716==
==2716==
==2716== 11 errors in context 2 of 2:
==2716== Use of uninitialised value of size 4
==2716== at 0x48E033C: strcpy (in /lib/libc-2.27.so)
==2716==
--2716--
--2716-- used_suppression: 3 dl-hack3-cond-1 /tmp/valgrind/default.supp:1236
==2716==
==2716== ERROR SUMMARY: 12 errors from 2 contexts (suppressed: 3 from 3)
root@fx30:/tmp/valgrind# cm info
Device: WP7702
IMEI: 352653090612345
IMEISV: 6
FSN: VU213430812345
Firmware Version: SWI9X06Y_02.36.06.00 63d944 jenkins 2020/12/10 19:12:28
Bootloader Version: SWI9X06Y_02.36.06.00 63d944 jenkins 2020/12/10 19:12:28
MCU Version: 002.015
PRI Part Number (PN): 9908741
PRI Revision: 002.001
Carrier PRI Name: GENERIC
Carrier PRI Revision: 001.071_001
SKU: 1104214
Last Reset Cause: Power Down
Resets Count: Expected: 123 Unexpected: 0
root@fx30:/tmp/valgrind# legato version
19.11.5.a1621d58_27c4cd8552e17e79fdc3b0c91ff8bce9

```
