Re: malloc() tracing in perf?

Frank Ch. Eigler
2009-08-06T11:22:03Z

Hi -

On Thu, Aug 06, 2009 at 10:16:50AM +0200, Peter Zijlstra wrote:
> [...]
> > But then it hit me, why can't I have kmemtrace + perf but for
> > user-space? Something like the "Malloc Trace" shown here:
> > [...]

> I seem to have heard people are working on such a thing, but I can't
> seem to find a single LKML post with 'uprobe' in the subject in the
> past two years [...]

That work is ongoing, and being discussed on utrace-devel@redhat.com,
since it is a prerequisite. One of the widgets that is being proposed
for it is an ftrace engine frontend for uprobes, paralleling the one
mhiramat wrote for kprobes.

> Now doing probes on userspace is hard because you need to know more
> about the userspace bits than a kernel really ought to be interested
> in. [...] Anyway, like you say, it has uses (potentially very
> powerful ones), Sun/Apple do it with Dtrace, Linux wants it but I
> don't think we quite agreed on how to do it :-)

While these deliberations are ongoing, you can use systemtap. Probing
random places in userspace is about as casual as probing the kernel:

# stap -e '
probe process("/lib/libc.so.6").function("malloc").return,
process("/lib/libc.so.6").function("free").return
{ println(probfunc()," ",$$parms," ",$$return) }
' -c 'ls' # -c 'CMD ARGS'

__libc_malloc bytes=0x238 return=0x1524010
__libc_malloc bytes=0x238 return=0x1524010
__libc_malloc bytes=0x78 return=0x1524250
__libc_malloc bytes=0xa return=0x15242d0
__libc_free mem=0x1524250
__libc_free mem=0x1524010
__libc_malloc bytes=0x64 return=0x1524010
__libc_malloc bytes=0x16 return=0x1524080
__libc_free mem=0x1524010
__libc_malloc bytes=0x64 return=0x1524010
[...]
__libc_free mem=0x1524490
__libc_free mem=0x1524500
__libc_free mem=0x15245e0
__libc_free mem=0x1524620
__libc_free mem=0x1524430
__libc_free mem=0x1524570
__libc_free mem=0x1524660
__libc_free mem=0x15246d0
__libc_free mem=0x15242d0

You can google some other success stories or ask for more help at
systemtap@sourceware.org.

- FChE