Skip to content

Commit

Permalink
examples: zigzag: add heap profiler
Browse files Browse the repository at this point in the history
Rename original feature 'profile' to 'cpu-profile' and add new
feature: `heap-profile`.
  • Loading branch information
schomatis committed Feb 28, 2019
1 parent 5601967 commit 5cfd1d9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
5 changes: 3 additions & 2 deletions filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -51,6 +51,7 @@ cbindgen = "0.6.8"

[features]
default = []
profile = []
cpu-profile = []
heap-profile = []
simd = ["storage-proofs/simd"]
asm = ["storage-proofs/asm"]
12 changes: 6 additions & 6 deletions filecoin-proofs/examples/beacon-post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand All @@ -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
Expand All @@ -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() {}

Expand Down
12 changes: 6 additions & 6 deletions filecoin-proofs/examples/drgporep-vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::*;
Expand All @@ -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
Expand All @@ -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() {}

Expand Down
12 changes: 6 additions & 6 deletions filecoin-proofs/examples/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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() {}

Expand Down
33 changes: 27 additions & 6 deletions filecoin-proofs/examples/zigzag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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() {}

Expand Down

0 comments on commit 5cfd1d9

Please sign in to comment.