@@ -23,20 +23,48 @@ cargo fuzz run fuzz_raw -j8
2323
2424Uncomment the ` println! ` calls for a more verbose output.
2525
26- # Coverage
26+ # Coverage v3
27+
28+ Run all these commands from inside "fuzz" folder:
29+
30+ Optionally, remove old coverage runs from ` proffiles ` folder.
31+
32+ Modify ` target_name ` in ` run_coverage.py `
33+
34+ Run it
35+
36+ ```
37+ rustup component add llvm-tools-preview
38+ grcov proffiles/ -s $HOME --binary-path ./target/x86_64-unknown-linux-gnu/debug -t html --branch --ignore-not-existing --ignore "target/debug/build/*" --ignore "*mock.rs" --ignore "*tests.rs" -o coverage --llvm
39+ ```
40+
41+ Will put coverage from ` proffiles/* ` into ` coverage ` folder.
42+
43+ Open ` coverage/index.html ` to see it.
44+
45+ To upload the coverage to github pages:
2746
2847```
29- cd fuzz
30- cargo fuzz coverage fuzz_raw
31- $HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov show target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/fuzz_raw --format=html -instr-profile=coverage/fuzz_raw/coverage.profdata --ignore-filename-regex='.*/\.cargo/.*' > index.html
32- firefox index.html
48+ git checkout gh-pages
49+ cp -rf fuzz/coverage_tmpname coverage/{target_name}
50+ # update index.html if new target
51+ git add coverage
52+ git commit -a --amend
53+ git push -f
54+ git checkout -
3355```
3456
35- # Coverage v2
57+ # Profiling
58+
59+ You can run perf on the fuzzer binary as is.
60+
61+ Delete the corpus if you want to see performance with an empty corpus, or keep the corpus to see performance when processing the corpus.
3662
3763```
38- RUSTFLAGS="--cfg fuzzing -C opt-level=3 -C target-cpu=native -C instrument-coverage" cargo run --bin fuzz_raw_coverage
39- # rm -rf proffiles/*
40- # Then run:
41- grcov proffiles/ -s $HOME --binary-path ./target/x86_64-unknown-linux-gnu/debug -t html --branch --ignore-not-existing --ignore "target/debug/build/*" --ignore "*mock.rs" --ignore "*tests.rs" -o coverage3/ --llvm
64+ echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
65+ # Copy the fuzzer command here, it is printed when running cargo fuzz
66+ perf record --call-graph=dwarf target/x86_64-unknown-linux-gnu/release/fuzz_starlight_live_oneblock_events -artifact_prefix=/home/tomasz/projects/fuzz-tanssi-runtime/fuzz/artifacts/fuzz_starlight_live_oneblock_events /home/tomasz/projects/fuzz-tanssi-runtime/fuzz/corpus/fuzz_starlight_live_oneblock_events
67+ perf script | inferno-collapse-perf > stacks.folded
68+ cat stacks.folded | inferno-flamegraph > flamegraph.svg
69+ # open in a web browser flamegraph.svg
4270```
0 commit comments