There are various tools that already implement the logic required to identify memory leaks under Solaris,
- libumem & mdb (
UMEM_DEBUG=default UMEM_LOGGING=transaction LD_PRELOAD=libumem.so.1
thenmdb's ::findleaks
) - dbx (
check -leaks
)
Should you still want to go the dtrace
way, you need to trace the process you suspect to leak memory using the pid provider. You searched the kernel probes with dtrace -l
and found nothing but this is expected as the kernel does not implement malloc
or brk
. They are userland functions located in the C standard library.
This script will trace every malloc
and free
calls by a program:
dtrace -qn '
pid$target:libc:malloc:entry {
self->size=arg0;
}
pid$target:libc:malloc:return /self->size/ {
printf("malloc(%d)=%p\n",self->size,arg1);
self->size=0;
}
pid$target:libc:free:entry {
printf("free(%p)\n",arg0);
}
' -c program_to_trace
For more in-depth examples, have a look to http://ewaldertl.blogspot.fr/2010/09/debugging-memory-leaks-with-dtrace-and.html and http://www.joyent.com/blog/bruning-questions-debugging