|Posted by FeepingCreature|
in reply to Tim
On Friday, 19 June 2020 at 16:03:55 UTC, Tim wrote:
> On Friday, 19 June 2020 at 13:45:23 UTC, Andrei Alexandrescu wrote:
>> dmd does most of its allcoation with new. I wonder what would be the easiest way to track how many instances of each type are created.
>> There are over 3000 call sites, so ideally the changes to the source would be entirely automatic (e.g. with sed).
>> Would be in your debt for any ideas. Thanks!
> You can also use heaptrack for tracing allocations under Linux. It uses LD_PRELOAD to replace allocation functions with wrappers.
> I have modified heaptrack to also track allocations on the D GC heap: https://github.com/tim-dlang/heaptrack/tree/heaptrack-d
> When using it, the application has to be linked with druntime dynamically. It also only works, when the application is launched by heaptrack, and not, when heaptrack is attached later. The modified heaptrack will only work with D applications.
> dmd can be linked dynamically with phobos/druntime by passing DFLAGS="-defaultlib=phobos2 -debuglib=phobos2" to build.d.
> For dmd you can call it like this:
> heaptrack dmd -lowmem test.d
> It will then generate a file like heaptrack.dmd.*.zst, which can be analyzed with heaptrack --analyze.
Reply to bump. This is one of the best "secret weapons" in the D ecosystem. Just yesterday we used it to find the reason why a service was ballooning to 11GB.