mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #16211 - fitzgen:little-trace-dump-stuff, r=jdm
Little HTML profile trace dumps related stuff <!-- Please describe your changes on the following line: --> Updates to fix the labels in the rendered traces, and some other tiny stuff. r? @jdm --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [X] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16211) <!-- Reviewable:end -->
This commit is contained in:
commit
6484109025
3 changed files with 21 additions and 27 deletions
|
@ -15,10 +15,8 @@ use std::borrow::ToOwned;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std_time::precise_time_ns;
|
use std_time::precise_time_ns;
|
||||||
|
@ -178,9 +176,7 @@ impl Profiler {
|
||||||
let outputoption = option.clone();
|
let outputoption = option.clone();
|
||||||
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
|
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
|
||||||
let trace = file_path.as_ref()
|
let trace = file_path.as_ref()
|
||||||
.map(path::Path::new)
|
.and_then(|p| TraceDump::new(p).ok());
|
||||||
.map(fs::File::create)
|
|
||||||
.map(|res| TraceDump::new(res.unwrap()));
|
|
||||||
let mut profiler = Profiler::new(port, trace, Some(outputoption));
|
let mut profiler = Profiler::new(port, trace, Some(outputoption));
|
||||||
profiler.start();
|
profiler.start();
|
||||||
}).expect("Thread spawning failed");
|
}).expect("Thread spawning failed");
|
||||||
|
@ -207,9 +203,7 @@ impl Profiler {
|
||||||
// Spawn the time profiler
|
// Spawn the time profiler
|
||||||
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
|
thread::Builder::new().name("Time profiler".to_owned()).spawn(move || {
|
||||||
let trace = file_path.as_ref()
|
let trace = file_path.as_ref()
|
||||||
.map(path::Path::new)
|
.and_then(|p| TraceDump::new(p).ok());
|
||||||
.map(fs::File::create)
|
|
||||||
.map(|res| TraceDump::new(res.unwrap()));
|
|
||||||
let mut profiler = Profiler::new(port, trace, None);
|
let mut profiler = Profiler::new(port, trace, None);
|
||||||
profiler.start();
|
profiler.start();
|
||||||
}).expect("Thread spawning failed");
|
}).expect("Thread spawning failed");
|
||||||
|
|
|
@ -244,11 +244,6 @@ Make sure to upstream changes, or they will get lost!
|
||||||
return increment;
|
return increment;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the category name for the given trace.
|
|
||||||
const traceCategory = exports.traceCategory = trace => {
|
|
||||||
return Object.keys(trace.category)[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
/*** Window Specific Code ***************************************************/
|
/*** Window Specific Code ***************************************************/
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
|
@ -528,7 +523,7 @@ Make sure to upstream changes, or they will get lost!
|
||||||
inner.style.width = state.nsToSelectionPx(trace.endTime - trace.startTime) + "px";
|
inner.style.width = state.nsToSelectionPx(trace.endTime - trace.startTime) + "px";
|
||||||
inner.style.marginLeft = state.nsToSelectionPx(trace.startTime - state.startSelection) + "px";
|
inner.style.marginLeft = state.nsToSelectionPx(trace.startTime - state.startSelection) + "px";
|
||||||
|
|
||||||
let category = traceCategory(trace);
|
let category = trace.category;
|
||||||
inner.textContent = category;
|
inner.textContent = category;
|
||||||
inner.style.backgroundColor = state.getColorForCategory(category);
|
inner.style.backgroundColor = state.getColorForCategory(category);
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
use profile_traits::time::{ProfilerCategory, TimerMetadata};
|
use profile_traits::time::{ProfilerCategory, TimerMetadata};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::{self, Write};
|
||||||
|
use std::path;
|
||||||
|
|
||||||
/// An RAII class for writing the HTML trace dump.
|
/// An RAII class for writing the HTML trace dump.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct TraceDump {
|
pub struct TraceDump {
|
||||||
file: fs::File,
|
file: fs::File,
|
||||||
}
|
}
|
||||||
|
@ -35,9 +37,12 @@ struct TraceEntry {
|
||||||
impl TraceDump {
|
impl TraceDump {
|
||||||
/// Create a new TraceDump and write the prologue of the HTML file out to
|
/// Create a new TraceDump and write the prologue of the HTML file out to
|
||||||
/// disk.
|
/// disk.
|
||||||
pub fn new(mut file: fs::File) -> TraceDump {
|
pub fn new<P>(trace_file_path: P) -> io::Result<TraceDump>
|
||||||
write_prologue(&mut file);
|
where P: AsRef<path::Path>
|
||||||
TraceDump { file: file }
|
{
|
||||||
|
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.
|
/// Write one trace to the trace dump file.
|
||||||
|
@ -62,18 +67,18 @@ impl Drop for TraceDump {
|
||||||
/// Write the epilogue of the trace dump HTML file out to disk on
|
/// Write the epilogue of the trace dump HTML file out to disk on
|
||||||
/// destruction.
|
/// destruction.
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
write_epilogue(&mut self.file);
|
write_epilogue(&mut self.file).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_prologue(file: &mut fs::File) {
|
fn write_prologue(file: &mut fs::File) -> io::Result<()> {
|
||||||
writeln!(file, "{}", include_str!("./trace-dump-prologue-1.html")).unwrap();
|
writeln!(file, "{}", include_str!("./trace-dump-prologue-1.html"))?;
|
||||||
writeln!(file, "{}", include_str!("./trace-dump.css")).unwrap();
|
writeln!(file, "{}", include_str!("./trace-dump.css"))?;
|
||||||
writeln!(file, "{}", include_str!("./trace-dump-prologue-2.html")).unwrap();
|
writeln!(file, "{}", include_str!("./trace-dump-prologue-2.html"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_epilogue(file: &mut fs::File) {
|
fn write_epilogue(file: &mut fs::File) -> io::Result<()> {
|
||||||
writeln!(file, "{}", include_str!("./trace-dump-epilogue-1.html")).unwrap();
|
writeln!(file, "{}", include_str!("./trace-dump-epilogue-1.html"))?;
|
||||||
writeln!(file, "{}", include_str!("./trace-dump.js")).unwrap();
|
writeln!(file, "{}", include_str!("./trace-dump.js"))?;
|
||||||
writeln!(file, "{}", include_str!("./trace-dump-epilogue-2.html")).unwrap();
|
writeln!(file, "{}", include_str!("./trace-dump-epilogue-2.html"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue