Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling with Stack

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).

like image 994
Damian Nadales Avatar asked Mar 23 '26 23:03

Damian Nadales


2 Answers

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"

like image 180
mgsloan Avatar answered Mar 25 '26 22:03

mgsloan


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.

like image 21
Vaibhav Sagar Avatar answered Mar 25 '26 20:03

Vaibhav Sagar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!