diff --git a/components/profile/time.rs b/components/profile/time.rs index be3be16655f..928eca4a263 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -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"); diff --git a/components/profile/trace_dump.rs b/components/profile/trace_dump.rs index 5576f1af94c..b0c8f9d7ef5 100644 --- a/components/profile/trace_dump.rs +++ b/components/profile/trace_dump.rs @@ -7,7 +7,8 @@ use profile_traits::time::{ProfilerCategory, TimerMetadata}; use serde_json; use std::fs; -use std::io::Write; +use std::io::{self, Write}; +use std::path; /// An RAII class for writing the HTML trace dump. #[derive(Debug)] @@ -36,9 +37,12 @@ struct TraceEntry { impl TraceDump { /// Create a new TraceDump and write the prologue of the HTML file out to /// disk. - pub fn new(mut file: fs::File) -> TraceDump { - write_prologue(&mut file); - TraceDump { file: file } + pub fn new
(trace_file_path: P) -> io::Result