aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/trace.rs7
-rw-r--r--components/script/dom/dedicatedworkerglobalscope.rs9
-rw-r--r--components/script/dom/document.rs52
-rw-r--r--components/script/dom/performancepainttiming.rs12
-rw-r--r--components/script/dom/vrdisplay.rs3
-rw-r--r--components/script/dom/websocket.rs3
-rw-r--r--components/script/dom/window.rs14
-rw-r--r--components/script/dom/workerglobalscope.rs13
-rw-r--r--components/script/dom/worklet.rs2
-rw-r--r--components/script/dom/xmlhttprequest.rs2
10 files changed, 96 insertions, 21 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 5c7723f17de..6f5dce2ab14 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -61,6 +61,7 @@ use js::glue::{CallObjectTracer, CallValueTracer};
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
use js::jsval::JSVal;
use js::rust::Runtime;
+use metrics::{InteractiveMetrics, InteractiveWindow};
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, TopLevelBrowsingContextId};
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads};
use net_traits::filemanager_thread::RelativePos;
@@ -283,7 +284,7 @@ unsafe impl<T: JSTraceable, U: JSTraceable> JSTraceable for Result<T, U> {
unsafe impl<K, V, S> JSTraceable for HashMap<K, V, S>
where K: Hash + Eq + JSTraceable,
V: JSTraceable,
- S: BuildHasher
+ S: BuildHasher,
{
#[inline]
unsafe fn trace(&self, trc: *mut JSTracer) {
@@ -296,7 +297,7 @@ unsafe impl<K, V, S> JSTraceable for HashMap<K, V, S>
unsafe impl<T, S> JSTraceable for HashSet<T, S>
where T: Hash + Eq + JSTraceable,
- S: BuildHasher
+ S: BuildHasher,
{
#[inline]
unsafe fn trace(&self, trc: *mut JSTracer) {
@@ -413,6 +414,8 @@ unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
unsafe_no_jsmanaged_fields!(MediaList);
unsafe_no_jsmanaged_fields!(WebVRGamepadHand);
unsafe_no_jsmanaged_fields!(ScriptToConstellationChan);
+unsafe_no_jsmanaged_fields!(InteractiveMetrics);
+unsafe_no_jsmanaged_fields!(InteractiveWindow);
unsafe impl<'a> JSTraceable for &'a str {
#[inline]
diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs
index 6c0f6cef867..058532e179e 100644
--- a/components/script/dom/dedicatedworkerglobalscope.rs
+++ b/components/script/dom/dedicatedworkerglobalscope.rs
@@ -195,7 +195,8 @@ impl DedicatedWorkerGlobalScope {
println!("error loading script {}", serialized_worker_url);
parent_sender.send(CommonScriptMsg::Task(
WorkerEvent,
- Box::new(SimpleWorkerErrorHandler::new(worker))
+ Box::new(SimpleWorkerErrorHandler::new(worker)),
+ pipeline_id
)).unwrap();
return;
}
@@ -357,6 +358,7 @@ impl DedicatedWorkerGlobalScope {
#[allow(unsafe_code)]
pub fn forward_error_to_worker_object(&self, error_info: ErrorInfo) {
let worker = self.worker.borrow().as_ref().unwrap().clone();
+ let pipeline_id = self.upcast::<GlobalScope>().pipeline_id();
let task = Box::new(task!(forward_error_to_worker_object: move || {
let worker = worker.root();
let global = worker.global();
@@ -382,7 +384,7 @@ impl DedicatedWorkerGlobalScope {
}
}));
// TODO: Should use the DOM manipulation task source.
- self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task)).unwrap();
+ self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task, Some(pipeline_id))).unwrap();
}
}
@@ -403,10 +405,11 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
unsafe fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
let data = StructuredCloneData::write(cx, message)?;
let worker = self.worker.borrow().as_ref().unwrap().clone();
+ let pipeline_id = self.upcast::<GlobalScope>().pipeline_id();
let task = Box::new(task!(post_worker_message: move || {
Worker::handle_message(worker, data);
}));
- self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task)).unwrap();
+ self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task, Some(pipeline_id))).unwrap();
Ok(())
}
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 95408843f07..9ed97c4be6d 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -99,6 +99,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 msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId};
use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy};
@@ -108,6 +109,7 @@ use net_traits::pub_domains::is_pub_domain;
use net_traits::request::RequestInit;
use net_traits::response::HttpsState;
use num_traits::ToPrimitive;
+use profile_traits::time::{TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType};
use script_layout_interface::message::{Msg, NodesFromPointQueryType, ReflowGoal};
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, ScriptThread};
@@ -360,6 +362,8 @@ pub struct Document {
/// is inserted or removed from the document.
/// See https://html.spec.whatwg.org/multipage/#form-owner
form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
+ interactive_time: DomRefCell<InteractiveMetrics>,
+ tti_window: DomRefCell<InteractiveWindow>,
}
#[derive(JSTraceable, MallocSizeOf)]
@@ -1834,6 +1838,9 @@ impl Document {
window.reflow(ReflowGoal::Full, ReflowReason::DOMContentLoaded);
update_with_current_time_ms(&self.dom_content_loaded_event_end);
+ // html parsing has finished - set dom content loaded
+ self.interactive_time.borrow().maybe_set_tti(self, InteractiveFlag::DOMContentLoaded);
+
// Step 4.2.
// TODO: client message queue.
}
@@ -1916,6 +1923,14 @@ impl Document {
self.dom_interactive.get()
}
+ pub fn get_interactive_metrics(&self) -> Ref<InteractiveMetrics> {
+ self.interactive_time.borrow()
+ }
+
+ pub fn has_recorded_tti_metric(&self) -> bool {
+ self.get_interactive_metrics().get_tti().is_some()
+ }
+
pub fn get_dom_content_loaded_event_start(&self) -> u64 {
self.dom_content_loaded_event_start.get()
}
@@ -1936,6 +1951,22 @@ impl Document {
self.load_event_end.get()
}
+ pub fn start_tti(&self) {
+ 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() as f64));
+ }
+ }
+
// https://html.spec.whatwg.org/multipage/#fire-a-focus-event
fn fire_focus_event(&self, focus_event_type: FocusEventType, node: &Node, related_target: Option<&EventTarget>) {
let (event_name, does_bubble) = match focus_event_type {
@@ -2145,6 +2176,8 @@ impl Document {
(DocumentReadyState::Complete, true)
};
+ let interactive_time = InteractiveMetrics::new(window.time_profiler_chan().clone());
+
Document {
node: Node::new_document_node(),
window: Dom::from_ref(window),
@@ -2236,6 +2269,8 @@ impl Document {
dom_count: Cell::new(1),
fullscreen_element: MutNullableDom::new(None),
form_id_listener_map: Default::default(),
+ interactive_time: DomRefCell::new(interactive_time),
+ tti_window: DomRefCell::new(InteractiveWindow::new()),
}
}
@@ -2579,11 +2614,13 @@ impl Document {
self.send_to_constellation(event);
}
+ let pipeline_id = self.window().pipeline_id();
+
// Step 7
let trusted_pending = Trusted::new(pending);
let trusted_promise = TrustedPromise::new(promise.clone());
let handler = ElementPerformFullscreenEnter::new(trusted_pending, trusted_promise, error);
- let script_msg = CommonScriptMsg::Task(ScriptThreadEventCategory::EnterFullscreen, handler);
+ let script_msg = CommonScriptMsg::Task(ScriptThreadEventCategory::EnterFullscreen, handler, pipeline_id);
let msg = MainThreadScriptMsg::Common(script_msg);
window.main_thread_script_chan().send(msg).unwrap();
@@ -2615,7 +2652,8 @@ impl Document {
let trusted_element = Trusted::new(element.r());
let trusted_promise = TrustedPromise::new(promise.clone());
let handler = ElementPerformFullscreenExit::new(trusted_element, trusted_promise);
- let script_msg = CommonScriptMsg::Task(ScriptThreadEventCategory::ExitFullscreen, handler);
+ let pipeline_id = Some(global.pipeline_id());
+ let script_msg = CommonScriptMsg::Task(ScriptThreadEventCategory::ExitFullscreen, handler, pipeline_id);
let msg = MainThreadScriptMsg::Common(script_msg);
window.main_thread_script_chan().send(msg).unwrap();
@@ -2673,6 +2711,16 @@ impl Element {
}
}
+impl ProfilerMetadataFactory for Document {
+ fn new_metadata(&self) -> Option<TimerMetadata> {
+ Some(TimerMetadata {
+ url: String::from(self.url().as_str()),
+ iframe: TimerMetadataFrameType::RootWindow,
+ incremental: TimerMetadataReflowType::Incremental,
+ })
+ }
+}
+
impl DocumentMethods for Document {
// https://drafts.csswg.org/cssom/#dom-document-stylesheets
fn StyleSheets(&self) -> DomRoot<StyleSheetList> {
diff --git a/components/script/dom/performancepainttiming.rs b/components/script/dom/performancepainttiming.rs
index 4c25e785208..f5fc8300587 100644
--- a/components/script/dom/performancepainttiming.rs
+++ b/components/script/dom/performancepainttiming.rs
@@ -9,7 +9,7 @@ use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use dom::performanceentry::PerformanceEntry;
use dom_struct::dom_struct;
-use script_traits::PaintMetricType;
+use script_traits::ProgressiveWebMetricType;
#[dom_struct]
pub struct PerformancePaintTiming {
@@ -17,11 +17,11 @@ pub struct PerformancePaintTiming {
}
impl PerformancePaintTiming {
- fn new_inherited(metric_type: PaintMetricType, start_time: f64)
- -> PerformancePaintTiming {
+ fn new_inherited(metric_type: ProgressiveWebMetricType, start_time: f64) -> PerformancePaintTiming {
let name = match metric_type {
- PaintMetricType::FirstPaint => DOMString::from("first-paint"),
- PaintMetricType::FirstContentfulPaint => DOMString::from("first-contentful-paint"),
+ ProgressiveWebMetricType::FirstPaint => DOMString::from("first-paint"),
+ ProgressiveWebMetricType::FirstContentfulPaint => DOMString::from("first-contentful-paint"),
+ _ => DOMString::from(""),
};
PerformancePaintTiming {
entry: PerformanceEntry::new_inherited(name,
@@ -33,7 +33,7 @@ impl PerformancePaintTiming {
#[allow(unrooted_must_root)]
pub fn new(global: &GlobalScope,
- metric_type: PaintMetricType,
+ metric_type: ProgressiveWebMetricType,
start_time: f64) -> DomRoot<PerformancePaintTiming> {
let entry = PerformancePaintTiming::new_inherited(metric_type, start_time);
reflect_dom_object(Box::new(entry), global, PerformancePaintTimingBinding::Wrap)
diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs
index d63e0f514e0..e931b4b7796 100644
--- a/components/script/dom/vrdisplay.rs
+++ b/components/script/dom/vrdisplay.rs
@@ -494,6 +494,7 @@ impl VRDisplay {
let address = Trusted::new(&*self);
let near_init = self.depth_near.get();
let far_init = self.depth_far.get();
+ let pipeline_id = self.global().pipeline_id();
// The render loop at native headset frame rate is implemented using a dedicated thread.
// Every loop iteration syncs pose data with the HMD, submits the pixels to the display and waits for Vsync.
@@ -515,7 +516,7 @@ impl VRDisplay {
let task = Box::new(task!(handle_vrdisplay_raf: move || {
this.root().handle_raf(&sender);
}));
- js_sender.send(CommonScriptMsg::Task(WebVREvent, task)).unwrap();
+ js_sender.send(CommonScriptMsg::Task(WebVREvent, task, Some(pipeline_id))).unwrap();
// Run Sync Poses in parallell on Render thread
let msg = WebVRCommand::SyncPoses(display_id, near, far, sync_sender.clone());
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs
index d8425d1d5b8..1048f26a85e 100644
--- a/components/script/dom/websocket.rs
+++ b/components/script/dom/websocket.rs
@@ -262,9 +262,10 @@ impl WebSocket {
address: address,
});
+ let pipeline_id = self.global().pipeline_id();
self.global()
.script_chan()
- .send(CommonScriptMsg::Task(WebSocketEvent, task))
+ .send(CommonScriptMsg::Task(WebSocketEvent, task, Some(pipeline_id)))
.unwrap();
}
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 1df5d6490c8..384c46a04fb 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -304,6 +304,11 @@ impl Window {
}
}
+ /// Get a sender to the time profiler thread.
+ pub fn time_profiler_chan(&self) -> &TimeProfilerChan {
+ self.globalscope.time_profiler_chan()
+ }
+
pub fn origin(&self) -> &MutableOrigin {
self.globalscope.origin()
}
@@ -1040,6 +1045,10 @@ impl Window {
}
}
+ pub fn get_navigation_start(&self) -> f64 {
+ self.navigation_start_precise.get()
+ }
+
/// Cancels all the tasks associated with that window.
///
/// This sets the current `ignore_further_async_events` sentinel value to
@@ -1854,6 +1863,10 @@ impl Window {
WindowBinding::Wrap(runtime.cx(), win)
}
}
+
+ pub fn pipeline_id(&self) -> Option<PipelineId> {
+ Some(self.upcast::<GlobalScope>().pipeline_id())
+ }
}
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
@@ -1962,6 +1975,7 @@ impl Window {
let _ = self.script_chan.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::DomEvent,
Box::new(self.task_canceller().wrap_task(task)),
+ self.pipeline_id()
));
}
}
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 0dfc2a83196..039cbd235dd 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -29,6 +29,7 @@ use ipc_channel::ipc::IpcSender;
use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime};
use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
+use msg::constellation_msg::PipelineId;
use net_traits::{IpcSend, load_whole_resource};
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, get_reports, Runtime};
@@ -165,6 +166,10 @@ impl WorkerGlobalScope {
cancelled: self.closing.clone(),
}
}
+
+ pub fn pipeline_id(&self) -> PipelineId {
+ self.globalscope.pipeline_id()
+ }
}
impl WorkerGlobalScopeMethods for WorkerGlobalScope {
@@ -363,15 +368,15 @@ impl WorkerGlobalScope {
}
pub fn file_reading_task_source(&self) -> FileReadingTaskSource {
- FileReadingTaskSource(self.script_chan())
+ FileReadingTaskSource(self.script_chan(), self.pipeline_id())
}
pub fn networking_task_source(&self) -> NetworkingTaskSource {
- NetworkingTaskSource(self.script_chan())
+ NetworkingTaskSource(self.script_chan(), self.pipeline_id())
}
pub fn performance_timeline_task_source(&self) -> PerformanceTimelineTaskSource {
- PerformanceTimelineTaskSource(self.script_chan())
+ PerformanceTimelineTaskSource(self.script_chan(), self.pipeline_id())
}
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
@@ -385,7 +390,7 @@ impl WorkerGlobalScope {
pub fn process_event(&self, msg: CommonScriptMsg) {
match msg {
- CommonScriptMsg::Task(_, task) => {
+ CommonScriptMsg::Task(_, task, _) => {
task.run_box()
},
CommonScriptMsg::CollectReports(reports_chan) => {
diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs
index f7d50ae4df3..619eccb07a0 100644
--- a/components/script/dom/worklet.rs
+++ b/components/script/dom/worklet.rs
@@ -644,7 +644,7 @@ impl WorkletThread {
where
T: TaskBox + 'static,
{
- let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, Box::new(task));
+ let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, Box::new(task), None);
let msg = MainThreadScriptMsg::Common(msg);
self.global_init.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
}
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index 7b05b080d71..580189f5768 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -1286,7 +1286,7 @@ impl XMLHttpRequest {
let (task_source, script_port) = if self.sync.get() {
let (tx, rx) = global.new_script_pair();
- (NetworkingTaskSource(tx), Some(rx))
+ (NetworkingTaskSource(tx, global.pipeline_id()), Some(rx))
} else {
(global.networking_task_source(), None)
};