Skip to content

Commit

Permalink
feat(example): feature with dhat mem-profiling
Browse files Browse the repository at this point in the history
**Motivaion**
Generalized Implementation #272

**Overview**
Thanks to cli+dhat we can now run any test cases and measure any memory usage
  • Loading branch information
cyphersnake committed May 28, 2024
1 parent e9ec84b commit e1ab7f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
poseidon-example = ["run", "--example", "poseidon", "--release", "--", "--json"]
trivial-example = ["run", "--example", "trivial", "--release", "--", "--json"]
cli-example = ["run", "--example", "cli", "--release", "--"]
cli-dhat = ["run", "--example", "cli", "--release", "--features", "dhat-heap", "--"]
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tracing = { version = "0.1.40", features = ["attributes"] }
bincode = "1.3"
clap = { version = "4.5.4", features = ["derive"] }
criterion = "0.5.1"
dhat = "0.3.3"
halo2_gadgets = { git = "https://github.com/snarkify/halo2", branch = "snarkify/dev", features = ["unstable"] }
maplit = "1.0.2"
prettytable-rs = "0.10.0"
Expand All @@ -49,3 +50,6 @@ harness = false
[[bench]]
name = "poseidon"
harness = false

[features]
dhat-heap = []
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ cargo poseidon-example | python3 .scripts/build_profiling.py --min-runtime 0.1s
cargo poseidon-example > log; cat log | python3 .scripts/build_profiling.py
```

# Memory-Profiling
The [dhat](https://valgrind.org/docs/manual/dh-manual.html) utility and the [dhat-rs](https://github.com/nnethercote/dhat-rs) experimental crate are used

```bash
# Run dhat with default IVC (poseidon+trivial)
cargo cli-dhat

# Check available params of run
cargo cli-dhat --help
```

# Benchmark

For benches, please check [benches](benches) folder.
Expand Down
7 changes: 7 additions & 0 deletions examples/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

use std::{array, num::NonZeroUsize};

use clap::{Parser, ValueEnum};
Expand Down Expand Up @@ -154,6 +158,9 @@ fn fold(
}

fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();

let args = Args::parse();

let builder = tracing_subscriber::fmt()
Expand Down

0 comments on commit e1ab7f5

Please sign in to comment.