Skip to content

Instantly share code, notes, and snippets.

@enricobottazzi
Last active August 31, 2023 13:38
Show Gist options
  • Save enricobottazzi/0e93d67f37c822314847fb87d440dc43 to your computer and use it in GitHub Desktop.
Save enricobottazzi/0e93d67f37c822314847fb87d440dc43 to your computer and use it in GitHub Desktop.
Profiling In Rust

Flamegraph

For function calls

https://github.com/flamegraph-rs/flamegraph

cargo install flamegraph
CARGO_PROFILE_BENCH_DEBUG=true sudo cargo flamegraph --bench full_solvency_flow -- --bench
open flamegraph.svg

DHAT

For heap allocation

cargo.toml

[features]
dev-graph = ["halo2_proofs/dev-graph", "plotters"]
dhat-heap = []

[dependencies]
dhat = "0.3.2"

[profile.release]
debug = 1

tests.rs

    #[cfg(feature = "dhat-heap")]
    #[global_allocator]
    static ALLOC: dhat::Alloc = dhat::Alloc;

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

        // create new merkle tree
        let merkle_tree =
            MerkleSumTree::<N_ASSETS, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
                .unwrap();
  }

cargo test test_mst --features dhat-heap

For visualization => https://nnethercote.github.io/dh_view/dh_view.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment