Tracing allocations with "new" in dmd
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Jun 19 16:09:00 UTC 2020
On 6/19/20 12:03 PM, 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.
Thanks. Does it provide type information about the objects allocated?
More information about the Digitalmars-d
mailing list