Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stack run with profiling in haskell

I tried running

$ stack build --profile && stack run myexec --rts-options -p

But I get

... 
Registering library for mylibrary-0.1.0.1..
Completed 2 action(s).      
myexec: the flag -p requires the program to be built with -prof
...

I know I could run

$ .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/myexe/myexe +RTS -p

But what's the point of stack run then? I don't want to have to know the version of cabal and the architecture etc (this all happens in a makefile).

like image 663
fakedrake Avatar asked Sep 13 '19 13:09

fakedrake


1 Answers

The command that you use stack run is a convenience command that not only runs the binary, but also builds it prior to that. So when you run stack build --profile it compiles you binary with all of the necessary ghc flags, but when you call stack run it compiles it again, but now without all of the profiling flags. So there are two way to do it properly:

  1. Don't run stack build, since it is redundant:
$ stack --profile run myexec --rts-options -p
  1. or call the executable directly with +RTS flags, but make sure to pass --profile to both stack invocations, otherwise the stack exec will be looking in the wrong place for the binary (namely non-profiling build) and will fail to find it.
$ stack --profile build
$ stack --profile exec -- myexec +RTS -p
like image 89
lehins Avatar answered Nov 08 '22 21:11

lehins