Skip to content

Commit

Permalink
Instructions for profiling; improve default.nix (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
samalws authored and ggrieco-tob committed Feb 8, 2022
1 parent 683bb3a commit 89f47c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ cabal.project.local
crytic-export/
echidna.cabal
*.swp
profiles/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,18 @@ All these can be solved, from a few seconds to one or two minutes on a laptop co
- [echidna-parade: A Tool for Diverse Multicore Smart Contract Fuzzing](https://agroce.github.io/issta21.pdf), Alex Groce, Gustavo Grieco - ISSTA '21

If you are using Echidna on an academic work, consider applying to the [Crytic $10k Research Prize](https://blog.trailofbits.com/2019/11/13/announcing-the-crytic-10k-research-prize/).

## Debugging Performance Problems

The best way to deal with an Echidna performance issue is to run `echidna-test` with profiling on.
This creates a text file, `echidna-test.prof`, which shows which functions take up the most CPU and memory usage.

To build a version of `echidna-test` that supports profiling, either Stack or Nix should be used.
With Stack, adding the flag `--profile` will make the build support profiling.
With Nix, running `nix-build --arg profiling true` will make the build support profiling.

To run with profiling on, add the flags `+RTS -p` to your original `echidna-test` command.

Performance issues in the past have been because of functions getting called repeatedly when they could be memoized,
and memory leaks related to Haskell's lazy evaluation;
checking for these would be a good place to start.
14 changes: 10 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
name = "nixpkgs-unstable-2021-10-15";
url = "https://github.com/nixos/nixpkgs/archive/ee084c02040e864eeeb4cf4f8538d92f7c675671.tar.gz";
sha256 = "sha256:1x8amcixdaw3ryyia32pb706vzhvn5whq9n8jin0qcha5qnm1fnh";
}) {}
}) {},
profiling ? false,
tests ? true
}:

let
Expand Down Expand Up @@ -32,6 +34,8 @@ let

v = "1.7.2";

testInputs = [ slither-analyzer solc ];

f = { mkDerivation, aeson, ansi-terminal, base, base16-bytestring, binary
, brick, bytestring, cborg, containers, data-dword, data-has, deepseq
, directory, exceptions, filepath, hashable, hevm, hpack, lens, lens-aeson
Expand All @@ -58,26 +62,28 @@ let
executableHaskellDepends = libraryHaskellDepends;
testHaskellDepends = [ tasty tasty-hunit tasty-quickcheck ];
libraryToolDepends = [ hpack ];
testToolDepends = [ slither-analyzer solc ];
testToolDepends = testInputs;
configureFlags = if profiling then [ "--enable-profiling" "--enable-library-profiling" ] else [];
preConfigure = ''
hpack
# re-enable dynamic build for Linux
sed -i -e 's/os(linux)/false/' echidna.cabal
'';
shellHook = "hpack";
license = pkgs.lib.licenses.agpl3;
doHaddock = false;
doCheck = true;
doCheck = tests;
};

echidna = pkgs.haskellPackages.callPackage f { };
echidnaShell = pkgs.haskellPackages.shellFor {
packages = p: [ echidna ];
shellHook = "hpack";
buildInputs = with pkgs.haskellPackages; [
hlint
cabal-install
haskell-language-server
];
nativeBuildInputs = if tests then [] else testInputs;
};
in
if pkgs.lib.inNixShell
Expand Down

0 comments on commit 89f47c1

Please sign in to comment.