Profiling builds with Stack

后端 未结 4 1417
囚心锁ツ
囚心锁ツ 2020-12-22 19:51

How do I tell stack to build my executable and all its dependencies with -prof?

Simply adding it to ghc-options in the

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 20:31

    Assuming a project called project-name, this is how I get a time and heap profile (with colors):

    1. Add dependencies to the build-depends section of project-name.cabal
    2. Get dependent packages: stack build
    3. From inside project-name/app compile the program with profiling enabled: stack ghc -- -prof -fprof-auto -rtsopts -O2 Main.hs
    4. Then create the heap and time profile ./Main +RTS -hc -p. This will produce Main.hp and Main.prof
    5. Turn the heap profile into a PostScript file and then into a PDF chart with colors: stack exec -- hp2ps -c Main.hp && ps2pdf Main.ps

    That's the heap profile from the PDF:

提交回复
热议问题