Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to profile? #5930

Closed
jrp2014 opened this issue Mar 9, 2019 · 15 comments
Closed

How to profile? #5930

jrp2014 opened this issue Mar 9, 2019 · 15 comments

Comments

@jrp2014
Copy link

jrp2014 commented Mar 9, 2019

Perhaps this is a documentation issue, but when I run something like cabal v2-bench --enable-profiling the benchmark runs, but produces no profiling output that I can see. If I run with cabal v2-run +RTS -p I get the the flag -p requires the program to be built with -prof error. Perhaps the bench and run executables are pointing at different things and perhaps the profiling output is buried somewhere, but the out of the box experience is suboptimal.

@hvr
Copy link
Member

hvr commented Mar 9, 2019

It's quite simple actually :-)

There's two ways of operation here: either you can operate in the non-stateful way, then you need to explicitly pass the --enable-profiling to every cabal command which is able to compute an install-plan, i.e.

cabal v2-run --enable-profiling exes --  +RTS -p

or you can persist those settings by invoking

cabal v2-configure --enable-profiling

which will merely create a file cabal.project.local with the single line

profiling: True

and then you don't need to explicitly pass --enable-profiling anymore via the CLI.

I hope this clears this up. Feel free to ask follow-up questions if something's still unclear.

@jrp2014
Copy link
Author

jrp2014 commented Mar 9, 2019

Many thanks, Herbert. That makes sense. (It would be good if the cabal documentation made the basic conventions clear; they seem obvious once they are explained but the cabal manual doesn't do a great job of explaining the underlying concepts (eg, when to drive and persist through the command line and when to put things into the cabal file).

@hasufell
Copy link
Member

hasufell commented Feb 26, 2020

This doesn't work for me. I built with the following config:

library-profiling: True
profiling: True

package *
  ghc-options: -O2 -threaded -fprof-auto "-with-rtsopts=-N -p -s -h -i0.1"

When running the executable with +RTS -p -RTS it errors out with the flag -p requires the program to be built with -prof. If you do what it says, you get the problems described in #2827

Edit: I'm using cabal v2-install and then run the exe directly.

@Achierius
Copy link

Same issues as @hausfell; I'm building for Windows, and I've tried a few permutations of the ghc-options listed above without luck.

@hasufell
Copy link
Member

hasufell commented Aug 13, 2020

@Achierius did you try to run cabal v2-build instead and then manually copy the binary? I consider v2-install broken by now (for installing local packages), because it ignores project files, afais.

@rubenmoor
Copy link

I put some {-# SCC foo #-} pragmas in my code, but they don't make a difference in the output when running my program "readFilePerformance":

cabal run --enable-profiling readFilePerformance -- +RTS -hc -s

As far as I can tell, the --profiling-detail flag doesn't make a difference, either.

Moreover, I receive a warning

Warning: 'ghc-options: -prof' is not necessary and will lead to problems when

but when I delete the flag (I have it in my cabal file, for the executable), I receive an error from ghc upon running cabal run ...:

readFilePerformance: the flag -hc requires the program to be built with -prof

I am completely confused now, especially regarding the SCC pragmas. Some heap profiling is going on, though.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 15, 2021

@rubenmoor: as you can see in comments above, you need -p in the +RTS section.

If that still doesn't work, you may have more luck with cabal build than cabal run.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 15, 2021

@rubenmoor; unless you only want to perform heap profiling with -hc, which should work fine. Does it produce the *.hp file? I don't remember if cost centres do anything for heap profiling. Probably not.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 15, 2021

@rubenmoor: and you usually don't want to both -p profile and -hc profile, because both change the performance characteristic of your program so you get doubly warped measurements.

@rubenmoor
Copy link

@rubenmoor: and you usually don't want to both -p profile and -hc profile, because both change the performance characteristic of your program so you get doubly warped measurements.

I use +RTS -hc and it produces the .hp-file. My only problem is that the cost centers that I manually set via the pragma {-# SCC foo #-} are completely ignored.

@Mikolaj
Copy link
Member

Mikolaj commented Dec 16, 2021

Let me check in the user guide:

https://downloads.haskell.org/ghc/latest/docs/html/users_guide/profiling.html#profiling-memory-usage

It seems, for the heap profiler to use your cost centre (for restricting what it profiles, there seems to be no other use), you need to give the cost centre name as argument to -hc. Do I read this right? Is that what you want?

@ulysses4ever
Copy link
Collaborator

This issue seems to have outlived its time here: the original question has been answered, and the follow-ups seem to have been abandoned. For posterity, the short answer is: create a cabal.project.local with:

profiling: True
profiling-detail: all-functions

Nothing else. Check out the profiling-related documentation in the manual.

I suggest we close.

@ratschan
Copy link

I exactly followed the instructions (creating a cabal.project.local file with "profiling: True" and "profiling-detail: all-functions"). However, after running "cabal run" I cannot find any .prof file. And worse, no error message appears, everything running through as usual.

@ulysses4ever
Copy link
Collaborator

@ratschan you're right: it is a bit confusing. The tail of the discussion above was devoted mostly to building code with profiling information included. What you're asking is how to run code so that you get the actual run-time information.

Here's an augmented answer: after setting up your .project file as discussed above, you need to pass the -p flag to the RTS, e.g.:

cabal run <name-of-exe-component> -- +RTS -p

@ratschan
Copy link

Great, that works, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants