profiling a constructor?

Andreas Klebinger klebinger.andreas at gmx.at
Sat May 23 13:32:32 UTC 2020


> Surely, the RTS must be able to count the number of times a constructor is used.
It can't. For one there are different kinds of "uses" for constructors.
* Allocations - They might be dead by the time we gc the nursery, so the
RTS never get's to see them.
* Accessing the Constructor? That's even harder to track.
* The constructor being present during GC? One can do this using heap
profiling (as ben described).

There are also top level constructors which currently don't generate
code at all (just static data).

So currently there is no such feature.

For allocations in particular we could implement one on top of the ticky
profiler.
It operates on the STG => Cmm boundry so doesn't affect core optimizations.

There we could for every runtime constructor allocation emit code which
will bump a counter for that specific constructor.

I imagine this wouldn't that hard either. But it does require
modification of the compiler.

Cheers,
Andreas



Richard Eisenberg schrieb am 23.05.2020 um 14:58:
> Hi devs,
>
> Is there a way to count the number of times a particular constructor is allocated? I might want to know, say, the total number of cons cells allocated over the course of a program, or (in my actual case) the total number of FunTy cells allocated over the course of a program.
>
> I can try to do this with an SCC. But it's very clunky:
> * The constructor may be used in a number of places; each such place would need the SCC.
> * SCCs can interfere with optimizations. In my use case, this would negate the usefulness of the exercise entirely, as I think some of the structures I wish to observe should never come into being, due to optimizations (e.g. case-of-known-constructor after inlining).
>
> Surely, the RTS must be able to count the number of times a constructor is used. But is there any way to access such a feature? If others agree that this would sometimes be helpful, perhaps we can build the feature. Now is not the first time I've wanted this.
>
> Thanks!
> Richard
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs



More information about the ghc-devs mailing list