Re: massif & counts per type

Milian Wolff <[email protected]>
Newsgroups gmane.comp.debugging.valgrind
Message-ID <2708399.KlBsvKRTlt@milian-workstation>
On Freitag, 11. September 2020 12:50:18 CEST folkert wrote:
> 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).

You have to take the memory mapping of the library into account and subtract 
that offset from the address.

Anyhow, it sounds like you are starting to reinvent heaptrack - it does 
exactly the above and then some.

Cheers

-- 
Milian Wolff
[email protected]
http://milianw.de

_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEezawi1aUvUGg3A1+8zYW/HGdOX8FAl9bj00ACgkQ8zYW/HGd
OX8Avg//et9pngxfdyrvA7TlVMs0tCvC8anpHsjFZOeCMhjL+46uh+IPRzrbOagk
6O1iGin4gQI2r9S2PGMuYxr0cJYyzzRLxOS6bmZTg2Td2yyxWVGRQ+/464ScDavZ
C/Zn1w6VFGAkO3ZV9k8hTreERU/r7GR5/jvC1UfOrgHdppH1Lvz512Eu4hX6iRdP
1CAgmpyYYPRXDEFyYdFatrffhmVa4YTfQOdkvqcgX7+OrKC1IjGQgNPbWqRMvvUi
dapa3i5mg27ATz3fXgemB1oF87ZnepxleV5vQIL0R+KP4EiV1JPF+R4D1svHN3Lr
hzCKqb3LWt4E33dKrKhVOUm5duHzvgr4tZd39STLuvkCt2xaC5Wq3Nnndwoc2rMj
mbheg660Kvok8RRFu0VkRlIkJQaApGs3ubFJ6GXqm/+6BtfJLC/LTUpLSrRa6sZH
aPcdVVmHIQkQqcKK/bN4w/Zdk/j647qgDE+PsSN8XGVT4gup8fPk3m9YS46nmnD8
RnZOTXCURbOq2o/f7zYorgk/FTcGypJT/PUc0fBRH0FmgJ/7pPliC5QvX8XBm6vs
DOdxkSd+fDiqtEdgFKcEa3Gruh2cycvivgL/uNEKMmlydKW38UIS0lmDLubxkPrI
nF0srYOHPFF1/aiKgdWTpQH/P1sB+euKmeXRU2oIUON0oEfvHmY=
=ozgi
-----END PGP SIGNATURE-----
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.