diff --git a/components/metrics/lib.rs b/components/metrics/lib.rs index 7e7cd9afd1d..bd2d488f100 100644 --- a/components/metrics/lib.rs +++ b/components/metrics/lib.rs @@ -40,6 +40,7 @@ pub trait ProgressiveWebMetric { fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: u64); } +/// TODO make this configurable /// maximum task time is 50ms (in ns) pub const MAX_TASK_NS: u64 = 50000000; /// 10 second window (in ns) @@ -84,6 +85,7 @@ fn set_metric( // Print the metric to console if the print-pwm option was given. if opts::get().print_pwm { + println!("Navigation start: {}", pwm.get_navigation_start().unwrap()); println!("{:?} {:?}", metric_type, time); } @@ -216,6 +218,10 @@ impl InteractiveMetrics { pub fn get_tti(&self) -> Option { self.time_to_interactive.get() } + + pub fn needs_tti(&self) -> bool { + self.get_tti().is_none() + } } impl ProgressiveWebMetric for InteractiveMetrics { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 5214ea4da66..c9130ad5e44 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -97,7 +97,7 @@ use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{JSContext, JSRuntime}; use js::jsapi::JS_GetRuntime; -use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory}; +use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy}; use net_traits::CookieSource::NonHTTP; @@ -1911,6 +1911,10 @@ impl Document { self.dom_interactive.get() } + pub fn set_navigation_start(&self, navigation_start: u64) { + self.interactive_time.borrow_mut().set_navigation_start(navigation_start); + } + pub fn get_interactive_metrics(&self) -> Ref { self.interactive_time.borrow() } @@ -1940,7 +1944,9 @@ impl Document { } pub fn start_tti(&self) { - self.tti_window.borrow_mut().start_window(); + if self.get_interactive_metrics().needs_tti() { + self.tti_window.borrow_mut().start_window(); + } } /// check tti for this document @@ -1948,7 +1954,6 @@ impl Document { /// main thread available and try to set tti pub fn record_tti_if_necessary(&self) { if self.has_recorded_tti_metric() { return; } - if self.tti_window.borrow().needs_check() { self.get_interactive_metrics().maybe_set_tti(self, InteractiveFlag::TimeToInteractive(self.tti_window.borrow().get_start())); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 5cd9261ed2b..d969a46fecc 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1248,6 +1248,9 @@ impl ScriptThread { for (doc_id, doc) in self.documents.borrow().iter() { if let Some(pipeline_id) = pipeline_id { if pipeline_id == doc_id && end - start > MAX_TASK_NS { + if opts::get().print_pwm { + println!("Task took longer than max allowed ({:?}) {:?}", category, end - start); + } doc.start_tti(); } } @@ -2229,6 +2232,7 @@ impl ScriptThread { let parse_input = DOMString::new(); document.set_https_state(metadata.https_state); + document.set_navigation_start(incomplete.navigation_start_precise); if is_html_document == IsHTMLDocument::NonHTMLDocument { ServoParser::parse_xml_document(&document, parse_input, final_url);