From 5cfd1d931ebb674ce235c790c217e7b9bf52cb06 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Tue, 26 Feb 2019 12:44:48 -0300 Subject: [PATCH] examples: zigzag: add heap profiler Rename original feature 'profile' to 'cpu-profile' and add new feature: `heap-profile`. --- Cargo.toml | 3 +- filecoin-proofs/Cargo.toml | 5 +-- filecoin-proofs/examples/beacon-post.rs | 12 +++---- filecoin-proofs/examples/drgporep-vanilla.rs | 12 +++---- filecoin-proofs/examples/encoding.rs | 12 +++---- filecoin-proofs/examples/zigzag.rs | 33 ++++++++++++++++---- 6 files changed, 50 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5bbe00dd2..39ce5aa6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ debug = true [features] default = [] -profile = ["filecoin-proofs/profile"] +cpu-profile = ["filecoin-proofs/cpu-profile"] +heap-profile = ["filecoin-proofs/heap-profile"] simd = ["storage-proofs/simd", "filecoin-proofs/simd"] asm = ["storage-proofs/asm", "filecoin-proofs/asm"] diff --git a/filecoin-proofs/Cargo.toml b/filecoin-proofs/Cargo.toml index 4e7d2ce7f..25e5f6b47 100644 --- a/filecoin-proofs/Cargo.toml +++ b/filecoin-proofs/Cargo.toml @@ -38,7 +38,7 @@ slog = { version = "2.4.1", features = ["max_level_trace", "release_max_level_tr regex = "1" [dev-dependencies] -gperftools = { git = "https://github.com/dignifiedquire/rust-gperftools" } +gperftools = "0.2" scopeguard = "0.3.3" [dependencies.pairing] @@ -51,6 +51,7 @@ cbindgen = "0.6.8" [features] default = [] -profile = [] +cpu-profile = [] +heap-profile = [] simd = ["storage-proofs/simd"] asm = ["storage-proofs/asm"] diff --git a/filecoin-proofs/examples/beacon-post.rs b/filecoin-proofs/examples/beacon-post.rs index 316a91736..ce80cf454 100644 --- a/filecoin-proofs/examples/beacon-post.rs +++ b/filecoin-proofs/examples/beacon-post.rs @@ -4,7 +4,7 @@ extern crate rand; extern crate sapling_crypto; #[macro_use] extern crate clap; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] extern crate gperftools; extern crate memmap; extern crate tempfile; @@ -15,7 +15,7 @@ extern crate filecoin_proofs; extern crate storage_proofs; use clap::{App, Arg}; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] use gperftools::profiler::PROFILER; use pairing::bls12_381::Bls12; use rand::{Rng, SeedableRng, XorShiftRng}; @@ -31,7 +31,7 @@ use storage_proofs::hasher::PedersenHasher; use storage_proofs::proof::ProofScheme; use storage_proofs::{vdf_post, vdf_sloth}; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn start_profile(stage: &str) { PROFILER @@ -41,17 +41,17 @@ fn start_profile(stage: &str) { .unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(not(feature = "cpu-profile"))] #[inline(always)] fn start_profile(_stage: &str) {} -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn stop_profile() { PROFILER.lock().unwrap().stop().unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(not(feature = "cpu-profile"))] #[inline(always)] fn stop_profile() {} diff --git a/filecoin-proofs/examples/drgporep-vanilla.rs b/filecoin-proofs/examples/drgporep-vanilla.rs index 6de58fff3..0e09b69da 100644 --- a/filecoin-proofs/examples/drgporep-vanilla.rs +++ b/filecoin-proofs/examples/drgporep-vanilla.rs @@ -4,7 +4,7 @@ extern crate rand; extern crate sapling_crypto; #[macro_use] extern crate clap; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] extern crate gperftools; #[macro_use] extern crate slog; @@ -17,7 +17,7 @@ use pairing::bls12_381::Bls12; use rand::{Rng, SeedableRng, XorShiftRng}; use std::time::{Duration, Instant}; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] use gperftools::profiler::PROFILER; use storage_proofs::drgporep::*; @@ -30,7 +30,7 @@ use storage_proofs::proof::ProofScheme; use filecoin_proofs::FCP_LOG; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn start_profile(stage: &str) { PROFILER @@ -40,17 +40,17 @@ fn start_profile(stage: &str) { .unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(not(feature = "cpu-profile"))] #[inline(always)] fn start_profile(_stage: &str) {} -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn stop_profile() { PROFILER.lock().unwrap().stop().unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(not(feature = "cpu-profile"))] #[inline(always)] fn stop_profile() {} diff --git a/filecoin-proofs/examples/encoding.rs b/filecoin-proofs/examples/encoding.rs index b58e83405..fddc75f83 100644 --- a/filecoin-proofs/examples/encoding.rs +++ b/filecoin-proofs/examples/encoding.rs @@ -4,7 +4,7 @@ extern crate rand; extern crate sapling_crypto; #[macro_use] extern crate clap; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] extern crate gperftools; extern crate memmap; extern crate tempfile; @@ -15,7 +15,7 @@ extern crate filecoin_proofs; extern crate storage_proofs; use clap::{App, Arg}; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] use gperftools::profiler::PROFILER; use memmap::MmapMut; use memmap::MmapOptions; @@ -37,7 +37,7 @@ use storage_proofs::zigzag_drgporep::*; use filecoin_proofs::FCP_LOG; -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn start_profile(stage: &str) { PROFILER @@ -47,17 +47,17 @@ fn start_profile(stage: &str) { .unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(not(feature = "cpu-profile"))] #[inline(always)] fn start_profile(_stage: &str) {} -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn stop_profile() { PROFILER.lock().unwrap().stop().unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(not(feature = "cpu-profile"))] #[inline(always)] fn stop_profile() {} diff --git a/filecoin-proofs/examples/zigzag.rs b/filecoin-proofs/examples/zigzag.rs index 246b61374..7f1b005c6 100644 --- a/filecoin-proofs/examples/zigzag.rs +++ b/filecoin-proofs/examples/zigzag.rs @@ -4,7 +4,7 @@ extern crate rand; extern crate sapling_crypto; #[macro_use] extern crate clap; -#[cfg(feature = "profile")] +#[cfg(any(feature = "cpu-profile", feature = "heap-profile"))] extern crate gperftools; extern crate memmap; extern crate tempfile; @@ -15,7 +15,9 @@ extern crate filecoin_proofs; extern crate storage_proofs; use clap::{App, Arg}; -#[cfg(feature = "profile")] +#[cfg(feature = "heap-profile")] +use gperftools::heap_profiler::HEAP_PROFILER; +#[cfg(feature = "cpu-profile")] use gperftools::profiler::PROFILER; use memmap::MmapMut; use memmap::MmapOptions; @@ -43,7 +45,10 @@ use storage_proofs::zigzag_drgporep::*; use filecoin_proofs::FCP_LOG; -#[cfg(feature = "profile")] +// We can only one of the profilers at a time, either CPU (`profile`) +// or memory (`heap-profile`), duplicating the function so they won't +// be built together. +#[cfg(feature = "cpu-profile")] #[inline(always)] fn start_profile(stage: &str) { PROFILER @@ -53,17 +58,33 @@ fn start_profile(stage: &str) { .unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(feature = "heap-profile")] +#[inline(always)] +fn start_profile(stage: &str) { + HEAP_PROFILER + .lock() + .unwrap() + .start(format!("./{}.heap-profile", stage)) + .unwrap(); +} + +#[cfg(not(any(feature = "cpu-profile", feature = "heap-profile")))] #[inline(always)] fn start_profile(_stage: &str) {} -#[cfg(feature = "profile")] +#[cfg(feature = "cpu-profile")] #[inline(always)] fn stop_profile() { PROFILER.lock().unwrap().stop().unwrap(); } -#[cfg(not(feature = "profile"))] +#[cfg(feature = "heap-profile")] +#[inline(always)] +fn stop_profile() { + HEAP_PROFILER.lock().unwrap().stop().unwrap(); +} + +#[cfg(not(any(feature = "cpu-profile", feature = "heap-profile")))] #[inline(always)] fn stop_profile() {}