Skip to content

Commit

Permalink
Document Haskell profiling and default to -fprof-auto (digital-asset#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cocreature authored Jul 2, 2019
1 parent 2bb9276 commit c66211d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
16 changes: 0 additions & 16 deletions BAZEL-haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,6 @@ alias(
)
```

## Profiling

To produce a binary with profiling information, you need to pass `-c
dbg` to Bazel. E.g., `bazel build -c dbg damlc` will build a profiled
version of `damlc`. Note that by default Bazel won’t automatically add
cost centres in your code. To get cost centres, you can either add
[cost centres manually](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html#inserting-cost-centres-by-hand)
or use one of the
[options provided by GHC](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html#compiler-options-for-profiling)
to add them automatically.
You can either add those options in the `compiler_flags` section of a
specific target, modify the `da_haskell_library` wrapper in
`bazel_tools/haskell.bzl` to add a flag to all DAML targets and
libraries or use it for all targets by modifying the
`compiler_flags` in the `haskell_toolchain`.

## Further reading:

- ["Bazel User Guide"](https://github.com/DACH-NY/da/blob/master/BAZEL.md) (DAML specific)
Expand Down
7 changes: 7 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ config_setting(
],
)

config_setting(
name = "profiling_build",
values = {
"compilation_mode": "dbg",
},
)

load(
"@io_tweag_rules_haskell//haskell:c2hs.bzl",
"c2hs_toolchain",
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ from the `.bazelrc` file.
If you work with multiple copies of this repository, you can point all of them to the same disk cache
by overwriting these configs in either a `.bazelrc.local` file in each copy, or a `~/.bazelrc` file
in your home directory.


### Haskell profiling builds

To build Haskell executables with profiling enabled, pass `-c dbg` to
Bazel, e.g. `bazel build -c dbg damlc`. If you want to build the whole
SDK with profiling enabled use `daml-sdk-head --profiling`.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ haskell_register_ghc_nixpkgs(
"-hide-package=ghc-boot-th",
"-hide-package=ghc-boot",
],
compiler_flags_select = {
"@com_github_digital_asset_daml//:profiling_build": ["-fprof-auto"],
"//conditions:default": [],
},
locale_archive = "@glibc_locales//:locale-archive",
nix_file = "//nix:bazel.nix",
nix_file_deps = nix_ghc_deps,
Expand Down
14 changes: 12 additions & 2 deletions dev-env/bin/daml-sdk-head
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,29 @@ fi


NUKE=0
PROFILING=0
for opt in "$@" ; do
case $opt in
"--nuke")
NUKE=1
;;
"--profiling")
PROFILING=1
;;
*)
echo "Unknown option: $opt"
echo "Available options:"
echo " --nuke Remove existing daml installation before installing daml-head."
echo " --profiling Build Haskell executables with profiling enabled."
exit 1
esac
done

BAZEL_MODE_FLAG=""

if [ "$PROFILING" -ne "0" ] ; then
BAZEL_MODE_FLAG="-c dbg"
fi

readonly DAML_HOME="$HOME/.daml"
if [ -d $DAML_HOME ] && [ "$NUKE" -ne "0" ] ; then
Expand Down Expand Up @@ -58,9 +68,9 @@ function cleanup() {
trap cleanup EXIT

# Building here separately so the user can see the build process which could take a while
bazel build //release:sdk-head-tarball.tar.gz
bazel build $BAZEL_MODE_FLAG //release:sdk-head-tarball.tar.gz

readonly TARBALL=$(bazel info bazel-genfiles)/release/sdk-head-tarball.tar.gz
readonly TARBALL=$(bazel info bazel-genfiles $BAZEL_MODE_FLAG)/release/sdk-head-tarball.tar.gz
readonly TMPDIR=$(mktemp -d)
mkdir -p $TMPDIR/sdk-head

Expand Down

0 comments on commit c66211d

Please sign in to comment.