time-ghc-modules/README.md

88 lines
2.5 KiB
Markdown
Raw Normal View History

2021-08-01 13:55:45 +03:00
# time-ghc-modules
2021-08-01 15:39:53 +03:00
Figure out why your builds are slow. This tool analyzes how long it takes GHC to compile your Haskell modules, broken down by phase.
2021-08-01 13:55:45 +03:00
2021-08-01 15:39:53 +03:00
# Quick start
2021-08-01 15:33:53 +03:00
``` shell
cd <my-project>
2021-08-01 15:36:06 +03:00
2021-08-01 15:33:53 +03:00
stack clean
stack build --ghc-options "-ddump-to-file -ddump-timings"
2021-08-01 15:36:06 +03:00
# ----- OR -----
cabal clean
cabal build all --ghc-options "-ddump-to-file -ddump-timings"
2021-08-01 15:33:53 +03:00
```
2022-06-15 02:26:07 +03:00
If you have Nix, you can simply run `time-ghc-modules` from Nixpkgs!
2021-08-01 15:33:53 +03:00
``` shell
2022-06-15 02:24:42 +03:00
nix run nixpkgs#time-ghc-modules
2021-08-01 15:33:53 +03:00
```
2022-06-15 02:26:07 +03:00
Or, clone the repo first:
2021-08-01 15:33:53 +03:00
``` shell
2022-06-15 02:24:42 +03:00
git clone git@github.com:codedownio/time-ghc-modules.git /path/to/time-ghc-modules
# If you have Nix, you can use the fully reproducible version
/path/to/time-ghc-modules/time-ghc-modules-nix
# Otherwise, your system needs to have SQLite >= 3.33.0, Python 3, and sed
2021-08-01 15:33:53 +03:00
/path/to/time-ghc-modules/time-ghc-modules
```
2021-08-01 15:39:53 +03:00
The script will search for all your `*.dump-timings` files and analyze them. It will finish by printing out the path to an HTML file:
``` shell
...
--> Wrote report at file:///tmp/tmp.pvnp4FYmLa/report.html
```
2021-08-01 14:04:24 +03:00
# Example: hledger
You can generate the time report below for [hledger](https://github.com/simonmichael/hledger) by running the following commands (assuming you have Nix).
``` shell
2021-08-01 14:04:24 +03:00
set -e
cd $(mktemp -d)
git clone git@github.com:simonmichael/hledger.git
git clone git@github.com:codedownio/time-ghc-modules.git
cd hledger
stack build --ghc-options "-ddump-to-file -ddump-timings"
../time-ghc-modules/time-ghc-modules-nix
```
![hledger profile](./hledger.png)
2021-08-03 23:46:48 +03:00
2021-08-04 09:20:36 +03:00
# Tips
2024-02-06 06:15:43 +03:00
* The script will output its log messages to `stderr` and print the final report path to `stdout` (assuming it didn't exit with a failure). This makes it easy to use the output in scripts. For example:
2021-08-04 09:20:36 +03:00
``` shell
# Build the report and open it in your browser
> firefox $(/path/to/time-ghc-modules/time-ghc-modules)
```
``` shell
# Build the report in CI and stash it somewhere
> cp $(/path/to/time-ghc-modules/time-ghc-modules) $MY_CI_ARTIFACTS_DIR/
```
2024-02-06 06:15:43 +03:00
* You can also look at the timing of individual components, but doing e.g. `stack build some-component:lib`. But, make sure to clean up any old `.dump-timings` files from previous runs:
``` shell
find . -name "*.dump-timings" | xargs rm
```
* GHC's `-dumpdir` option can be used to consolidate the `.dump-timings` files, so they aren't left all over your source tree. For example:
``` shell
stack build --ghc-options "-ddump-to-file -ddump-timings -dumpdir .ghcdump"
```
2021-08-03 23:46:48 +03:00
# Compatibility
The flag `-ddump-timings` is available for `GHC >= 8.4.1`.