Skip to content

Commit

Permalink
added navigation start for interactive metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
avadacatavra committed Nov 14, 2017
1 parent d287ec8 commit 2ef28d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions components/metrics/lib.rs
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions components/script/dom/document.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()));
Expand Down
4 changes: 4 additions & 0 deletions components/script/script_thread.rs
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2ef28d0

Please sign in to comment.