[Haskell-cafe] how to profile my code

Ruben Astudillo ruben.astud at gmail.com
Sun Sep 29 04:31:45 UTC 2019


Hi

On 27-09-19 05:30, PICCA Frederic-Emmanuel wrote:
> [...]
> It is nice, but I would like to understand the real problem.
> 
> I used hp2ps in order to monitor the memory usage, but my code is
> dominated by PINNED values (attached file)

I'll admit I am not an expert, but I've found some space leaks on
haskell projects (and fixes) so I'll take a stab. The info
on [1] for profiling memory usage is good, but usually doesn't tell you
what to use. If you profile with `+RTS -h --RTS` that actually means
`-hc` which profiles by cost centre. Those are defined at compile time,
so if you don't know where the leak is, compiling with `ghc -prof
-fprof-auto` or `cabal --enable-profiling` should do the trick.

But on your .ps you see lots of PINNED values, AFAIK those are usually
C-style buffers as used underlying for example by the Bytestring library
or FFI. I don't know how to further break them down via cost centres.

You have at your disposal other types of profiling (by types, by
modules), you could try any of those. One that I like is by retainer
sets info (-hr), check [1]. The basic idea is that memory leaks can be
break down on "set of cost centers". You can get lucky and see that lots
of memory are only held alive because a single retainer set of cost
center have those references, so `seq` some thunks solves the problem.

Finally I recommend to use the hp2pretty package for generating the
graphs as it has more options to organize info and to use `+RTS -L200
--RTS` when generating profiling info to include namespaces info for the
closures you're studying.

Good luck.

[1]: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html

-- 
-- Ruben
-- PGP: 4EE9 28F7 932E F4AD


More information about the Haskell-Cafe mailing list