Files
tubestation/servo/components/script/dom/performancetiming.rs
Alan Jeffrey 34492ce772 servo: Merge #19569 - Add a topLevelDomComplete metric (from asajeffrey:script-perf-measure-topLevelDomComplete); r=jdm
<!-- Please describe your changes on the following line: -->

Measure DOM completion without iframes. This is in support of measuring when the main document is loaded, ignoring secondary content, e.g. ads.

---
<!-- 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 #19561
- [X] There are tests for these changes

<!-- 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. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: d832e1b8f843612b4cb124d8c4eb9dce94e92d50
2017-12-14 17:02:44 -06:00

103 lines
3.5 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::PerformanceTimingBinding;
use dom::bindings::codegen::Bindings::PerformanceTimingBinding::PerformanceTimingMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot};
use dom::document::Document;
use dom::window::Window;
use dom_struct::dom_struct;
#[dom_struct]
pub struct PerformanceTiming {
reflector_: Reflector,
navigation_start: u64,
navigation_start_precise: u64,
document: Dom<Document>,
}
impl PerformanceTiming {
fn new_inherited(nav_start: u64,
nav_start_precise: u64,
document: &Document)
-> PerformanceTiming {
PerformanceTiming {
reflector_: Reflector::new(),
navigation_start: nav_start,
navigation_start_precise: nav_start_precise,
document: Dom::from_ref(document),
}
}
#[allow(unrooted_must_root)]
pub fn new(window: &Window,
navigation_start: u64,
navigation_start_precise: u64)
-> DomRoot<PerformanceTiming> {
let timing = PerformanceTiming::new_inherited(navigation_start,
navigation_start_precise,
&window.Document());
reflect_dom_object(Box::new(timing),
window,
PerformanceTimingBinding::Wrap)
}
}
impl PerformanceTimingMethods for PerformanceTiming {
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-navigationStart
fn NavigationStart(&self) -> u64 {
self.navigation_start
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domLoading
fn DomLoading(&self) -> u64 {
self.document.get_dom_loading()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domInteractive
fn DomInteractive(&self) -> u64 {
self.document.get_dom_interactive()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domContentLoadedEventStart
fn DomContentLoadedEventStart(&self) -> u64 {
self.document.get_dom_content_loaded_event_start()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domContentLoadedEventEnd
fn DomContentLoadedEventEnd(&self) -> u64 {
self.document.get_dom_content_loaded_event_end()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-domComplete
fn DomComplete(&self) -> u64 {
self.document.get_dom_complete()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-loadEventStart
fn LoadEventStart(&self) -> u64 {
self.document.get_load_event_start()
}
// https://w3c.github.io/navigation-timing/#widl-PerformanceTiming-loadEventEnd
fn LoadEventEnd(&self) -> u64 {
self.document.get_load_event_end()
}
// check-tidy: no specs after this line
// Servo-only timing for when top-level content (not iframes) is complete
fn TopLevelDomComplete(&self) -> u64 {
self.document.get_top_level_dom_complete()
}
}
impl PerformanceTiming {
pub fn navigation_start_precise(&self) -> u64 {
self.navigation_start_precise
}
}