diff --git a/.buildkite/benchmark.sh b/.buildkite/benchmark.sh index 79ff737c23a..93abe9f0f21 100755 --- a/.buildkite/benchmark.sh +++ b/.buildkite/benchmark.sh @@ -3,20 +3,11 @@ set -euo pipefail -netname="${1-}" - -if [ -z "$netname" ]; then - echo "usage: benchmark.sh NETWORK" - exit 1 -fi - echo "--- Build code and benchmarks" stack build --bench --no-run-benchmarks -export NETWORK=$netname - -echo "+++ Run benchmarks" -stack bench cardano-wallet:restore --interleaved-output --ba "$netname +RTS -N2 -qg -A1m -I0 -T -M8G -h -RTS" +echo "+++ Run benchmarks - $NETWORK" +stack bench cardano-wallet:restore --interleaved-output --ba "$NETWORK +RTS -N2 -qg -A1m -I0 -T -M8G -h -RTS" hp2pretty restore.hp diff --git a/.buildkite/nightly.yml b/.buildkite/nightly.yml index bf9abbbeae9..2e0902a98b8 100644 --- a/.buildkite/nightly.yml +++ b/.buildkite/nightly.yml @@ -2,12 +2,16 @@ env: NIX_PATH: "channel:nixos-19.03" steps: - label: 'Restore benchmark - testnet' - command: "./.buildkite/benchmark.sh testnet" + command: "./.buildkite/benchmark.sh" timeout_in_minutes: 60 agents: system: x86_64-linux + env: + NETWORK: testnet - label: 'Restore benchmark - mainnet' - command: "./.buildkite/benchmark.sh mainnet" + command: "./.buildkite/benchmark.sh" timeout_in_minutes: 60 agents: system: x86_64-linux + env: + NETWORK: mainnet diff --git a/test/bench/Main.hs b/test/bench/Main.hs index c305565239e..c4515054666 100644 --- a/test/bench/Main.hs +++ b/test/bench/Main.hs @@ -61,6 +61,8 @@ import Fmt ( fmt, (+|), (+||), (|+), (||+) ) import Say ( sayErr ) +import System.Environment + ( getArgs, setEnv ) import System.IO ( BufferMode (..), hSetBuffering, stderr, stdout ) @@ -77,6 +79,7 @@ main = do hSetBuffering stdout NoBuffering hSetBuffering stderr NoBuffering installSignalHandlers + getArgs >>= overrideEnvironment prepareNode runBenchmarks [ bench ("restore " <> toText network <> " seq") @@ -125,6 +128,17 @@ bench benchName action = do printResult :: Text -> Double -> IO () printResult benchName dur = sayErr . fmt $ " "+|benchName|+": "+|secs dur|+"" +-- FIXME This only exists because somehow, in buildkite, we can't pass ENV var +-- to the haskell executable? There's probably some Nix magic going on and I +-- don't have time for this. +overrideEnvironment :: [String] -> IO () +overrideEnvironment [ntwrk] = + setEnv "NETWORK" ntwrk +overrideEnvironment [] = + return () +overrideEnvironment _ = + fail "benchmark expects only one argument to override the '$NETWORK' ENV var" + {------------------------------------------------------------------------------- Benchmarks -------------------------------------------------------------------------------}