How to profile a GHC Plugin?
Context
I have built a GHC Plugin to symbolically execute Haskell Core, which I want to optimize. Profiling the plugin seems like a good starting point, but I’m having issues with this as the plugin is run through GHC. I.e. I cannot simply supply the flags +RTS -p -RTS to my plugin like I would for an executable. My plugin is built using stack and ideally I can profile it when it compiles another package via stack build.
What I’ve tried
I’ve manually compiled a version of GHC that supports profiling, such that I can pass the flags +RTS -p -RTS to it when GHC compiles using my plugin. AFAIK, there is no registry where one can download this. I’ve compiled GHC with the following command:
ghcup compile ghc -j 4 -v 9.10.2 -b 9.10.1 -o %v-profile -f "default+profiled_ghc+no_dynamic_ghc" --verbose
Note that the build system would complain to me that the dynamic “flavour” is not possible when compiling a profiling build, hence I added no_dynamic_ghc.
When I let stack build a program with this Haskell version 9.10.2-profile for whose compilation I would like profiling results, it seems to work up until I reach the package th-orphans, at which point I get the following error:
Interpreter failed to load profiled static library HSth-compat-0.1.6-DEIPkwUWmB23kAHF3cPtBW.
Trying dynamic library instead. If this fails try to rebuild libraries with profiling support.
libHSth-compat-0.1.6-DEIPkwUWmB23kAHF3cPtBW.so: cannot open shared object file: No such file or directory
CallStack (from -prof):
GHC.Utils.Panic.Plain.cmdLineErrorIO1 (<no location info>)
GHC.Linker.Loader.$wload_dyn (<no location info>)
GHC.Linker.Loader.$wloadPackages' (<no location info> GHC.Linker.Loader.initLoaderState1 (<no location info>)
GHC.Linker.Loader.loadDecls1 (<no location info>)
GHC.Driver.Main.hscCompileCoreExpr1 (<no location info>)
...
How to proceed?
- Is this really the best way to profile a GHC Plugin even? Perhaps I missed something, this seems awfully complex…
- If this is the best way to proceed, how would I resolve the above compilation issue? It suggests to compile libraries with profiling support, but the GHC build only has an option to disable profiling in libs (i.e.
no_profiled_libs), suggesting the libraries are profiled by default (profiled_libsdoesn’t exist).
Discussion in the ATmosphere