mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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:
parent
f003fdf106
commit
9ef436cf8e
2 changed files with 19 additions and 21 deletions
|
@ -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<P>(trace_file_path: P) -> io::Result<TraceDump>
|
||||
where P: AsRef<path::Path>
|
||||
{
|
||||
let mut file = fs::File::create(trace_file_path)?;
|
||||
write_prologue(&mut file)?;
|
||||
Ok(TraceDump { file: file })
|
||||
}
|
||||
|
||||
/// Write one trace to the trace dump file.
|
||||
|
@ -63,18 +67,18 @@ impl Drop for TraceDump {
|
|||
/// Write the epilogue of the trace dump HTML file out to disk on
|
||||
/// destruction.
|
||||
fn drop(&mut self) {
|
||||
write_epilogue(&mut self.file);
|
||||
write_epilogue(&mut self.file).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn write_prologue(file: &mut fs::File) {
|
||||
writeln!(file, "{}", include_str!("./trace-dump-prologue-1.html")).unwrap();
|
||||
writeln!(file, "{}", include_str!("./trace-dump.css")).unwrap();
|
||||
writeln!(file, "{}", include_str!("./trace-dump-prologue-2.html")).unwrap();
|
||||
fn write_prologue(file: &mut fs::File) -> io::Result<()> {
|
||||
writeln!(file, "{}", include_str!("./trace-dump-prologue-1.html"))?;
|
||||
writeln!(file, "{}", include_str!("./trace-dump.css"))?;
|
||||
writeln!(file, "{}", include_str!("./trace-dump-prologue-2.html"))
|
||||
}
|
||||
|
||||
fn write_epilogue(file: &mut fs::File) {
|
||||
writeln!(file, "{}", include_str!("./trace-dump-epilogue-1.html")).unwrap();
|
||||
writeln!(file, "{}", include_str!("./trace-dump.js")).unwrap();
|
||||
writeln!(file, "{}", include_str!("./trace-dump-epilogue-2.html")).unwrap();
|
||||
fn write_epilogue(file: &mut fs::File) -> io::Result<()> {
|
||||
writeln!(file, "{}", include_str!("./trace-dump-epilogue-1.html"))?;
|
||||
writeln!(file, "{}", include_str!("./trace-dump.js"))?;
|
||||
writeln!(file, "{}", include_str!("./trace-dump-epilogue-2.html"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue