Skip to content

Commit

Permalink
Add profile.bench-memory and use it for memory profiling (#4494)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Jan 30, 2024
1 parent f209a9d commit c90120e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,15 @@ codegen-units = 1

# Builds with debug metadata but not debug assertions
# for testing GIGO code paths
[profile.debug-without-assertions]
[profile.dev-without-assertions]
inherits = "dev"
debug-assertions = false

# Enable debug information specifically for memory profiling.
# https://docs.rs/dhat/0.2.1/dhat/#configuration
#
# 2021-01-08: This would be nicer as a named profile, e.g. [profile.memory]
# https://github.com/rust-lang/cargo/issues/6988
[profile.bench]
lto = true

# Enable debug information specifically for memory profiling.
# https://docs.rs/dhat/0.2.1/dhat/#configuration
[profile.bench-memory]
inherits = "bench"
debug = true
debug-assertions = false
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies = [
description = "Run specific tests with debug assertions disabled"
category = "CI"
dependencies = [
"test-debug-without-assertions",
"test-dev-without-assertions",
]

[tasks.ci-job-test-tutorials-local]
Expand Down
8 changes: 6 additions & 2 deletions tools/benchmark/memory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ fn main() {
Command::new("cargo")
.arg("build")
.arg("--examples")
.arg("--profile")
.arg("bench-memory")
.arg("--features")
.arg("icu_benchmark_macros/benchmark_memory")
.arg("--features")
Expand All @@ -108,7 +110,7 @@ fn main() {
eprintln!("Failed to collect examples {err:?}");
process::exit(1);
});
fs::read_dir(root_dir.join("target/debug/examples"))
fs::read_dir(root_dir.join("target/bench-memory/examples"))
.unwrap()
.flat_map(|entry| {
entry.ok()?.file_name().into_string().ok().and_then(|s| {
Expand All @@ -122,6 +124,8 @@ fn main() {
.collect()
};

println!("[memory] Examples to benchmark: {examples:?}");

// benchmarks/memory/{os}
let benchmark_dir = root_dir
.join("benchmarks/memory")
Expand Down Expand Up @@ -156,7 +160,7 @@ fn main() {
.arg("--example")
.arg(example)
.arg("--profile")
.arg("bench")
.arg("bench-memory")
// The dhat-rs instrumentation is hidden behind the "benchmark_memory" feature in the
// icu_benchmark_macros package.
.arg("--features")
Expand Down
4 changes: 2 additions & 2 deletions tools/make/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ env = { RUSTFLAGS = "--cfg=icu4x_run_size_tests" }
command = "cargo"
args = ["test", "--all-features", "--all-targets", "--no-fail-fast"]

[tasks.test-debug-without-assertions]
[tasks.test-dev-without-assertions]
description = "Run all Rust unit and integration tests without debug assertions (GIGO mode)"
category = "ICU4X Development"
command = "cargo"
args = ["test", "--profile=debug-without-assertions", "--all-features", "--tests", "--no-fail-fast"]
args = ["test", "--profile=dev-without-assertions", "--all-features", "--tests", "--no-fail-fast"]

[tasks.test-docs]
description = "Run all Rust doctests with all features"
Expand Down
4 changes: 2 additions & 2 deletions tools/make/valgrind.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ args = [
"build", "--examples",
"--features", "icu_benchmark_macros/rust_global_allocator",
"--features", "zerovec/serde",
"--profile", "bench",
"--profile", "bench-memory",
]

[tasks.valgrind]
Expand All @@ -33,7 +33,7 @@ mkdir benchmarks
mkdir benchmarks/valgrind
# Re-run the build command only to generate the JSON output (--message-format=json)
output = exec cargo build --examples --message-format=json --features icu_benchmark_macros/rust_global_allocator --features zerovec/serde --profile bench
output = exec cargo build --examples --message-format=json --features icu_benchmark_macros/rust_global_allocator --features zerovec/serde --profile bench-memory
if ${output.code}
trigger_error "Build failed! To debug, build examples with `--features icu_benchmark_macros/rust_global_allocator`"
end
Expand Down

0 comments on commit c90120e

Please sign in to comment.