From c4f957636811cc779d6b70fa1dbe886f28061654 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 10 May 2016 14:03:10 -0700 Subject: [PATCH] Make --profile-trace-path work without -p --- components/profile/time.rs | 63 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/components/profile/time.rs b/components/profile/time.rs index 4348fc4af76..db9ef2f0ac4 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -135,39 +135,40 @@ pub struct Profiler { impl Profiler { pub fn create(period: Option, file_path: Option) -> ProfilerChan { let (chan, port) = ipc::channel().unwrap(); - match period { - Some(period) => { - let chan = chan.clone(); - spawn_named("Time profiler timer".to_owned(), move || { - loop { - thread::sleep(duration_from_seconds(period)); - if chan.send(ProfilerMsg::Print).is_err() { - break; - } + if let Some(period) = period { + let chan = chan.clone(); + spawn_named("Time profiler timer".to_owned(), move || { + loop { + thread::sleep(duration_from_seconds(period)); + if chan.send(ProfilerMsg::Print).is_err() { + break; } - }); - // Spawn the time profiler. - spawn_named("Time profiler".to_owned(), move || { - let trace = file_path.as_ref() - .map(path::Path::new) - .map(fs::File::create) - .map(|res| TraceDump::new(res.unwrap())); - let mut profiler = Profiler::new(port, trace); - profiler.start(); - }); - } - None => { - // No-op to handle messages when the time profiler is inactive. - spawn_named("Time profiler".to_owned(), move || { - loop { - match port.recv() { - Err(_) | Ok(ProfilerMsg::Exit) => break, - _ => {} - } - } - }); - } + } + }); } + + if period.is_some() || file_path.is_some() { + // Spawn the time profiler. + spawn_named("Time profiler".to_owned(), move || { + let trace = file_path.as_ref() + .map(path::Path::new) + .map(fs::File::create) + .map(|res| TraceDump::new(res.unwrap())); + let mut profiler = Profiler::new(port, trace); + profiler.start(); + }); + } else { + // No-op to handle messages when the time profiler is inactive. + spawn_named("Time profiler".to_owned(), move || { + loop { + match port.recv() { + Err(_) | Ok(ProfilerMsg::Exit) => break, + _ => {} + } + } + }); + } + heartbeats::init(); let profiler_chan = ProfilerChan(chan);