added pipelines to all task sources

changed task sources to accept pipeline ids
This commit is contained in:
ddh 2017-10-24 02:45:55 +01:00
parent 2ffbe53989
commit 52b63def44
20 changed files with 194 additions and 230 deletions

2
Cargo.lock generated
View file

@ -1819,7 +1819,6 @@ dependencies = [
"gfx 0.0.1", "gfx 0.0.1",
"gfx_traits 0.0.1", "gfx_traits 0.0.1",
"ipc-channel 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1", "malloc_size_of 0.0.1",
"malloc_size_of_derive 0.0.1", "malloc_size_of_derive 0.0.1",
@ -2420,7 +2419,6 @@ version = "0.0.1"
dependencies = [ dependencies = [
"energy-monitor 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "energy-monitor 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"energymon 0.3.0 (git+https://github.com/energymon/energymon-rust.git)", "energymon 0.3.0 (git+https://github.com/energymon/energymon-rust.git)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -17,7 +17,6 @@ log = "0.3.5"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" } malloc_size_of_derive = { path = "../malloc_size_of_derive" }
msg = {path = "../msg"} msg = {path = "../msg"}
lazy_static = "0.2"
profile_traits = {path = "../profile_traits"} profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
servo_config = {path = "../config"} servo_config = {path = "../config"}

View file

@ -1,14 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public /* 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(custom_attribute)]
extern crate gfx; extern crate gfx;
extern crate gfx_traits; extern crate gfx_traits;
extern crate ipc_channel; extern crate ipc_channel;
#[macro_use] #[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log; extern crate log;
extern crate malloc_size_of; extern crate malloc_size_of;
#[macro_use] #[macro_use]
@ -25,12 +22,11 @@ use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId; use msg::constellation_msg::PipelineId;
use profile_traits::time::{ProfilerChan, ProfilerCategory, send_profile_data}; use profile_traits::time::{ProfilerChan, ProfilerCategory, send_profile_data};
use profile_traits::time::TimerMetadata; use profile_traits::time::TimerMetadata;
use script_traits::{ConstellationControlMsg, LayoutMsg, PWMType}; use script_traits::{ConstellationControlMsg, LayoutMsg, ProgressiveWebMetricType};
use servo_config::opts; use servo_config::opts;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use std::time::{Instant, Duration};
use time::precise_time_ns; use time::precise_time_ns;
pub trait ProfilerMetadataFactory { pub trait ProfilerMetadataFactory {
@ -41,25 +37,23 @@ pub trait ProgressiveWebMetric {
fn get_navigation_start(&self) -> Option<f64>; fn get_navigation_start(&self) -> Option<f64>;
fn set_navigation_start(&mut self, time: f64); fn set_navigation_start(&mut self, time: f64);
fn get_time_profiler_chan(&self) -> &ProfilerChan; fn get_time_profiler_chan(&self) -> &ProfilerChan;
fn send_queued_constellation_msg(&self, name: PWMType, time: f64); fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: f64);
} }
lazy_static!{ /// maximum task time is 50ms (in ns)
static ref TEN_SECONDS: Duration = Duration::new(10, 0); pub const MAX_TASK_NS: u64 = 50000000;
pub static ref MAX_TASK_TIME: u64 = 50000000; /// 10 second window (in ns)
} const INTERACTIVE_WINDOW_SECONDS_IN_NS: u64 = 10000000000;
// there should be some requirements on self fn set_metric<U: ProgressiveWebMetric>(
// can i have self<U> ?
pub fn set_metric<U: ProgressiveWebMetric>(
pwm: &U, pwm: &U,
metadata: Option<TimerMetadata>, metadata: Option<TimerMetadata>,
metric_type: PWMType, metric_type: ProgressiveWebMetricType,
category: ProfilerCategory, category: ProfilerCategory,
attr: &Cell<Option<f64>>, attr: &Cell<Option<f64>>,
metric_time: Option<f64>, metric_time: Option<f64>)
) { {
let navigation_start = match pwm.get_navigation_start() { let navigation_start = match pwm.get_navigation_start() {
Some(time) => time, Some(time) => time,
None => { None => {
@ -67,7 +61,6 @@ pub fn set_metric<U: ProgressiveWebMetric>(
return; return;
} }
}; };
let now = match metric_time { let now = match metric_time {
Some(time) => time, Some(time) => time,
None => precise_time_ns() as f64, None => precise_time_ns() as f64,
@ -97,11 +90,19 @@ pub fn set_metric<U: ProgressiveWebMetric>(
} }
// https://github.com/GoogleChrome/lighthouse/issues/27 // https://github.com/GoogleChrome/lighthouse/issues/27
// we can look at three different metrics here:
// navigation start -> visually ready (dom content loaded)
// navigation start -> thread ready (main thread available)
// visually ready -> thread ready
#[derive(MallocSizeOf)] #[derive(MallocSizeOf)]
pub struct InteractiveMetrics { pub struct InteractiveMetrics {
navigation_start: Cell<Option<f64>>, /// when we navigated to the page
navigation_start: Option<f64>,
/// indicates if the page is visually ready
dom_content_loaded: Cell<Option<f64>>, dom_content_loaded: Cell<Option<f64>>,
/// main thread is available -- there's been a 10s window with no tasks longer than 50ms
main_thread_available: Cell<Option<f64>>, main_thread_available: Cell<Option<f64>>,
// max(main_thread_available, dom_content_loaded)
time_to_interactive: Cell<Option<f64>>, time_to_interactive: Cell<Option<f64>>,
#[ignore_malloc_size_of = "can't measure channels"] #[ignore_malloc_size_of = "can't measure channels"]
time_profiler_chan: ProfilerChan, time_profiler_chan: ProfilerChan,
@ -110,73 +111,44 @@ pub struct InteractiveMetrics {
#[derive(Clone, Copy, Debug, MallocSizeOf)] #[derive(Clone, Copy, Debug, MallocSizeOf)]
pub struct InteractiveWindow { pub struct InteractiveWindow {
start: u64, start: u64,
#[ignore_malloc_size_of = "don't need to measure rn"] //FIXME
instant: Instant,
all_interactive: bool,
} }
//TODO i don't think all interactive is needed anymore
impl InteractiveWindow { impl InteractiveWindow {
pub fn new() -> InteractiveWindow { pub fn new() -> InteractiveWindow {
InteractiveWindow { InteractiveWindow {
start: precise_time_ns(), start: precise_time_ns(),
instant: Instant::now(),
all_interactive: false,
} }
} }
// We need to either start or restart the 10s window // We need to either start or restart the 10s window
// start: we've added a new document // start: we've added a new document
// restart: there was a task > 50s // restart: there was a task > 50ms
// not all documents are interactive // not all documents are interactive
pub fn start_window(&mut self) { pub fn start_window(&mut self) {
self.start = precise_time_ns(); self.start = precise_time_ns();
self.instant = Instant::now();
self.unset_all_interactive();
} }
/// check if 10s has elapsed since start
pub fn needs_check(&self) -> bool { pub fn needs_check(&self) -> bool {
self.instant.elapsed() > *TEN_SECONDS precise_time_ns() - self.start >= INTERACTIVE_WINDOW_SECONDS_IN_NS
}
pub fn check_interactive(&self) -> bool {
self.all_interactive
}
pub fn set_all_interactive(&mut self) {
self.all_interactive = true;
}
pub fn unset_all_interactive(&mut self) {
self.all_interactive = false;
} }
pub fn get_start(&self) -> u64 { pub fn get_start(&self) -> u64 {
self.start self.start
} }
pub fn elapsed_since_start(&self) -> u64 {
self.instant.elapsed().as_secs()
}
// ^^^^^^^^^^^^^ expected u64, found struct `MAX_TASK_TIME`
pub fn max_task_time() -> u64 {
50000000
}
} }
#[derive(Debug)] #[derive(Debug)]
pub enum InteractiveFlag { pub enum InteractiveFlag {
DCL, DOMContentLoaded,
TTI, TimeToInteractive(f64),
} }
impl InteractiveMetrics { impl InteractiveMetrics {
pub fn new(time_profiler_chan: ProfilerChan) -> InteractiveMetrics { pub fn new(time_profiler_chan: ProfilerChan) -> InteractiveMetrics {
InteractiveMetrics { InteractiveMetrics {
navigation_start: Cell::new(None), navigation_start: None,
dom_content_loaded: Cell::new(None), dom_content_loaded: Cell::new(None),
main_thread_available: Cell::new(None), main_thread_available: Cell::new(None),
time_to_interactive: Cell::new(None), time_to_interactive: Cell::new(None),
@ -190,9 +162,9 @@ impl InteractiveMetrics {
} }
} }
pub fn set_main_thread_available(&self, time: Option<f64>) { pub fn set_main_thread_available(&self, time: f64) {
if self.main_thread_available.get().is_none() && time.is_some() { if self.main_thread_available.get().is_none() {
self.main_thread_available.set(time); self.main_thread_available.set(Some(time));
} }
} }
@ -209,7 +181,6 @@ impl InteractiveMetrics {
pub fn maybe_set_tti<T>( pub fn maybe_set_tti<T>(
&self, &self,
profiler_metadata_factory: &T, profiler_metadata_factory: &T,
time: Option<f64>,
metric: InteractiveFlag, metric: InteractiveFlag,
) where ) where
T: ProfilerMetadataFactory, T: ProfilerMetadataFactory,
@ -218,32 +189,28 @@ impl InteractiveMetrics {
return; return;
} }
match metric { match metric {
InteractiveFlag::DCL => self.set_dom_content_loaded(), InteractiveFlag::DOMContentLoaded => self.set_dom_content_loaded(),
InteractiveFlag::TTI => self.set_main_thread_available(time), InteractiveFlag::TimeToInteractive(time) => self.set_main_thread_available(time),
} }
let dcl = self.dom_content_loaded.get(); let dcl = self.dom_content_loaded.get();
let mta = self.main_thread_available.get(); let mta = self.main_thread_available.get();
if dcl.is_some() && mta.is_some() { let (dcl, mta) = match (dcl, mta) {
let metric_time = match dcl.unwrap().partial_cmp(&mta.unwrap()) { (Some(dcl), Some(mta)) => (dcl, mta),
Some(order) => { _ => return,
match order { };
Ordering::Less => mta, let metric_time = match dcl.partial_cmp(&mta) {
_ => dcl, Some(Ordering::Less) => mta,
} Some(_) => dcl,
} None => panic!("no ordering possible. something bad happened"),
None => panic!("no ordering possible. something bad happened"), };
}; set_metric(
set_metric( self,
self, profiler_metadata_factory.new_metadata(),
profiler_metadata_factory.new_metadata(), ProgressiveWebMetricType::TimeToInteractive,
PWMType::TimeToInteractive, ProfilerCategory::TimeToInteractive,
ProfilerCategory::TimeToInteractive, &self.time_to_interactive,
&self.time_to_interactive, Some(metric_time));
metric_time,
);
}
} }
pub fn get_tti(&self) -> Option<f64> { pub fn get_tti(&self) -> Option<f64> {
@ -251,19 +218,16 @@ impl InteractiveMetrics {
} }
} }
// TODO don't impl on ref
impl ProgressiveWebMetric for InteractiveMetrics { impl ProgressiveWebMetric for InteractiveMetrics {
fn get_navigation_start(&self) -> Option<f64> { fn get_navigation_start(&self) -> Option<f64> {
self.navigation_start.get() self.navigation_start
} }
fn set_navigation_start(&mut self, time: f64) { fn set_navigation_start(&mut self, time: f64) {
self.navigation_start.set(Some(time)); self.navigation_start = Some(time);
} }
fn send_queued_constellation_msg(&self, name: PWMType, time: f64) { fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: f64) { }
// TODO
}
fn get_time_profiler_chan(&self) -> &ProfilerChan { fn get_time_profiler_chan(&self) -> &ProfilerChan {
&self.time_profiler_chan &self.time_profiler_chan
@ -272,7 +236,7 @@ impl ProgressiveWebMetric for InteractiveMetrics {
pub struct PaintTimeMetrics { pub struct PaintTimeMetrics {
pending_metrics: RefCell<HashMap<Epoch, (Option<TimerMetadata>, bool)>>, pending_metrics: RefCell<HashMap<Epoch, (Option<TimerMetadata>, bool)>>,
navigation_start: Cell<Option<f64>>, navigation_start: Option<f64>,
first_paint: Cell<Option<f64>>, first_paint: Cell<Option<f64>>,
first_contentful_paint: Cell<Option<f64>>, first_contentful_paint: Cell<Option<f64>>,
pipeline_id: PipelineId, pipeline_id: PipelineId,
@ -286,11 +250,11 @@ impl PaintTimeMetrics {
pipeline_id: PipelineId, pipeline_id: PipelineId,
time_profiler_chan: ProfilerChan, time_profiler_chan: ProfilerChan,
constellation_chan: IpcSender<LayoutMsg>, constellation_chan: IpcSender<LayoutMsg>,
script_chan: IpcSender<ConstellationControlMsg>, script_chan: IpcSender<ConstellationControlMsg>)
) -> PaintTimeMetrics { -> PaintTimeMetrics {
PaintTimeMetrics { PaintTimeMetrics {
pending_metrics: RefCell::new(HashMap::new()), pending_metrics: RefCell::new(HashMap::new()),
navigation_start: Cell::new(None), navigation_start: None,
first_paint: Cell::new(None), first_paint: Cell::new(None),
first_contentful_paint: Cell::new(None), first_contentful_paint: Cell::new(None),
pipeline_id, pipeline_id,
@ -304,16 +268,14 @@ impl PaintTimeMetrics {
where where
T: ProfilerMetadataFactory, T: ProfilerMetadataFactory,
{ {
{ if self.first_paint.get().is_some() {
if self.first_paint.get().is_some() { return;
return;
}
} }
set_metric( set_metric(
self, self,
profiler_metadata_factory.new_metadata(), profiler_metadata_factory.new_metadata(),
PWMType::FirstPaint, ProgressiveWebMetricType::FirstPaint,
ProfilerCategory::TimeToFirstPaint, ProfilerCategory::TimeToFirstPaint,
&self.first_paint, &self.first_paint,
None, None,
@ -324,10 +286,8 @@ impl PaintTimeMetrics {
&self, &self,
profiler_metadata_factory: &T, profiler_metadata_factory: &T,
epoch: Epoch, epoch: Epoch,
display_list: &DisplayList, display_list: &DisplayList)
) where where T: ProfilerMetadataFactory {
T: ProfilerMetadataFactory,
{
if self.first_paint.get().is_some() && self.first_contentful_paint.get().is_some() { if self.first_paint.get().is_some() && self.first_contentful_paint.get().is_some() {
// If we already set all paint metrics, we just bail out. // If we already set all paint metrics, we just bail out.
return; return;
@ -363,9 +323,8 @@ impl PaintTimeMetrics {
} }
pub fn maybe_set_metric(&self, epoch: Epoch, paint_time: f64) { pub fn maybe_set_metric(&self, epoch: Epoch, paint_time: f64) {
if (self.first_paint.get().is_some() && self.first_contentful_paint.get().is_some()) || if self.first_paint.get().is_some() && self.first_contentful_paint.get().is_some() ||
self.get_navigation_start().is_none() self.navigation_start.is_none() {
{
// If we already set all paint metrics or we have not set navigation start yet, // If we already set all paint metrics or we have not set navigation start yet,
// we just bail out. // we just bail out.
return; return;
@ -376,7 +335,7 @@ impl PaintTimeMetrics {
set_metric( set_metric(
self, self,
profiler_metadata.clone(), profiler_metadata.clone(),
PWMType::FirstPaint, ProgressiveWebMetricType::FirstPaint,
ProfilerCategory::TimeToFirstPaint, ProfilerCategory::TimeToFirstPaint,
&self.first_paint, &self.first_paint,
Some(paint_time), Some(paint_time),
@ -386,7 +345,7 @@ impl PaintTimeMetrics {
set_metric( set_metric(
self, self,
profiler_metadata, profiler_metadata,
PWMType::FirstContentfulPaint, ProgressiveWebMetricType::FirstContentfulPaint,
ProfilerCategory::TimeToFirstContentfulPaint, ProfilerCategory::TimeToFirstContentfulPaint,
&self.first_contentful_paint, &self.first_contentful_paint,
Some(paint_time), Some(paint_time),
@ -404,17 +363,16 @@ impl PaintTimeMetrics {
} }
} }
// TODO don't impl on ref
impl ProgressiveWebMetric for PaintTimeMetrics { impl ProgressiveWebMetric for PaintTimeMetrics {
fn get_navigation_start(&self) -> Option<f64> { fn get_navigation_start(&self) -> Option<f64> {
self.navigation_start.get() self.navigation_start
} }
fn set_navigation_start(&mut self, time: f64) { fn set_navigation_start(&mut self, time: f64) {
self.navigation_start.set(Some(time)); self.navigation_start = Some(time);
} }
fn send_queued_constellation_msg(&self, name: PWMType, time: f64) { fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: f64) {
let msg = ConstellationControlMsg::PaintMetric(self.pipeline_id, name, time); let msg = ConstellationControlMsg::PaintMetric(self.pipeline_id, name, time);
if let Err(e) = self.script_chan.send(msg) { if let Err(e) = self.script_chan.send(msg) {
warn!("Sending metric to script thread failed ({}).", e); warn!("Sending metric to script thread failed ({}).", e);

View file

@ -359,7 +359,7 @@ impl DedicatedWorkerGlobalScope {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn forward_error_to_worker_object(&self, error_info: ErrorInfo) { pub fn forward_error_to_worker_object(&self, error_info: ErrorInfo) {
let worker = self.worker.borrow().as_ref().unwrap().clone(); let worker = self.worker.borrow().as_ref().unwrap().clone();
let pipeline_id = worker.clone().root().global().pipeline_id(); let pipeline_id = self.upcast::<GlobalScope>().pipeline_id();
let task = Box::new(task!(forward_error_to_worker_object: move || { let task = Box::new(task!(forward_error_to_worker_object: move || {
let worker = worker.root(); let worker = worker.root();
let global = worker.global(); let global = worker.global();
@ -406,7 +406,7 @@ impl DedicatedWorkerGlobalScopeMethods for DedicatedWorkerGlobalScope {
unsafe fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult { unsafe fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
let data = StructuredCloneData::write(cx, message)?; let data = StructuredCloneData::write(cx, message)?;
let worker = self.worker.borrow().as_ref().unwrap().clone(); let worker = self.worker.borrow().as_ref().unwrap().clone();
let pipeline_id = worker.clone().root().global().pipeline_id(); let pipeline_id = self.upcast::<GlobalScope>().pipeline_id();
let task = Box::new(task!(post_worker_message: move || { let task = Box::new(task!(post_worker_message: move || {
Worker::handle_message(worker, data); Worker::handle_message(worker, data);
})); }));

View file

@ -99,7 +99,7 @@ use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSContext, JSRuntime}; use js::jsapi::{JSContext, JSRuntime};
use js::jsapi::JS_GetRuntime; use js::jsapi::JS_GetRuntime;
use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric}; use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory};
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId};
use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy}; use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy};
@ -1839,7 +1839,7 @@ impl Document {
update_with_current_time_ms(&self.dom_content_loaded_event_end); update_with_current_time_ms(&self.dom_content_loaded_event_end);
// html parsing has finished - set dom content loaded // html parsing has finished - set dom content loaded
self.interactive_time.borrow().maybe_set_tti(self, None, InteractiveFlag::DCL); self.interactive_time.borrow().maybe_set_tti(self, InteractiveFlag::DOMContentLoaded);
// Step 4.2. // Step 4.2.
// TODO: client message queue. // TODO: client message queue.
@ -1927,7 +1927,7 @@ impl Document {
self.interactive_time.borrow() self.interactive_time.borrow()
} }
pub fn is_interactive(&self) -> bool { pub fn has_recorded_tti_metric(&self) -> bool {
self.get_interactive_metrics().get_tti().is_some() self.get_interactive_metrics().get_tti().is_some()
} }
@ -1958,13 +1958,12 @@ impl Document {
/// check tti for this document /// check tti for this document
/// if it's been 10s since this doc encountered a task over 50ms, then we consider the /// 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 /// main thread available and try to set tti
pub fn check_tti(&self) { pub fn record_tti_if_necessary(&self) {
if self.is_interactive() { return; } if self.has_recorded_tti_metric() { return; }
if self.tti_window.borrow().needs_check() { if self.tti_window.borrow().needs_check() {
self.get_interactive_metrics().maybe_set_tti(self, self.get_interactive_metrics().maybe_set_tti(self,
Some(self.tti_window.borrow().get_start() as f64), InteractiveFlag::TimeToInteractive(self.tti_window.borrow().get_start() as f64));
InteractiveFlag::TTI);
} }
} }
@ -2177,8 +2176,7 @@ impl Document {
(DocumentReadyState::Complete, true) (DocumentReadyState::Complete, true)
}; };
let mut interactive_time = InteractiveMetrics::new(window.time_profiler_chan().clone()); let interactive_time = InteractiveMetrics::new(window.time_profiler_chan().clone());
interactive_time.set_navigation_start(window.get_navigation_start());
Document { Document {
node: Node::new_document_node(), node: Node::new_document_node(),

View file

@ -9,7 +9,7 @@ use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom::performanceentry::PerformanceEntry; use dom::performanceentry::PerformanceEntry;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use script_traits::PWMType; use script_traits::ProgressiveWebMetricType;
#[dom_struct] #[dom_struct]
pub struct PerformancePaintTiming { pub struct PerformancePaintTiming {
@ -17,10 +17,10 @@ pub struct PerformancePaintTiming {
} }
impl PerformancePaintTiming { impl PerformancePaintTiming {
fn new_inherited(metric_type: PWMType, start_time: f64) -> PerformancePaintTiming { fn new_inherited(metric_type: ProgressiveWebMetricType, start_time: f64) -> PerformancePaintTiming {
let name = match metric_type { let name = match metric_type {
PWMType::FirstPaint => DOMString::from("first-paint"), ProgressiveWebMetricType::FirstPaint => DOMString::from("first-paint"),
PWMType::FirstContentfulPaint => DOMString::from("first-contentful-paint"), ProgressiveWebMetricType::FirstContentfulPaint => DOMString::from("first-contentful-paint"),
_ => DOMString::from(""), _ => DOMString::from(""),
}; };
PerformancePaintTiming { PerformancePaintTiming {
@ -33,7 +33,7 @@ impl PerformancePaintTiming {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(global: &GlobalScope, pub fn new(global: &GlobalScope,
metric_type: PWMType, metric_type: ProgressiveWebMetricType,
start_time: f64) -> DomRoot<PerformancePaintTiming> { start_time: f64) -> DomRoot<PerformancePaintTiming> {
let entry = PerformancePaintTiming::new_inherited(metric_type, start_time); let entry = PerformancePaintTiming::new_inherited(metric_type, start_time);
reflect_dom_object(Box::new(entry), global, PerformancePaintTimingBinding::Wrap) reflect_dom_object(Box::new(entry), global, PerformancePaintTimingBinding::Wrap)

View file

@ -494,6 +494,7 @@ impl VRDisplay {
let address = Trusted::new(&*self); let address = Trusted::new(&*self);
let near_init = self.depth_near.get(); let near_init = self.depth_near.get();
let far_init = self.depth_far.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. // 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. // Every loop iteration syncs pose data with the HMD, submits the pixels to the display and waits for Vsync.
@ -505,7 +506,6 @@ impl VRDisplay {
let (raf_sender, raf_receiver) = mpsc::channel(); let (raf_sender, raf_receiver) = mpsc::channel();
let mut near = near_init; let mut near = near_init;
let mut far = far_init; let mut far = far_init;
// let pipeline_id = self.global().pipeline_id().clone(); TODO
// Initialize compositor // Initialize compositor
api_sender.send_vr(WebVRCommand::Create(display_id)).unwrap(); api_sender.send_vr(WebVRCommand::Create(display_id)).unwrap();
@ -516,7 +516,7 @@ impl VRDisplay {
let task = Box::new(task!(handle_vrdisplay_raf: move || { let task = Box::new(task!(handle_vrdisplay_raf: move || {
this.root().handle_raf(&sender); this.root().handle_raf(&sender);
})); }));
js_sender.send(CommonScriptMsg::Task(WebVREvent, task, None)).unwrap(); js_sender.send(CommonScriptMsg::Task(WebVREvent, task, Some(pipeline_id))).unwrap();
// Run Sync Poses in parallell on Render thread // Run Sync Poses in parallell on Render thread
let msg = WebVRCommand::SyncPoses(display_id, near, far, sync_sender.clone()); let msg = WebVRCommand::SyncPoses(display_id, near, far, sync_sender.clone());

View file

@ -29,6 +29,7 @@ use ipc_channel::ipc::IpcSender;
use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime}; use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind; use js::panic::maybe_resume_unwind;
use msg::constellation_msg::PipelineId;
use net_traits::{IpcSend, load_whole_resource}; use net_traits::{IpcSend, load_whole_resource};
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit, Type as RequestType}; use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit, Type as RequestType};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, get_reports, Runtime}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, get_reports, Runtime};
@ -165,6 +166,10 @@ impl WorkerGlobalScope {
cancelled: self.closing.clone(), cancelled: self.closing.clone(),
} }
} }
pub fn pipeline_id(&self) -> PipelineId {
self.globalscope.pipeline_id()
}
} }
impl WorkerGlobalScopeMethods for WorkerGlobalScope { impl WorkerGlobalScopeMethods for WorkerGlobalScope {
@ -364,15 +369,15 @@ impl WorkerGlobalScope {
} }
pub fn file_reading_task_source(&self) -> FileReadingTaskSource { 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 { 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 { 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>) { pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {

View file

@ -1285,7 +1285,7 @@ impl XMLHttpRequest {
let (task_source, script_port) = if self.sync.get() { let (task_source, script_port) = if self.sync.get() {
let (tx, rx) = global.new_script_pair(); let (tx, rx) = global.new_script_pair();
(NetworkingTaskSource(tx), Some(rx)) (NetworkingTaskSource(tx, global.pipeline_id()), Some(rx))
} else { } else {
(global.networking_task_source(), None) (global.networking_task_source(), None)
}; };

View file

@ -16,7 +16,6 @@
//! takes over the response body. Once parsing is complete, the document lifecycle for loading //! takes over the response body. Once parsing is complete, the document lifecycle for loading
//! a page runs its course and the script thread returns to processing events in the main event //! a page runs its course and the script thread returns to processing events in the main event
//! loop. //! loop.
#![feature(box_syntax)]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLPipeline; use canvas_traits::webgl::WebGLPipeline;
@ -75,7 +74,7 @@ use js::jsapi::{JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use malloc_size_of::MallocSizeOfOps; use malloc_size_of::MallocSizeOfOps;
use mem::malloc_size_of_including_self; use mem::malloc_size_of_including_self;
use metrics::{InteractiveWindow, PaintTimeMetrics}; use metrics::{MAX_TASK_NS, PaintTimeMetrics};
use microtask::{MicrotaskQueue, Microtask}; use microtask::{MicrotaskQueue, Microtask};
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, PipelineNamespace, TopLevelBrowsingContextId}; use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, PipelineNamespace, TopLevelBrowsingContextId};
use net_traits::{FetchMetadata, FetchResponseListener, FetchResponseMsg}; use net_traits::{FetchMetadata, FetchResponseListener, FetchResponseMsg};
@ -92,7 +91,7 @@ use script_traits::{CompositorEvent, ConstellationControlMsg};
use script_traits::{DiscardBrowsingContext, DocumentActivity, EventResult}; use script_traits::{DiscardBrowsingContext, DocumentActivity, EventResult};
use script_traits::{InitialScriptState, JsEvalResult, LayoutMsg, LoadData}; use script_traits::{InitialScriptState, JsEvalResult, LayoutMsg, LoadData};
use script_traits::{MouseButton, MouseEventType, MozBrowserEvent, NewLayoutInfo}; use script_traits::{MouseButton, MouseEventType, MozBrowserEvent, NewLayoutInfo};
use script_traits::{PWMType, Painter, ScriptMsg, ScriptThreadFactory}; use script_traits::{ProgressiveWebMetricType, Painter, ScriptMsg, ScriptThreadFactory};
use script_traits::{ScriptToConstellationChan, TimerEvent, TimerSchedulerMsg}; use script_traits::{ScriptToConstellationChan, TimerEvent, TimerSchedulerMsg};
use script_traits::{TimerSource, TouchEventType, TouchId, UntrustedNodeAddress}; use script_traits::{TimerSource, TouchEventType, TouchId, UntrustedNodeAddress};
use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType}; use script_traits::{UpdatePipelineIdReason, WindowSizeData, WindowSizeType};
@ -415,17 +414,17 @@ pub struct ScriptThread {
/// events in the event queue. /// events in the event queue.
chan: MainThreadScriptChan, chan: MainThreadScriptChan,
dom_manipulation_task_source: DOMManipulationTaskSource, dom_manipulation_task_sender: Sender<MainThreadScriptMsg>,
user_interaction_task_source: UserInteractionTaskSource, user_interaction_task_sender: Sender<MainThreadScriptMsg>,
networking_task_source: NetworkingTaskSource, networking_task_sender: Box<ScriptChan>,
history_traversal_task_source: HistoryTraversalTaskSource, history_traversal_task_source: HistoryTraversalTaskSource,
file_reading_task_source: FileReadingTaskSource, file_reading_task_sender: Box<ScriptChan>,
performance_timeline_task_source: PerformanceTimelineTaskSource, performance_timeline_task_sender: Box<ScriptChan>,
/// A channel to hand out to threads that need to respond to a message from the script thread. /// A channel to hand out to threads that need to respond to a message from the script thread.
control_chan: IpcSender<ConstellationControlMsg>, control_chan: IpcSender<ConstellationControlMsg>,
@ -686,8 +685,8 @@ impl ScriptThread {
SCRIPT_THREAD_ROOT.with(|root| { SCRIPT_THREAD_ROOT.with(|root| {
if let Some(script_thread) = root.get() { if let Some(script_thread) = root.get() {
let script_thread = unsafe { &*script_thread }; let script_thread = unsafe { &*script_thread };
let p_id = Some(new_layout_info.new_pipeline_id); let pipeline_id = Some(new_layout_info.new_pipeline_id);
script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, p_id, || { script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, pipeline_id, || {
script_thread.handle_new_layout(new_layout_info, origin); script_thread.handle_new_layout(new_layout_info, origin);
}) })
} }
@ -836,12 +835,13 @@ impl ScriptThread {
port: port, port: port,
chan: MainThreadScriptChan(chan.clone()), chan: MainThreadScriptChan(chan.clone()),
dom_manipulation_task_source: DOMManipulationTaskSource(chan.clone()), dom_manipulation_task_sender: chan.clone(),
user_interaction_task_source: UserInteractionTaskSource(chan.clone()), user_interaction_task_sender: chan.clone(),
networking_task_source: NetworkingTaskSource(boxed_script_sender.clone()), networking_task_sender: boxed_script_sender.clone(),
file_reading_task_sender: boxed_script_sender.clone(),
performance_timeline_task_sender: boxed_script_sender.clone(),
history_traversal_task_source: HistoryTraversalTaskSource(chan), history_traversal_task_source: HistoryTraversalTaskSource(chan),
file_reading_task_source: FileReadingTaskSource(boxed_script_sender.clone()),
performance_timeline_task_source: PerformanceTimelineTaskSource(boxed_script_sender),
control_chan: state.control_chan, control_chan: state.control_chan,
control_port: control_port, control_port: control_port,
@ -970,8 +970,8 @@ impl ScriptThread {
// child list yet, causing the find() to fail. // child list yet, causing the find() to fail.
FromConstellation(ConstellationControlMsg::AttachLayout( FromConstellation(ConstellationControlMsg::AttachLayout(
new_layout_info)) => { new_layout_info)) => {
//FIXME there should be a pipeline id let pipeline_id = new_layout_info.new_pipeline_id;
self.profile_event(ScriptThreadEventCategory::AttachLayout, None, || { self.profile_event(ScriptThreadEventCategory::AttachLayout, Some(pipeline_id), || {
// If this is an about:blank load, it must share the creator's origin. // If this is an about:blank load, it must share the creator's origin.
// This must match the logic in the constellation when creating a new pipeline // This must match the logic in the constellation when creating a new pipeline
let origin = if new_layout_info.load_data.url.as_str() != "about:blank" { let origin = if new_layout_info.load_data.url.as_str() != "about:blank" {
@ -1060,9 +1060,9 @@ impl ScriptThread {
debug!("Processing event {:?}.", msg); debug!("Processing event {:?}.", msg);
let category = self.categorize_msg(&msg); let category = self.categorize_msg(&msg);
let p_id = self.message_to_pipeline(&msg); let pipeline_id = self.message_to_pipeline(&msg);
let result = self.profile_event(category, p_id, move || { let result = self.profile_event(category, pipeline_id, move || {
match msg { match msg {
FromConstellation(ConstellationControlMsg::ExitScriptThread) => { FromConstellation(ConstellationControlMsg::ExitScriptThread) => {
self.handle_exit_script_thread_msg(); self.handle_exit_script_thread_msg();
@ -1127,6 +1127,7 @@ impl ScriptThread {
_ => ScriptThreadEventCategory::ConstellationMsg _ => ScriptThreadEventCategory::ConstellationMsg
} }
}, },
// TODO https://github.com/servo/servo/issues/18998
MixedMessage::FromDevtools(_) => ScriptThreadEventCategory::DevtoolsMsg, MixedMessage::FromDevtools(_) => ScriptThreadEventCategory::DevtoolsMsg,
MixedMessage::FromImageCache(_) => ScriptThreadEventCategory::ImageCacheMsg, MixedMessage::FromImageCache(_) => ScriptThreadEventCategory::ImageCacheMsg,
MixedMessage::FromScript(ref inner_msg) => { MixedMessage::FromScript(ref inner_msg) => {
@ -1169,15 +1170,15 @@ impl ScriptThread {
FocusIFrame(id, ..) => Some(id), FocusIFrame(id, ..) => Some(id),
WebDriverScriptCommand(id, ..) => Some(id), WebDriverScriptCommand(id, ..) => Some(id),
TickAllAnimations(id) => Some(id), TickAllAnimations(id) => Some(id),
// FIXME https://github.com/servo/servo/issues/15079
TransitionEnd(..) => None, TransitionEnd(..) => None,
WebFontLoaded(id) => Some(id), WebFontLoaded(id) => Some(id),
DispatchIFrameLoadEvent { .. } => None, DispatchIFrameLoadEvent { target: _, parent: id, child: _ } => Some(id),
DispatchStorageEvent(id, ..) => Some(id), DispatchStorageEvent(id, ..) => Some(id),
ReportCSSError(id, ..) => Some(id), ReportCSSError(id, ..) => Some(id),
Reload(id, ..) => Some(id), Reload(id, ..) => Some(id),
WebVREvents(id, ..) => Some(id), WebVREvents(id, ..) => Some(id),
PaintMetric(..) => None, PaintMetric(..) => None,
InteractiveMetric(..) => None,
} }
}, },
MixedMessage::FromDevtools(_) => None, MixedMessage::FromDevtools(_) => None,
@ -1185,7 +1186,7 @@ impl ScriptThread {
match *inner_msg { match *inner_msg {
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, _, pipeline_id)) => MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, _, pipeline_id)) =>
pipeline_id, pipeline_id,
MainThreadScriptMsg::Common(_) => None, //TODO double check MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(_)) => None,
MainThreadScriptMsg::ExitWindow(pipeline_id) => Some(pipeline_id), MainThreadScriptMsg::ExitWindow(pipeline_id) => Some(pipeline_id),
MainThreadScriptMsg::Navigate(pipeline_id, ..) => Some(pipeline_id), MainThreadScriptMsg::Navigate(pipeline_id, ..) => Some(pipeline_id),
MainThreadScriptMsg::WorkletLoaded(pipeline_id) => Some(pipeline_id), MainThreadScriptMsg::WorkletLoaded(pipeline_id) => Some(pipeline_id),
@ -1204,9 +1205,10 @@ impl ScriptThread {
} }
} }
fn profile_event<F, R>(&self, category: ScriptThreadEventCategory, p_id: Option<PipelineId>, f: F) -> R fn profile_event<F, R>(&self, category: ScriptThreadEventCategory, pipeline_id: Option<PipelineId>, f: F) -> R
where F: FnOnce() -> R { where F: FnOnce() -> R {
if opts::get().profile_script_events { let start = precise_time_ns();
let value = if opts::get().profile_script_events {
let profiler_cat = match category { let profiler_cat = match category {
ScriptThreadEventCategory::AttachLayout => ProfilerCategory::ScriptAttachLayout, ScriptThreadEventCategory::AttachLayout => ProfilerCategory::ScriptAttachLayout,
ScriptThreadEventCategory::ConstellationMsg => ProfilerCategory::ScriptConstellationMsg, ScriptThreadEventCategory::ConstellationMsg => ProfilerCategory::ScriptConstellationMsg,
@ -1238,27 +1240,20 @@ impl ScriptThread {
ScriptThreadEventCategory::ExitFullscreen => ProfilerCategory::ScriptExitFullscreen, ScriptThreadEventCategory::ExitFullscreen => ProfilerCategory::ScriptExitFullscreen,
ScriptThreadEventCategory::PerformanceTimelineTask => ProfilerCategory::ScriptPerformanceEvent, ScriptThreadEventCategory::PerformanceTimelineTask => ProfilerCategory::ScriptPerformanceEvent,
}; };
profile(profiler_cat, None, self.time_profiler_chan.clone(), f)
let start = precise_time_ns();
let t = profile(profiler_cat, None, self.time_profiler_chan.clone(), f);
let end = precise_time_ns();
debug!("Task {:?} took {}", category, end - start); // TODO do we want to do anything with this?
for (doc_id, doc) in self.documents.borrow().iter() {
match p_id {
Some(p_id) => {
if p_id == doc_id && end - start > InteractiveWindow::max_task_time() {
doc.start_tti()
}
},
_ => ()
}
doc.check_tti();
}
t
} else { } else {
f() f()
};
let end = precise_time_ns();
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 {
doc.start_tti();
}
}
doc.record_tti_if_necessary();
} }
value
} }
fn handle_msg_from_constellation(&self, msg: ConstellationControlMsg) { fn handle_msg_from_constellation(&self, msg: ConstellationControlMsg) {
@ -1326,7 +1321,6 @@ impl ScriptThread {
self.handle_webvr_events(pipeline_id, events), self.handle_webvr_events(pipeline_id, events),
ConstellationControlMsg::PaintMetric(pipeline_id, metric_type, metric_value) => ConstellationControlMsg::PaintMetric(pipeline_id, metric_type, metric_value) =>
self.handle_paint_metric(pipeline_id, metric_type, metric_value), self.handle_paint_metric(pipeline_id, metric_type, metric_value),
ConstellationControlMsg::InteractiveMetric(pipeline_id, metric_value) => (), //TODO
msg @ ConstellationControlMsg::AttachLayout(..) | msg @ ConstellationControlMsg::AttachLayout(..) |
msg @ ConstellationControlMsg::Viewport(..) | msg @ ConstellationControlMsg::Viewport(..) |
msg @ ConstellationControlMsg::SetScrollState(..) | msg @ ConstellationControlMsg::SetScrollState(..) |
@ -1812,12 +1806,24 @@ impl ScriptThread {
let _ = self.chan.0.send(MainThreadScriptMsg::DispatchJobQueue { scope_url }); let _ = self.chan.0.send(MainThreadScriptMsg::DispatchJobQueue { scope_url });
} }
pub fn dom_manipulation_task_source(&self) -> &DOMManipulationTaskSource { pub fn dom_manipulation_task_source(&self, pipeline_id: PipelineId) -> DOMManipulationTaskSource {
&self.dom_manipulation_task_source DOMManipulationTaskSource(self.dom_manipulation_task_sender.clone(), pipeline_id)
} }
pub fn performance_timeline_task_source(&self) -> &PerformanceTimelineTaskSource { pub fn performance_timeline_task_source(&self, pipeline_id: PipelineId) -> PerformanceTimelineTaskSource {
&self.performance_timeline_task_source PerformanceTimelineTaskSource(self.performance_timeline_task_sender.clone(), pipeline_id)
}
pub fn user_interaction_task_source(&self, pipeline_id: PipelineId) -> UserInteractionTaskSource {
UserInteractionTaskSource(self.user_interaction_task_sender.clone(), pipeline_id)
}
pub fn networking_task_source(&self, pipeline_id: PipelineId) -> NetworkingTaskSource {
NetworkingTaskSource(self.networking_task_sender.clone(), pipeline_id)
}
pub fn file_reading_task_source(&self, pipeline_id: PipelineId) -> FileReadingTaskSource {
FileReadingTaskSource(self.file_reading_task_sender.clone(), pipeline_id)
} }
/// Handles a request for the window title. /// Handles a request for the window title.
@ -2105,8 +2111,6 @@ impl ScriptThread {
debug!("ScriptThread: loading {} on pipeline {:?}", incomplete.url, incomplete.pipeline_id); debug!("ScriptThread: loading {} on pipeline {:?}", incomplete.url, incomplete.pipeline_id);
let MainThreadScriptChan(ref sender) = self.chan; let MainThreadScriptChan(ref sender) = self.chan;
let DOMManipulationTaskSource(ref dom_sender) = self.dom_manipulation_task_source;
let UserInteractionTaskSource(ref user_sender) = self.user_interaction_task_source;
let HistoryTraversalTaskSource(ref history_sender) = self.history_traversal_task_source; let HistoryTraversalTaskSource(ref history_sender) = self.history_traversal_task_source;
let (ipc_timer_event_chan, ipc_timer_event_port) = ipc::channel().unwrap(); let (ipc_timer_event_chan, ipc_timer_event_port) = ipc::channel().unwrap();
@ -2128,12 +2132,12 @@ impl ScriptThread {
let window = Window::new( let window = Window::new(
self.js_runtime.clone(), self.js_runtime.clone(),
MainThreadScriptChan(sender.clone()), MainThreadScriptChan(sender.clone()),
DOMManipulationTaskSource(dom_sender.clone()), self.dom_manipulation_task_source(incomplete.pipeline_id),
UserInteractionTaskSource(user_sender.clone()), self.user_interaction_task_source(incomplete.pipeline_id),
self.networking_task_source.clone(), self.networking_task_source(incomplete.pipeline_id),
HistoryTraversalTaskSource(history_sender.clone()), HistoryTraversalTaskSource(history_sender.clone()),
self.file_reading_task_source.clone(), self.file_reading_task_source(incomplete.pipeline_id),
self.performance_timeline_task_source.clone(), self.performance_timeline_task_source(incomplete.pipeline_id).clone(),
self.image_cache_channel.clone(), self.image_cache_channel.clone(),
self.image_cache.clone(), self.image_cache.clone(),
self.resource_threads.clone(), self.resource_threads.clone(),
@ -2650,7 +2654,7 @@ impl ScriptThread {
fn handle_paint_metric(&self, fn handle_paint_metric(&self,
pipeline_id: PipelineId, pipeline_id: PipelineId,
metric_type: PWMType, metric_type: ProgressiveWebMetricType,
metric_value: f64) { metric_value: f64) {
let window = self.documents.borrow().find_window(pipeline_id); let window = self.documents.borrow().find_window(pipeline_id);
if let Some(window) = window { if let Some(window) = window {

View file

@ -153,19 +153,21 @@ impl JobQueue {
// https://w3c.github.io/ServiceWorker/#register-algorithm // https://w3c.github.io/ServiceWorker/#register-algorithm
fn run_register(&self, job: &Job, scope_url: ServoUrl, script_thread: &ScriptThread) { fn run_register(&self, job: &Job, scope_url: ServoUrl, script_thread: &ScriptThread) {
debug!("running register job"); debug!("running register job");
let global = &*job.client.global();
let pipeline_id = global.pipeline_id();
// Step 1-3 // Step 1-3
if !UrlHelper::is_origin_trustworthy(&job.script_url) { if !UrlHelper::is_origin_trustworthy(&job.script_url) {
// Step 1.1 // Step 1.1
reject_job_promise(job, reject_job_promise(job,
Error::Type("Invalid script ServoURL".to_owned()), Error::Type("Invalid script ServoURL".to_owned()),
script_thread.dom_manipulation_task_source()); &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 1.2 (see run_job) // Step 1.2 (see run_job)
return; return;
} else if job.script_url.origin() != job.referrer.origin() || job.scope_url.origin() != job.referrer.origin() { } else if job.script_url.origin() != job.referrer.origin() || job.scope_url.origin() != job.referrer.origin() {
// Step 2.1/3.1 // Step 2.1/3.1
reject_job_promise(job, reject_job_promise(job,
Error::Security, Error::Security,
script_thread.dom_manipulation_task_source()); &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 2.2/3.2 (see run_job) // Step 2.2/3.2 (see run_job)
return; return;
} }
@ -180,17 +182,15 @@ impl JobQueue {
if let Some(ref newest_worker) = reg.get_newest_worker() { if let Some(ref newest_worker) = reg.get_newest_worker() {
if (&*newest_worker).get_script_url() == job.script_url { if (&*newest_worker).get_script_url() == job.script_url {
// Step 5.3.1 // Step 5.3.1
resolve_job_promise(job, &*reg, script_thread.dom_manipulation_task_source()); resolve_job_promise(job, &*reg, &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 5.3.2 (see run_job) // Step 5.3.2 (see run_job)
return; return;
} }
} }
} else { } else {
// Step 6.1 // Step 6.1
let global = &*job.client.global();
let pipeline = global.pipeline_id();
let new_reg = ServiceWorkerRegistration::new(&*global, &job.script_url, scope_url); let new_reg = ServiceWorkerRegistration::new(&*global, &job.script_url, scope_url);
script_thread.handle_serviceworker_registration(&job.scope_url, &*new_reg, pipeline); script_thread.handle_serviceworker_registration(&job.scope_url, &*new_reg, pipeline_id);
} }
// Step 7 // Step 7
self.update(job, script_thread) self.update(job, script_thread)
@ -218,13 +218,16 @@ impl JobQueue {
// https://w3c.github.io/ServiceWorker/#update-algorithm // https://w3c.github.io/ServiceWorker/#update-algorithm
fn update(&self, job: &Job, script_thread: &ScriptThread) { fn update(&self, job: &Job, script_thread: &ScriptThread) {
debug!("running update job"); debug!("running update job");
let global = &*job.client.global();
let pipeline_id = global.pipeline_id();
// Step 1 // Step 1
let reg = match script_thread.handle_get_registration(&job.scope_url) { let reg = match script_thread.handle_get_registration(&job.scope_url) {
Some(reg) => reg, Some(reg) => reg,
None => { None => {
let err_type = Error::Type("No registration to update".to_owned()); let err_type = Error::Type("No registration to update".to_owned());
// Step 2.1 // Step 2.1
reject_job_promise(job, err_type, script_thread.dom_manipulation_task_source()); reject_job_promise(job, err_type, &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 2.2 (see run_job) // Step 2.2 (see run_job)
return; return;
} }
@ -233,7 +236,7 @@ impl JobQueue {
if reg.get_uninstalling() { if reg.get_uninstalling() {
let err_type = Error::Type("Update called on an uninstalling registration".to_owned()); let err_type = Error::Type("Update called on an uninstalling registration".to_owned());
// Step 2.1 // Step 2.1
reject_job_promise(job, err_type, script_thread.dom_manipulation_task_source()); reject_job_promise(job, err_type, &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 2.2 (see run_job) // Step 2.2 (see run_job)
return; return;
} }
@ -244,7 +247,7 @@ impl JobQueue {
if newest_worker_url.as_ref() == Some(&job.script_url) && job.job_type == JobType::Update { if newest_worker_url.as_ref() == Some(&job.script_url) && job.job_type == JobType::Update {
let err_type = Error::Type("Invalid script ServoURL".to_owned()); let err_type = Error::Type("Invalid script ServoURL".to_owned());
// Step 4.1 // Step 4.1
reject_job_promise(job, err_type, script_thread.dom_manipulation_task_source()); reject_job_promise(job, err_type, &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 4.2 (see run_job) // Step 4.2 (see run_job)
return; return;
} }
@ -252,7 +255,7 @@ impl JobQueue {
if let Some(newest_worker) = newest_worker { if let Some(newest_worker) = newest_worker {
job.client.set_controller(&*newest_worker); job.client.set_controller(&*newest_worker);
// Step 8.1 // Step 8.1
resolve_job_promise(job, &*reg, script_thread.dom_manipulation_task_source()); resolve_job_promise(job, &*reg, &script_thread.dom_manipulation_task_source(pipeline_id));
// Step 8.2 present in run_job // Step 8.2 present in run_job
} }
// TODO Step 9 (create new service worker) // TODO Step 9 (create new service worker)

View file

@ -7,6 +7,7 @@ use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask}; use dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask};
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
use dom::window::Window; use dom::window::Window;
use msg::constellation_msg::PipelineId;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::MainThreadScriptMsg; use script_thread::MainThreadScriptMsg;
use servo_atoms::Atom; use servo_atoms::Atom;
@ -17,7 +18,7 @@ use task::{TaskCanceller, TaskOnce};
use task_source::TaskSource; use task_source::TaskSource;
#[derive(Clone, JSTraceable)] #[derive(Clone, JSTraceable)]
pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>); pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>, pub PipelineId);
impl fmt::Debug for DOMManipulationTaskSource { impl fmt::Debug for DOMManipulationTaskSource {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -37,7 +38,7 @@ impl TaskSource for DOMManipulationTaskSource {
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
ScriptThreadEventCategory::ScriptEvent, ScriptThreadEventCategory::ScriptEvent,
Box::new(canceller.wrap_task(task)), Box::new(canceller.wrap_task(task)),
None //TODO Some(self.1)
)); ));
self.0.send(msg).map_err(|_| ()) self.0.send(msg).map_err(|_| ())
} }

View file

@ -4,17 +4,18 @@
use dom::domexception::DOMErrorName; use dom::domexception::DOMErrorName;
use dom::filereader::{FileReader, TrustedFileReader, GenerationId, ReadMetaData}; use dom::filereader::{FileReader, TrustedFileReader, GenerationId, ReadMetaData};
use msg::constellation_msg::PipelineId;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan}; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan};
use std::sync::Arc; use std::sync::Arc;
use task::{TaskCanceller, TaskOnce}; use task::{TaskCanceller, TaskOnce};
use task_source::TaskSource; use task_source::TaskSource;
#[derive(JSTraceable)] #[derive(JSTraceable)]
pub struct FileReadingTaskSource(pub Box<ScriptChan + Send + 'static>); pub struct FileReadingTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId);
impl Clone for FileReadingTaskSource { impl Clone for FileReadingTaskSource {
fn clone(&self) -> FileReadingTaskSource { fn clone(&self) -> FileReadingTaskSource {
FileReadingTaskSource(self.0.clone()) FileReadingTaskSource(self.0.clone(), self.1.clone())
} }
} }
@ -30,7 +31,7 @@ impl TaskSource for FileReadingTaskSource {
self.0.send(CommonScriptMsg::Task( self.0.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::FileRead, ScriptThreadEventCategory::FileRead,
Box::new(canceller.wrap_task(task)), Box::new(canceller.wrap_task(task)),
None //TODO Some(self.1),
)) ))
} }
} }

View file

@ -2,16 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use msg::constellation_msg::PipelineId;
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
use task::{TaskCanceller, TaskOnce}; use task::{TaskCanceller, TaskOnce};
use task_source::TaskSource; use task_source::TaskSource;
#[derive(JSTraceable)] #[derive(JSTraceable)]
pub struct NetworkingTaskSource(pub Box<ScriptChan + Send + 'static>); pub struct NetworkingTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId);
impl Clone for NetworkingTaskSource { impl Clone for NetworkingTaskSource {
fn clone(&self) -> NetworkingTaskSource { fn clone(&self) -> NetworkingTaskSource {
NetworkingTaskSource(self.0.clone()) NetworkingTaskSource(self.0.clone(), self.1.clone())
} }
} }
@ -27,7 +28,7 @@ impl TaskSource for NetworkingTaskSource {
self.0.send(CommonScriptMsg::Task( self.0.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::NetworkEvent, ScriptThreadEventCategory::NetworkEvent,
Box::new(canceller.wrap_task(task)), Box::new(canceller.wrap_task(task)),
None Some(self.1),
)) ))
} }
} }
@ -42,7 +43,7 @@ impl NetworkingTaskSource {
self.0.send(CommonScriptMsg::Task( self.0.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::NetworkEvent, ScriptThreadEventCategory::NetworkEvent,
Box::new(task), Box::new(task),
None //TODO Some(self.1),
)) ))
} }
} }

View file

@ -8,6 +8,7 @@
use dom::bindings::refcounted::Trusted; use dom::bindings::refcounted::Trusted;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use msg::constellation_msg::PipelineId;
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
use std::fmt; use std::fmt;
use std::result::Result; use std::result::Result;
@ -15,11 +16,11 @@ use task::{TaskCanceller, TaskOnce};
use task_source::TaskSource; use task_source::TaskSource;
#[derive(JSTraceable)] #[derive(JSTraceable)]
pub struct PerformanceTimelineTaskSource(pub Box<ScriptChan + Send + 'static>); pub struct PerformanceTimelineTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId);
impl Clone for PerformanceTimelineTaskSource { impl Clone for PerformanceTimelineTaskSource {
fn clone(&self) -> PerformanceTimelineTaskSource { fn clone(&self) -> PerformanceTimelineTaskSource {
PerformanceTimelineTaskSource(self.0.clone()) PerformanceTimelineTaskSource(self.0.clone(), self.1.clone())
} }
} }
@ -41,7 +42,7 @@ impl TaskSource for PerformanceTimelineTaskSource {
let msg = CommonScriptMsg::Task( let msg = CommonScriptMsg::Task(
ScriptThreadEventCategory::PerformanceTimelineTask, ScriptThreadEventCategory::PerformanceTimelineTask,
Box::new(canceller.wrap_task(task)), Box::new(canceller.wrap_task(task)),
None Some(self.1)
); );
self.0.send(msg).map_err(|_| ()) self.0.send(msg).map_err(|_| ())
} }

View file

@ -7,6 +7,7 @@ use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventTask}; use dom::event::{EventBubbles, EventCancelable, EventTask};
use dom::eventtarget::EventTarget; use dom::eventtarget::EventTarget;
use dom::window::Window; use dom::window::Window;
use msg::constellation_msg::PipelineId;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::MainThreadScriptMsg; use script_thread::MainThreadScriptMsg;
use servo_atoms::Atom; use servo_atoms::Atom;
@ -17,7 +18,7 @@ use task::{TaskCanceller, TaskOnce};
use task_source::TaskSource; use task_source::TaskSource;
#[derive(Clone, JSTraceable)] #[derive(Clone, JSTraceable)]
pub struct UserInteractionTaskSource(pub Sender<MainThreadScriptMsg>); pub struct UserInteractionTaskSource(pub Sender<MainThreadScriptMsg>, pub PipelineId);
impl fmt::Debug for UserInteractionTaskSource { impl fmt::Debug for UserInteractionTaskSource {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -37,7 +38,7 @@ impl TaskSource for UserInteractionTaskSource {
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
ScriptThreadEventCategory::InputEvent, ScriptThreadEventCategory::InputEvent,
Box::new(canceller.wrap_task(task)), Box::new(canceller.wrap_task(task)),
None Some(self.1)
)); ));
self.0.send(msg).map_err(|_| ()) self.0.send(msg).map_err(|_| ())
} }

View file

@ -233,7 +233,7 @@ pub enum DocumentActivity {
/// Type of recorded progressive web metric /// Type of recorded progressive web metric
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum PWMType { pub enum ProgressiveWebMetricType {
/// Time to first Paint /// Time to first Paint
FirstPaint, FirstPaint,
/// Time to first contentful paint /// Time to first contentful paint
@ -324,9 +324,7 @@ pub enum ConstellationControlMsg {
/// Notifies the script thread of WebVR events. /// Notifies the script thread of WebVR events.
WebVREvents(PipelineId, Vec<WebVREvent>), WebVREvents(PipelineId, Vec<WebVREvent>),
/// Notifies the script thread about a new recorded paint metric. /// Notifies the script thread about a new recorded paint metric.
PaintMetric(PipelineId, PWMType, f64), PaintMetric(PipelineId, ProgressiveWebMetricType, f64),
/// Notifies the script thread of interactive time
InteractiveMetric(PipelineId, f64),
} }
impl fmt::Debug for ConstellationControlMsg { impl fmt::Debug for ConstellationControlMsg {
@ -361,7 +359,6 @@ impl fmt::Debug for ConstellationControlMsg {
Reload(..) => "Reload", Reload(..) => "Reload",
WebVREvents(..) => "WebVREvents", WebVREvents(..) => "WebVREvents",
PaintMetric(..) => "PaintMetric", PaintMetric(..) => "PaintMetric",
InteractiveMetric(..) => "InteractiveMetric"
}; };
write!(formatter, "ConstellationMsg::{}", variant) write!(formatter, "ConstellationMsg::{}", variant)
} }

View file

@ -34,12 +34,12 @@ fn test_set_dcl() {
let profiler_metadata_factory = DummyProfilerMetadataFactory {}; let profiler_metadata_factory = DummyProfilerMetadataFactory {};
let interactive = test_interactive(); let interactive = test_interactive();
interactive.maybe_set_tti(&profiler_metadata_factory, None, InteractiveFlag::DCL); interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
let dcl = interactive.get_dom_content_loaded(); let dcl = interactive.get_dom_content_loaded();
assert!(dcl.is_some()); assert!(dcl.is_some());
//try to overwrite //try to overwrite
interactive.maybe_set_tti(&profiler_metadata_factory, None, InteractiveFlag::DCL); interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
assert_eq!(interactive.get_dom_content_loaded(), dcl); assert_eq!(interactive.get_dom_content_loaded(), dcl);
assert_eq!(interactive.get_tti(), None); assert_eq!(interactive.get_tti(), None);
} }
@ -52,8 +52,7 @@ fn test_set_mta() {
let t = time::precise_time_ns(); let t = time::precise_time_ns();
interactive.maybe_set_tti( interactive.maybe_set_tti(
&profiler_metadata_factory, &profiler_metadata_factory,
Some(t as f64), InteractiveFlag::TimeToInteractive(t as f64),
InteractiveFlag::TTI,
); );
let mta = interactive.get_main_thread_available(); let mta = interactive.get_main_thread_available();
assert!(mta.is_some()); assert!(mta.is_some());
@ -62,8 +61,7 @@ fn test_set_mta() {
//try to overwrite //try to overwrite
interactive.maybe_set_tti( interactive.maybe_set_tti(
&profiler_metadata_factory, &profiler_metadata_factory,
Some(time::precise_time_ns() as f64), InteractiveFlag::TimeToInteractive(time::precise_time_ns() as f64),
InteractiveFlag::TTI,
); );
assert_eq!(interactive.get_main_thread_available(), mta); assert_eq!(interactive.get_main_thread_available(), mta);
assert_eq!(interactive.get_tti(), None); assert_eq!(interactive.get_tti(), None);
@ -77,13 +75,12 @@ fn test_set_tti_dcl() {
let t = time::precise_time_ns(); let t = time::precise_time_ns();
interactive.maybe_set_tti( interactive.maybe_set_tti(
&profiler_metadata_factory, &profiler_metadata_factory,
Some(t as f64), InteractiveFlag::TimeToInteractive(t as f64),
InteractiveFlag::TTI,
); );
let mta = interactive.get_main_thread_available(); let mta = interactive.get_main_thread_available();
assert!(mta.is_some()); assert!(mta.is_some());
interactive.maybe_set_tti(&profiler_metadata_factory, None, InteractiveFlag::DCL); interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
let dcl = interactive.get_dom_content_loaded(); let dcl = interactive.get_dom_content_loaded();
assert!(dcl.is_some()); assert!(dcl.is_some());
@ -96,15 +93,14 @@ fn test_set_tti_mta() {
let profiler_metadata_factory = DummyProfilerMetadataFactory {}; let profiler_metadata_factory = DummyProfilerMetadataFactory {};
let interactive = test_interactive(); let interactive = test_interactive();
interactive.maybe_set_tti(&profiler_metadata_factory, None, InteractiveFlag::DCL); interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
let dcl = interactive.get_dom_content_loaded(); let dcl = interactive.get_dom_content_loaded();
assert!(dcl.is_some()); assert!(dcl.is_some());
let t = time::precise_time_ns(); let t = time::precise_time_ns();
interactive.maybe_set_tti( interactive.maybe_set_tti(
&profiler_metadata_factory, &profiler_metadata_factory,
Some(t as f64), InteractiveFlag::TimeToInteractive(t as f64),
InteractiveFlag::TTI,
); );
let mta = interactive.get_main_thread_available(); let mta = interactive.get_main_thread_available();
assert!(mta.is_some()); assert!(mta.is_some());

View file

@ -15,4 +15,5 @@ extern crate time;
#[cfg(test)] #[cfg(test)]
mod interactive_time; mod interactive_time;
#[cfg(test)]
mod paint_time; mod paint_time;

View file

@ -100,7 +100,7 @@ fn test_first_paint_setter() {
clip_scroll_nodes: Vec::new(), clip_scroll_nodes: Vec::new(),
}; };
let epoch = Epoch(0); let epoch = Epoch(0);
let mut paint_time_metrics = test_common(&empty_display_list, epoch); let paint_time_metrics = test_common(&empty_display_list, epoch);
let now = time::precise_time_ns() as f64; let now = time::precise_time_ns() as f64;
paint_time_metrics.maybe_set_metric(epoch, now); paint_time_metrics.maybe_set_metric(epoch, now);
assert!( assert!(
@ -134,7 +134,7 @@ fn test_first_contentful_paint_setter() {
clip_scroll_nodes: Vec::new(), clip_scroll_nodes: Vec::new(),
}; };
let epoch = Epoch(0); let epoch = Epoch(0);
let mut paint_time_metrics = test_common(&display_list, epoch); let paint_time_metrics = test_common(&display_list, epoch);
let now = time::precise_time_ns() as f64; let now = time::precise_time_ns() as f64;
paint_time_metrics.maybe_set_metric(epoch, now); paint_time_metrics.maybe_set_metric(epoch, now);
assert!( assert!(