Permalink
Browse files

added navigation start for interactive metrics

  • Loading branch information...
avadacatavra committed Nov 14, 2017
1 parent d287ec8 commit 2ef28d05b58b3184773c4bcd2b41601dcb69da8e
Showing with 18 additions and 3 deletions.
  1. +6 −0 components/metrics/lib.rs
  2. +8 −3 components/script/dom/document.rs
  3. +4 −0 components/script/script_thread.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<U: ProgressiveWebMetric>(
// 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<u64> {
self.time_to_interactive.get()
}
pub fn needs_tti(&self) -> bool {
self.get_tti().is_none()
}
}
impl ProgressiveWebMetric for InteractiveMetrics {
@@ -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<InteractiveMetrics> {
self.interactive_time.borrow()
}
@@ -1940,15 +1944,16 @@ 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
/// if it's been 10s since this doc encountered a task over 50ms, then we consider the
/// 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()));
@@ -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);

0 comments on commit 2ef28d0

Please sign in to comment.