{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreifr52hahqnylb7w3tyjzhmuekwctwmszqt2yzorymtijohjdscbly",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mfv5jaueft32"
  },
  "path": "/t/how-to-profile-a-ghc-plugin/13745#post_1",
  "publishedAt": "2026-02-27T16:39:16.000Z",
  "site": "https://discourse.haskell.org",
  "textContent": "# Context\n\nI 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`.\n\n# What I’ve tried\n\nI’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:\n\n\n    ghcup compile ghc -j 4 -v 9.10.2 -b 9.10.1 -o %v-profile -f \"default+profiled_ghc+no_dynamic_ghc\" --verbose\n\n\nNote 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`.\n\nWhen 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:\n\n\n    Interpreter failed to load profiled static library HSth-compat-0.1.6-DEIPkwUWmB23kAHF3cPtBW.\n    Trying dynamic library instead. If this fails try to rebuild libraries with profiling support.\n\n    libHSth-compat-0.1.6-DEIPkwUWmB23kAHF3cPtBW.so: cannot open shared object file: No such file or directory\n    CallStack (from -prof):\n      GHC.Utils.Panic.Plain.cmdLineErrorIO1 (<no location info>)\n      GHC.Linker.Loader.$wload_dyn (<no location info>)\n      GHC.Linker.Loader.$wloadPackages' (<no location info>  GHC.Linker.Loader.initLoaderState1 (<no location info>)\n      GHC.Linker.Loader.loadDecls1 (<no location info>)\n      GHC.Driver.Main.hscCompileCoreExpr1 (<no location info>)\n      ...\n\n\n# How to proceed?\n\n  1. Is this really the best way to profile a GHC Plugin even? Perhaps I missed something, this seems awfully complex…\n  2. 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_libs` doesn’t exist).\n\n",
  "title": "How to profile a GHC Plugin?"
}