Skip to content
Draft

bench #1759

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ chrono = { version = "0.4.45", default-features = false, features = [] }
clap = { version = "4.6.6", default-features = true, features = [] }
color-eyre = { version = "0.6.5", default-features = false, features = [] }
colored = { version = "3.1.1", default-features = false, features = [] }
criterion = { version = "0.8.2", default-features = false, features = [] }
criterion = { version = "0.8.2", default-features = false, features = [
"cargo_bench_support",
"html_reports",
"plotters",
] }
iai-callgrind = { version = "0.16.1" }
crossbeam-utils = { version = "0.8.22", default-features = false, features = [] }
dashmap = { version = "6.2.1", default-features = false, features = [] }
derive_builder = { version = "0.20.2", default-features = false, features = [] }
Expand Down
2 changes: 1 addition & 1 deletion acl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ clock = { workspace = true, features = ["virtual"] }
# differential-test against it, so make it available whenever test/bench targets are built.
dataplane-acl = { path = ".", features = ["reference"] }
bolero = { workspace = true, features = ["std"] }
criterion = { workspace = true, features = ["cargo_bench_support"] }
criterion = { workspace = true }
dpdk = { workspace = true, features = ["test"] }
match-action = { workspace = true, features = ["derive", "bolero"] }
net = { workspace = true, features = ["test_buffer", "builder"] }
Expand Down
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ let
duvet
gateway-crd
gettext
iai-callgrind-runner
jq
just
kopium
Expand All @@ -188,6 +189,8 @@ let
rust-toolchain
shellcheck
skopeo
static-web-server
valgrind
wasmtime
wget
yq
Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ignore = [
"RUSTSEC-2024-0436",
# proc-macro-error2 is unmaintained but is needed by multi_index_map_derive, and our own fixin; ignore until both dependencies have migrated away from it.
"RUSTSEC-2026-0173",
"RUSTSEC-2025-0141",
]

[licenses]
Expand Down
90 changes: 85 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ kernel := if platform == "wasm32-wasip1" { "wasip1" } else { "linux" }
# cargo build profile (debug/release/fuzz)
profile := "debug"

export callgrind_package := "dataplane-routing"
export callgrind_bench := "fib_lookup_callgrind"

# sanitizer to use (address/thread/safe-stack/cfi/"")
sanitize := ""

Expand Down Expand Up @@ -199,14 +202,66 @@ fuzz target time="60s" *args="":
{{ if sanitize == "thread" { "--build-std" } else { "" } }} \
{{ _cargo_feature_flags }} {{ args }}

# Build and run the criterion benches. The rte_acl benches are gated behind the
# `dpdk` feature, so run `just features=dpdk bench` to exercise them; a plain
# `just bench` builds them as empty `main()` and only runs the reference benches.
[private]
[script]
_bench-release-only:
{{ _just_debuggable_ }}
if [ '{{ profile }}' != "release" ]; then
echo "error: benchmarks want profile=release, not '{{ profile }}'" >&2
echo " run: just profile=release bench" >&2
exit 1
fi

