Move trace file opening into TraceDump::new

Moves the responsibility of opening the trace file into TraceDump::new, so that
it doesn't need to be repeated at every call site.
This commit is contained in:
Nick Fitzgerald 2017-03-31 14:37:38 -07:00
parent f003fdf106
commit 9ef436cf8e
2 changed files with 19 additions and 21 deletions

View file

@ -15,10 +15,8 @@ use std::borrow::ToOwned;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::error::Error;
use std::fs;
use std::fs::File;
use std::io::{self, Write};
use std::path;
use std::path::Path;
use std::time::Duration;
use std_time::precise_time_ns;
@ -178,9 +176,7 @@ impl Profiler {
let outputoption = option.clone();
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
let trace = file_path.as_ref()
.map(path::Path::new)
.map(fs::File::create)
.map(|res| TraceDump::new(res.unwrap()));
.and_then(|p| TraceDump::new(p).ok());
let mut profiler = Profiler::new(port, trace, Some(outputoption));
profiler.start();
}).expect("Thread spawning failed");
@ -207,9 +203,7 @@ impl Profiler {
// Spawn the time profiler
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
let trace = file_path.as_ref()
.map(path::Path::new)
.map(fs::File::create)
.map(|res| TraceDump::new(res.unwrap()));
.and_then(|p| TraceDump::new(p).ok());
let mut profiler = Profiler::new(port, trace, None);
profiler.start();
}).expect("Thread spawning failed");