I'm trying to profile my program. So I compile it with -prof
and -auto-all
flags and run with -P
to get detailed profiling report:
$ ghc --make -prof -auto-all Test.hs
$ ./Test +RTS -P
Here is a piece of profiling report:
COST CENTRE MODULE no. entries %time %alloc
main Main 266 1 0.0 0.0
run Main 273 21845 99.3 99.7
sz Main 274 21844 0.0 0.0
size Main 268 21845 0.7 0.3
It seems that run
consumes all time and memory. It calls a lot of functions from various libraries, and I'm quite sure that most time is spent in one of them, but I can't figure in which one.
How can I get more detailed report? I hope that putting lots of SCC
annotations manually is not the only way.
Update. For now I "solved" the problem by copying sources of libraries to my program directory. This allows GHC to treat them as part of program, not as external libraries.
For the profiler to discriminate library functions, there have to be cost-center annotations on them. You can do this two ways:
-p -auto
so that library functions get annotated with SCCs.It's a gprof-type profiler - pretty weak, for these reasons.
You can use GHCi to find performance issues the same way you would find infinite loops, by this technique in this manner:
The only difference between any performance problem and an infinite loop is - infinite loops waste 100% of the time, while performance problems waste a lesser percent. So you might have to break into it a few times.