[doc("Wall-clock time, via criterion")]
[script]
bench: (build "benches")
bench *args: _bench-release-only (build "benches")
{{ _just_debuggable_ }}
shopt -s nullglob
for bench in ./results/benches/bin/*; do "$bench" --bench; done
for bench in ./results/benches/bin/*; do
case "${bench}" in
*_callgrind) continue ;;
esac
"${bench}" --bench {{ args }}
done
if [ -f target/criterion/report/index.html ]; then
echo
echo "html report: target/criterion/report/index.html"
fi

[doc("Instructions and cache traffic, via iai-callgrind")]
[script]
bench-callgrind *args:
{{ _just_debuggable_ }}
cargo bench -p "${callgrind_package}" --bench "${callgrind_bench}" {{ args }}

[doc("Compare against a baseline and print a markdown report")]
[script]
bench-compare baseline="base" *args:
{{ _just_debuggable_ }}
mkdir -p results/bench
if find target/iai -type f -name '*base@{{ baseline }}*' -print -quit 2>/dev/null | grep -q . \
&& cargo bench -p "${callgrind_package}" --bench "${callgrind_bench}" -- \
--baseline='{{ baseline }}' --output-format=json > results/bench/run.jsonl 2>/dev/null; then
./scripts/bench-report.ts results/bench/run.jsonl {{ args }}
else
cargo bench -p "${callgrind_package}" --bench "${callgrind_bench}" -- \
--save-baseline='{{ baseline }}' --output-format=json > results/bench/run.jsonl
./scripts/bench-report.ts results/bench/run.jsonl {{ args }}
fi

[doc("Record a baseline for `bench-compare`, without reporting")]
[script]
bench-baseline name="base":
{{ _just_debuggable_ }}
cargo bench -p "${callgrind_package}" --bench "${callgrind_bench}" -- \
--save-baseline='{{ name }}' > /dev/null
echo "recorded baseline '{{ name }}'"

[doc("Serve the criterion html report over http")]
[script]
bench-serve port="8080":
{{ _just_debuggable_ }}
just serve ./target/criterion '{{ port }}' report/index.html

[script]
build-each *args: (build "workspace" args)
Expand Down Expand Up @@ -754,6 +809,31 @@ coverage *args:
cargo llvm-cov report --branch --lcov --output-path="${out}/lcov.info"
cargo llvm-cov report --branch --codecov --output-path="${out}/codecov.json"
cargo llvm-cov report --branch --summary-only
echo
echo "html report: ${out}/html/index.html (\`just serve-coverage\` to browse it)"

serve_host := "127.0.0.1"

[doc("Serve a directory of generated html over http")]
[script]
serve dir port="8080" index="index.html":
{{ _just_debuggable_ }}
if [ ! -d '{{ dir }}' ]; then
echo "error: no such directory: {{ dir }}" >&2
exit 1
fi
server="$(command -v static-web-server || true)"
if [ -z "${server}" ] && [ -x ./devroot/bin/static-web-server ]; then
server="$(pwd)/devroot/bin/static-web-server"
fi
if [ -z "${server}" ]; then
echo "error: static-web-server not found; re-enter the dev shell, or \`just setup-roots\`" >&2
exit 1
fi
echo "serving {{ dir }} at http://{{ serve_host }}:{{ port }}/{{ index }} (ctrl-c to stop)"
"${server}" --root '{{ dir }}' --host '{{ serve_host }}' --port '{{ port }}' --log-level warn

serve-coverage port="8080": (serve "./target/nextest/coverage/html" port)

[script]
duvet *args:
Expand Down
4 changes: 4 additions & 0 deletions nix/overlays/dataplane-dev.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ in
opengrep = final.callPackage ../pkgs/opengrep {
src = sources.opengrep;
};
iai-callgrind-runner = final.callPackage ../pkgs/iai-callgrind-runner {
inherit (override-packages) rustPlatform;
version = "0.16.1";
};
cargo-bolero = prev.cargo-bolero.override { inherit (override-packages) rustPlatform; };
cargo-deny = prev.cargo-deny.override { inherit (override-packages) rustPlatform; };
cargo-edit = prev.cargo-edit.override { inherit (override-packages) rustPlatform; };
Expand Down
18 changes: 18 additions & 0 deletions nix/pkgs/iai-callgrind-runner/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Open Network Fabric Authors
{
fetchCrate,
rustPlatform,
version,
...
}:
rustPlatform.buildRustPackage (final: {
pname = "iai-callgrind-runner";
inherit version;
src = fetchCrate {
inherit (final) pname version;
hash = "sha256-wJTwaqAz8GWCJ/l9GRXYBVBkpPYrWxN4VQ7GdRFXmzM=";
};
cargoHash = "sha256-4N7P23bCeeJee/Cm3sSORByh+HzflOENqYqpu629mpA=";
doCheck = false;
})
13 changes: 12 additions & 1 deletion routing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@ procfs = { workspace = true }
netdev = { workspace = true }

[dev-dependencies]
dataplane-routing = { path = ".", features = ["testing"] }
lpm = { workspace = true, features = ["testing"] }
clock = { workspace = true, features = ["virtual"] }
criterion = { workspace = true }
iai-callgrind = { workspace = true }
bolero = { workspace = true, default-features = false }
concurrency = { workspace = true }
lpm = { workspace = true, features = ["testing"] }
net = { workspace = true, features = ["test_buffer"] }
rand = { workspace = true, default-features = false, features = ["thread_rng"] }
tokio = { workspace = true, features = ["time", "test-util"] }
tracing-test = { workspace = true, features = [] }

[[bench]]
name = "fib_lookup"
harness = false

[[bench]]
name = "fib_lookup_callgrind"
harness = false
Loading
Loading