Re: massif & counts per type

folkert <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Organization www.vanheusden.com
Message-ID <[email protected]>
Hi,

> > How can I obtain the number of mallocs per type in a time-frame using
> > massif? I'm NOT interested in the total in use, I would like to know how
> > often type x is allocated between t+1 and t+2.
> 
> To my knowledge, this data is not recorded by Massif. You could try to have a 
> look at heaptrack [1] instead.
> 
> [1]: https://invent.kde.org/sdk/heaptrack
> 
> Note though that on Linux, malloc does not retain any type information. As 
> such, even with heaptrack you cannot easily filter by type. But by leveraging 
> the flamegraph you can often still get a similar intuition based on the 
> callstacks. I have an idea to parse the callstack code lines to find type 
> information from the call to `new` but that's probably quite hairy to get 
> right in practice. Suggestions welcome on how to trace the type information!
> 
> And finally, with heaptrack it is also not yet easily doable to get a diff 
> between two time stamps. Also a feature I've long thought about implementing, 
> but never got around to...

This morning I came up with an other solution: I made a LD_PRELOAD
wrapper which counts every malloc-call. Decided that allocated-type is
not really required in my case, but to know which malloc did it would
work as well.
So in malloc() I do __builtin_return_address(0), hash the pointer and
use that as an index in array of counters.

Gives me:

pointer          count
...
000000000041db10 00000000002a427
00007ffff4a6c1b1 00000000007f1da

Going from 000000000041db10 to a symbol works fine, the shared library
(00007ffff4a6c1b1) is a bit troublesome though (disabled
randomize_va_space and using eu-addr2line).



Folkert van Heusden

--
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.