fix windows pprof build

This commit is contained in:
Stephan Dilly 2020-07-04 16:24:51 +02:00
parent 972f071fe4
commit 8f1a1a008a
2 changed files with 4 additions and 3 deletions

View File

@ -40,9 +40,7 @@ serde = "1.0"
anyhow = "1.0.31"
unicode-width = "0.1"
[target.'cfg(unix)'.dependencies]
pprof = { version = "0.3", features = ["flamegraph"], optional = true }
[target.'cfg(macos)'.dependencies]
[target.'cfg(not(windows))'.dependencies]
pprof = { version = "0.3", features = ["flamegraph"], optional = true }
[badges]

View File

@ -2,6 +2,7 @@
/// also we make sure to generate a flamegraph on program exit
pub struct Profiler {
#[cfg(feature = "pprof")]
#[cfg(not(windows))]
guard: pprof::ProfilerGuard<'static>,
}
@ -9,6 +10,7 @@ impl Profiler {
pub fn new() -> Self {
Self {
#[cfg(feature = "pprof")]
#[cfg(not(windows))]
guard: pprof::ProfilerGuard::new(100)
.expect("profiler launch error"),
}
@ -16,6 +18,7 @@ impl Profiler {
fn report(&mut self) {
#[cfg(feature = "pprof")]
#[cfg(not(windows))]
if let Ok(report) = self.guard.report().build() {
let file = std::fs::File::create("flamegraph.svg")
.expect("flamegraph file err");