How to make ghc profiler penetrate deeper into libraries?

I am trying to profile my program. Therefore, I compile it with the -prof and -auto-all flags and run with -P to get a detailed profiling report:

 $ ghc --make -prof -auto-all Test.hs $ ./Test +RTS -P 

Here is a snippet of the 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 

run seems to consume all the time and memory. He calls a lot of functions from different libraries, and I'm sure that most of the time is spent in one of them, but I can’t understand which one. How can I get a more detailed report? I hope that adding a lot of SCC comments manually is not the only way.

Update . At the moment, I have "solved" the problem by copying the library sources into my program directory. This allows the GHC to consider them as part of a program, and not as external libraries.

+4
source share
2 answers

This gprof type profiler is rather weak for these reasons.

You can use GHCi to find performance issues just like you could find infinite loops, with this technique like this:

6.3 Endless loops On Glasgow-haskell users on November 21, 2007, Pep made the following suggestion to discover the cause of endless loops in GHCi. Assuming the violating function is called loop and takes one argument:

1.enable flag -fbreak-on-error ( :set -fbreak-on-error in GHCi)

2.Clear your expression with: trace ( :trace loop 'a' )

3.hit Ctrl-C while your program gets stuck in a loop so that the debugger breaks in a loop

4.use: history and: back to find out where the loop is and why.

The only difference between any performance problem and an infinite loop is the endless loops spent 100% of the time, while performance problems lose a smaller percentage. Therefore, you may need to break into it several times.

+1
source

In order for the profiler to distinguish library functions, they must have annotations of cost centers. You can do this in two ways:

  • Recompile libraries of interest with -p -auto so that library functions are annotated with SCC.
  • Insert SCC annotations around probable long library calls in your code.
+4
source

Source: https://habr.com/ru/post/1342326/


All Articles