Overview

The latrace utility allows users to trace the library calls of a given application similar to ltrace. It uses the auditing API provided by the GNU dynamic linker. This allows latrace to get notified if a PLT entry is called and thus collect the calls to shared objects. In addition latrace can print statistics using the -c switch like strace does for syscalls.

Project Information

Installation Instructions

Available by default at the Linaro developer image, and also at the Overlay PPA. To install it at any Linaro image, just run:

sudo apt-get install latrace

Using latrace

Statistics:

$ latrace -c pwd
/home

pwd finished - exited, status=0

--------------------------------------------------------------------------
Statistics for [pwd] total runtime: 0.039490 sec

Thread 2380 (runtime 0.023864 sec)
sec usec            %  usec/call      calls symbol                        
--- ------ ---------- ---------- ---------- ------------------------------
  0:006344  26.250673        198         32 malloc@/lib/libc.so.6
  0:000732   3.028924        183          4 free@/lib/libc.so.6
  0:000336   1.390326        168          2 __fpending@/lib/libc.so.6
  0:000396   1.638598        198          2 fclose@/lib/libc.so.6
  0:000000   0.000000          0          1 __libc_start_main@/lib/libc.so.6
  0:000214   0.885505        214          1 getenv@/lib/libc.so.6
  0:000183   0.757231        183          1 strrchr@/lib/libc.so.6
  0:013000  53.792362      13000          1 setlocale@/lib/libc.so.6
  0:000641   2.652377        641          1 bindtextdomain@/lib/libc.so.6
  0:000489   2.023420        489          1 textdomain@/lib/libc.so.6
  0:000153   0.633095        153          1 __cxa_atexit@/lib/libc.so.6
  0:000214   0.885505        214          1 getopt_long@/lib/libc.so.6
  0:000915   3.786155        915          1 getcwd@/lib/libc.so.6
  0:000153   0.633095        153          1 realloc@/lib/libc.so.6
  0:000397   1.642736        397          1 puts@/lib/libc.so.6
  0:000000   0.000000          0          1 exit@/lib/libc.so.6

Future areas

Comments from Ken Warner:

latrace works pretty good on ARM. I noticed that latrace segfaults in case a lib gets unload (via dlclose for example). The src/symbol.c holds a binary tree called root and does tsearch to find a symbol. The nodes are compared using symbol names (see symbol.c:compare). In case a lib is already unload the strcmp gets a segfault. The simplest testcase that came to my mind is a simple main that dlopens and dlcloses two dynamic shared libs. I also noticed that the -d (C++ demangler) doesn't work in conjunction with -c (statistics counts). As a workaround I just omitted the -d and piped the output into c++filt.

Limitations

latrace cannot attach to running process with -p pid option like ltrace. This is a fundamental limitation caused by using the LD_AUDIT feature, which cannot be enabled "on fly".

Pointers


CategoryHowTo

Platform/DevPlatform/Tools/Latrace (last modified 2011-09-01 04:01:22)