Skip to content

Commit

Permalink
fix profiling conflicts with no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
torao committed Sep 21, 2022
1 parent e945b42 commit dd8b4f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@torao
33 changes: 1 addition & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! This crate is `no_std` compatible.
//!
#![cfg_attr(not(test), no_std)]
#![no_std]
use core::cmp::min;

use rand::{Error, RngCore, SeedableRng};
Expand Down Expand Up @@ -171,34 +171,3 @@ impl RngCore for TinyMT32 {
Ok(())
}
}

#[cfg(test)]
mod test {

#[test]
#[cfg(not(target_os = "windows"))]
fn profiling() {
use super::*;
use pprof;
use rand::Rng;
let guard = pprof::ProfilerGuardBuilder::default()
.frequency(1000)
.blocklist(&["libc", "libgcc", "pthread"])
.build()
.unwrap();

let mut random = TinyMT64::from_entropy();
for _i in 0..10000 {
let rn = random.gen_range(0.0..1.0);
assert!((0.0..1.0).contains(&rn));
}

if let Ok(report) = guard.report().build() {
println!("report: {:?}", &report);
};
if let Ok(report) = guard.report().build() {
let file = std::fs::File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
};
}
}
26 changes: 26 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,29 @@ fn verify_chi_squared(histogram: &[u32], expected: f64, threshold: f64) {
println!("χ² := {}, expected := {}", chi2, expected);
assert!(chi2 < threshold);
}

#[test]
#[cfg(not(target_os = "windows"))]
fn profiling() {
use pprof;
use rand::Rng;
let guard = pprof::ProfilerGuardBuilder::default()
.frequency(1000)
.blocklist(&["libc", "libgcc", "pthread"])
.build()
.unwrap();

let mut random = TinyMT64::from_entropy();
for _i in 0..10000 {
let rn = random.gen_range(0.0..1.0);
assert!((0.0..1.0).contains(&rn));
}

if let Ok(report) = guard.report().build() {
println!("report: {:?}", &report);
};
if let Ok(report) = guard.report().build() {
let file = std::fs::File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
};
}

0 comments on commit dd8b4f7

Please sign in to comment.