Profiling Haskell applications with GHC

I’m looking into profiling a Haskell cabal project and I added the following lines to ghc-options:

    "-with-rtsopts=-N -p -s -h -i0.1"

according to this tutorial this should work. But when I run the resulting resulting binary I get the following message:

<no location info>: fatal:
    Cannot load -prof objects when GHC is built with -dynamic
    To fix this, either:
      (1) Use -fexternal-interpreter, or
      (2) Build the program twice: once with -dynamic, and then
          with -prof using -osuf to set a different object file suffix.

I assume this is because of the way nixos builds GHC. Is there a way to not build GHC with the -dynamic flag and allow profiling to work? I use external plugins so I can’t use -fexternal-interpreter because this results in the following message:

<command line>: Plugins require -fno-external-interpreter

I’d rather not have to compile everything twice when I’m trying to optimize my code.

1 Like

With cabal you should use --enable-profiling or similar flags, as described in this issue.

In nixpkgs based Haskell derivation you can use the enableExecutableProfiling and enableLibraryProfiling` arguments to achieve the same.

1 Like