Reputation: 5037
I'm trying to get profiling working in Stack, so that I can get the same metrics as the one indicated on Chapter 25 of RWH. I started a new Stack project, as follows:
stack new test
Then, as indicated here I ran:
stack install --executable-profiling --library-profiling --ghc-options="-rtsopts"
However this command fails with the following error:
While constructing the BuildPlan the following exceptions were encountered:
-- While attempting to add dependency,
Could not find package base in known packages
-- Failure when adding dependencies:
base: needed (>=4.7 && <5), stack configuration has no specified version (latest applicable is 4.9.0.0)
needed for package test-0.1.0.0
Recommended action: try adding the following to your extra-deps in /home/damian/test/stack.yaml
- base-4.9.0.0
You may also want to try the 'stack solver' command
I've tried the recommendations above, without success.
If I run stack build
then the program is built without errors.
As an additional question, I wonder whether is not possible to run stack test
or stack exec
with the flags above (this seems more logical than installing a the executable in order to profile it).
Upvotes: 3
Views: 497
Reputation: 34041
The only option that seems to work for me is:
stack exec --profile NameOfYourAppGoesHere -- +RTS -p
Upvotes: 1
Reputation: 2264
stack install
is equivalent to stack build --copy-bins
, so you should be able to run
stack build --executable-profiling --library-profiling --ghc-options="-rtsopts"
which will result in a compiled executable somewhere underneath your .stack-work/
directory (stack
will tell you where). You should then be able to run it and get the .prof
file you are expecting.
Upvotes: 1
Reputation: 3295
It works for me on lts-6.4
. To me, this indicates that you don't have a profiling version of base installed. This would need to get installed when installing GHC. What does stack exec -- which ghc
say? If ghc isn't located in your stack root, ~/.stack/programs
, then this means that you're using a custom GHC install, which may lack a profiling version of base. To resolve, either:
1) Remove custom install and run "stack setup"
2) Alternatively, set system-ghc: false
and run "stack setup"
Upvotes: 3