diff --git a/components/profile/Cargo.toml b/components/profile/Cargo.toml index 1088725a8b5..ca7a2dc25cb 100644 --- a/components/profile/Cargo.toml +++ b/components/profile/Cargo.toml @@ -16,6 +16,9 @@ ipc-channel = {git = "https://github.com/servo/ipc-channel"} hbs-pow = "0.2" log = "0.3.5" libc = "0.2" +serde = "0.7" +serde_json = "0.7" +serde_macros = "0.7" time = "0.1.12" [target.'cfg(target_os = "macos")'.dependencies] diff --git a/components/profile/lib.rs b/components/profile/lib.rs index 5885d85588d..da2d03c0a8d 100644 --- a/components/profile/lib.rs +++ b/components/profile/lib.rs @@ -7,6 +7,8 @@ #![feature(iter_arith)] #![feature(plugin)] #![plugin(plugins)] +#![feature(custom_derive)] +#![plugin(serde_macros)] #![deny(unsafe_code)] @@ -22,6 +24,8 @@ extern crate log; extern crate profile_traits; #[cfg(target_os = "linux")] extern crate regex; +extern crate serde; +extern crate serde_json; #[cfg(target_os = "macos")] extern crate task_info; extern crate time as std_time; @@ -32,3 +36,4 @@ mod heartbeats; #[allow(unsafe_code)] pub mod mem; pub mod time; +pub mod trace_dump; diff --git a/components/profile/time.rs b/components/profile/time.rs index 6a1152a2d72..fa02cf51f3d 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -12,10 +12,13 @@ use profile_traits::time::{TimerMetadataReflowType, TimerMetadataFrameType}; use std::borrow::ToOwned; use std::cmp::Ordering; use std::collections::BTreeMap; +use std::fs; use std::io::{self, Write}; +use std::path; use std::time::Duration; use std::{thread, f64}; use std_time::precise_time_ns; +use trace_dump::TraceDump; use util::thread::spawn_named; use util::time::duration_from_seconds; @@ -125,10 +128,11 @@ pub struct Profiler { pub port: IpcReceiver, buckets: ProfilerBuckets, pub last_msg: Option, + trace: Option, } impl Profiler { - pub fn create(period: Option) -> ProfilerChan { + pub fn create(period: Option, file_path: Option) -> ProfilerChan { let (chan, port) = ipc::channel().unwrap(); match period { Some(period) => { @@ -143,7 +147,11 @@ impl Profiler { }); // Spawn the time profiler. spawn_named("Time profiler".to_owned(), move || { - let mut profiler = Profiler::new(port); + 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(); }); } @@ -206,11 +214,12 @@ impl Profiler { profiler_chan } - pub fn new(port: IpcReceiver) -> Profiler { + pub fn new(port: IpcReceiver, trace: Option) -> Profiler { Profiler { port: port, buckets: BTreeMap::new(), last_msg: None, + trace: trace, } } @@ -235,6 +244,9 @@ impl Profiler { match msg.clone() { ProfilerMsg::Time(k, t, e) => { heartbeats::maybe_heartbeat(&k.0, t.0, t.1, e.0, e.1); + if let Some(ref mut trace) = self.trace { + trace.write_one(&k, t, e); + } let ms = (t.1 - t.0) as f64 / 1000000f64; self.find_or_insert(k, ms); }, diff --git a/components/profile/trace-dump-epilogue-1.html b/components/profile/trace-dump-epilogue-1.html new file mode 100644 index 00000000000..401f8301ee1 --- /dev/null +++ b/components/profile/trace-dump-epilogue-1.html @@ -0,0 +1,3 @@ + ]; + + + + diff --git a/components/profile/trace-dump-prologue-1.html b/components/profile/trace-dump-prologue-1.html new file mode 100644 index 00000000000..7638b8d678a --- /dev/null +++ b/components/profile/trace-dump-prologue-1.html @@ -0,0 +1,5 @@ + + + + + + + +