Auto merge of #19218 - avadacatavra:nav-start, r=jdm

added navigation start for interactive metrics

<!-- Please describe your changes on the following line: -->
 follow up from  #18670, fixing #19099

---
<!-- 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
- [X] These changes fix #19099 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/19218)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-14 09:53:30 -06:00 committed by GitHub
commit 7d13e5b83c
3 changed files with 18 additions and 3 deletions

View file

@ -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 {

View file

@ -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,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()));

View file

@ -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);