mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #18670 - avadacatavra:interactive-metrics, r=jdm
added time to interactive metrics <!-- Please describe your changes on the following line: --> Added time to interactive metrics and refactored metrics/lib I need to write tests, but wanted to submit the PR for review --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (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/18670) <!-- Reviewable:end -->
This commit is contained in:
commit
e438b094f6
28 changed files with 738 additions and 182 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1820,10 +1820,13 @@ dependencies = [
|
||||||
"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)",
|
||||||
"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_derive 0.0.1",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
|
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -86,7 +86,7 @@ use layout::wrapper::LayoutNodeLayoutData;
|
||||||
use layout_traits::LayoutThreadFactory;
|
use layout_traits::LayoutThreadFactory;
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory, ProgressiveWebMetric};
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||||
use net_traits::image_cache::{ImageCache, UsePlaceholder};
|
use net_traits::image_cache::{ImageCache, UsePlaceholder};
|
||||||
|
|
|
@ -14,7 +14,10 @@ gfx = {path = "../gfx"}
|
||||||
gfx_traits = {path = "../gfx_traits"}
|
gfx_traits = {path = "../gfx_traits"}
|
||||||
ipc-channel = "0.9"
|
ipc-channel = "0.9"
|
||||||
log = "0.3.5"
|
log = "0.3.5"
|
||||||
|
malloc_size_of = { path = "../malloc_size_of" }
|
||||||
|
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||||
msg = {path = "../msg"}
|
msg = {path = "../msg"}
|
||||||
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"}
|
||||||
|
time = "0.1"
|
||||||
|
|
|
@ -7,10 +7,14 @@ extern crate gfx_traits;
|
||||||
extern crate ipc_channel;
|
extern crate ipc_channel;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
extern crate malloc_size_of;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate malloc_size_of_derive;
|
||||||
extern crate msg;
|
extern crate msg;
|
||||||
extern crate profile_traits;
|
extern crate profile_traits;
|
||||||
extern crate script_traits;
|
extern crate script_traits;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
|
extern crate time;
|
||||||
|
|
||||||
use gfx::display_list::{DisplayItem, DisplayList};
|
use gfx::display_list::{DisplayItem, DisplayList};
|
||||||
use gfx_traits::Epoch;
|
use gfx_traits::Epoch;
|
||||||
|
@ -18,56 +22,217 @@ 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, PaintMetricType};
|
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::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use time::precise_time_ns;
|
||||||
|
|
||||||
pub trait ProfilerMetadataFactory {
|
pub trait ProfilerMetadataFactory {
|
||||||
fn new_metadata(&self) -> Option<TimerMetadata>;
|
fn new_metadata(&self) -> Option<TimerMetadata>;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! make_time_setter(
|
pub trait ProgressiveWebMetric {
|
||||||
( $attr:ident, $func:ident, $category:ident, $label:expr, $metric_type:path ) => (
|
fn get_navigation_start(&self) -> Option<f64>;
|
||||||
fn $func(&self,
|
fn set_navigation_start(&mut self, time: f64);
|
||||||
profiler_metadata: Option<TimerMetadata>,
|
fn get_time_profiler_chan(&self) -> &ProfilerChan;
|
||||||
paint_time: f64) {
|
fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: f64);
|
||||||
if self.$attr.get().is_some() {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let navigation_start = match self.navigation_start {
|
/// maximum task time is 50ms (in ns)
|
||||||
Some(time) => time,
|
pub const MAX_TASK_NS: u64 = 50000000;
|
||||||
None => {
|
/// 10 second window (in ns)
|
||||||
warn!("Trying to set metric before navigation start");
|
const INTERACTIVE_WINDOW_SECONDS_IN_NS: u64 = 10000000000;
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let time = paint_time - navigation_start;
|
|
||||||
self.$attr.set(Some(time));
|
|
||||||
|
|
||||||
// Queue performance observer notification.
|
fn set_metric<U: ProgressiveWebMetric>(
|
||||||
let msg = ConstellationControlMsg::PaintMetric(self.pipeline_id,
|
pwm: &U,
|
||||||
$metric_type,
|
metadata: Option<TimerMetadata>,
|
||||||
time);
|
metric_type: ProgressiveWebMetricType,
|
||||||
if let Err(e) = self.script_chan.send(msg) {
|
category: ProfilerCategory,
|
||||||
warn!("Sending paint metric to script thread failed ({}).", e);
|
attr: &Cell<Option<f64>>,
|
||||||
}
|
metric_time: Option<f64>)
|
||||||
|
{
|
||||||
// Send the metric to the time profiler.
|
let navigation_start = match pwm.get_navigation_start() {
|
||||||
send_profile_data(ProfilerCategory::$category,
|
Some(time) => time,
|
||||||
profiler_metadata,
|
None => {
|
||||||
&self.time_profiler_chan,
|
warn!("Trying to set metric before navigation start");
|
||||||
time as u64, time as u64, 0, 0);
|
return;
|
||||||
|
|
||||||
// Print the metric to console if the print-pwm option was given.
|
|
||||||
if opts::get().print_pwm {
|
|
||||||
println!("{:?} {:?}", $label, time);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
let now = match metric_time {
|
||||||
|
Some(time) => time,
|
||||||
|
None => precise_time_ns() as f64,
|
||||||
|
};
|
||||||
|
let time = now - navigation_start;
|
||||||
|
attr.set(Some(time));
|
||||||
|
|
||||||
|
// Queue performance observer notification.
|
||||||
|
pwm.send_queued_constellation_msg(metric_type, time);
|
||||||
|
|
||||||
|
// Send the metric to the time profiler.
|
||||||
|
send_profile_data(
|
||||||
|
category,
|
||||||
|
metadata,
|
||||||
|
&pwm.get_time_profiler_chan(),
|
||||||
|
time as u64,
|
||||||
|
time as u64,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
);
|
);
|
||||||
);
|
|
||||||
|
// Print the metric to console if the print-pwm option was given.
|
||||||
|
if opts::get().print_pwm {
|
||||||
|
println!("{:?} {:?}", metric_type, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)]
|
||||||
|
pub struct InteractiveMetrics {
|
||||||
|
/// when we navigated to the page
|
||||||
|
navigation_start: Option<f64>,
|
||||||
|
/// indicates if the page is visually ready
|
||||||
|
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>>,
|
||||||
|
// max(main_thread_available, dom_content_loaded)
|
||||||
|
time_to_interactive: Cell<Option<f64>>,
|
||||||
|
#[ignore_malloc_size_of = "can't measure channels"]
|
||||||
|
time_profiler_chan: ProfilerChan,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf)]
|
||||||
|
pub struct InteractiveWindow {
|
||||||
|
start: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl InteractiveWindow {
|
||||||
|
pub fn new() -> InteractiveWindow {
|
||||||
|
InteractiveWindow {
|
||||||
|
start: precise_time_ns(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to either start or restart the 10s window
|
||||||
|
// start: we've added a new document
|
||||||
|
// restart: there was a task > 50ms
|
||||||
|
// not all documents are interactive
|
||||||
|
pub fn start_window(&mut self) {
|
||||||
|
self.start = precise_time_ns();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// check if 10s has elapsed since start
|
||||||
|
pub fn needs_check(&self) -> bool {
|
||||||
|
precise_time_ns() - self.start >= INTERACTIVE_WINDOW_SECONDS_IN_NS
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_start(&self) -> u64 {
|
||||||
|
self.start
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum InteractiveFlag {
|
||||||
|
DOMContentLoaded,
|
||||||
|
TimeToInteractive(f64),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InteractiveMetrics {
|
||||||
|
pub fn new(time_profiler_chan: ProfilerChan) -> InteractiveMetrics {
|
||||||
|
InteractiveMetrics {
|
||||||
|
navigation_start: None,
|
||||||
|
dom_content_loaded: Cell::new(None),
|
||||||
|
main_thread_available: Cell::new(None),
|
||||||
|
time_to_interactive: Cell::new(None),
|
||||||
|
time_profiler_chan: time_profiler_chan,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_dom_content_loaded(&self) {
|
||||||
|
if self.dom_content_loaded.get().is_none() {
|
||||||
|
self.dom_content_loaded.set(Some(precise_time_ns() as f64));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_main_thread_available(&self, time: f64) {
|
||||||
|
if self.main_thread_available.get().is_none() {
|
||||||
|
self.main_thread_available.set(Some(time));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_dom_content_loaded(&self) -> Option<f64> {
|
||||||
|
self.dom_content_loaded.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_main_thread_available(&self) -> Option<f64> {
|
||||||
|
self.main_thread_available.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// can set either dlc or tti first, but both must be set to actually calc metric
|
||||||
|
// when the second is set, set_tti is called with appropriate time
|
||||||
|
pub fn maybe_set_tti<T>(
|
||||||
|
&self,
|
||||||
|
profiler_metadata_factory: &T,
|
||||||
|
metric: InteractiveFlag,
|
||||||
|
) where
|
||||||
|
T: ProfilerMetadataFactory,
|
||||||
|
{
|
||||||
|
if self.get_tti().is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match metric {
|
||||||
|
InteractiveFlag::DOMContentLoaded => self.set_dom_content_loaded(),
|
||||||
|
InteractiveFlag::TimeToInteractive(time) => self.set_main_thread_available(time),
|
||||||
|
}
|
||||||
|
|
||||||
|
let dcl = self.dom_content_loaded.get();
|
||||||
|
let mta = self.main_thread_available.get();
|
||||||
|
let (dcl, mta) = match (dcl, mta) {
|
||||||
|
(Some(dcl), Some(mta)) => (dcl, mta),
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
let metric_time = match dcl.partial_cmp(&mta) {
|
||||||
|
Some(Ordering::Less) => mta,
|
||||||
|
Some(_) => dcl,
|
||||||
|
None => panic!("no ordering possible. something bad happened"),
|
||||||
|
};
|
||||||
|
set_metric(
|
||||||
|
self,
|
||||||
|
profiler_metadata_factory.new_metadata(),
|
||||||
|
ProgressiveWebMetricType::TimeToInteractive,
|
||||||
|
ProfilerCategory::TimeToInteractive,
|
||||||
|
&self.time_to_interactive,
|
||||||
|
Some(metric_time));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_tti(&self) -> Option<f64> {
|
||||||
|
self.time_to_interactive.get()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProgressiveWebMetric for InteractiveMetrics {
|
||||||
|
fn get_navigation_start(&self) -> Option<f64> {
|
||||||
|
self.navigation_start
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_navigation_start(&mut self, time: f64) {
|
||||||
|
self.navigation_start = Some(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: f64) { }
|
||||||
|
|
||||||
|
fn get_time_profiler_chan(&self) -> &ProfilerChan {
|
||||||
|
&self.time_profiler_chan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PaintTimeMetrics {
|
pub struct PaintTimeMetrics {
|
||||||
pending_metrics: RefCell<HashMap<Epoch, (Option<TimerMetadata>, bool)>>,
|
pending_metrics: RefCell<HashMap<Epoch, (Option<TimerMetadata>, bool)>>,
|
||||||
|
@ -81,11 +246,12 @@ pub struct PaintTimeMetrics {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PaintTimeMetrics {
|
impl PaintTimeMetrics {
|
||||||
pub fn new(pipeline_id: PipelineId,
|
pub fn new(
|
||||||
time_profiler_chan: ProfilerChan,
|
pipeline_id: PipelineId,
|
||||||
constellation_chan: IpcSender<LayoutMsg>,
|
time_profiler_chan: ProfilerChan,
|
||||||
script_chan: IpcSender<ConstellationControlMsg>)
|
constellation_chan: IpcSender<LayoutMsg>,
|
||||||
-> PaintTimeMetrics {
|
script_chan: IpcSender<ConstellationControlMsg>)
|
||||||
|
-> PaintTimeMetrics {
|
||||||
PaintTimeMetrics {
|
PaintTimeMetrics {
|
||||||
pending_metrics: RefCell::new(HashMap::new()),
|
pending_metrics: RefCell::new(HashMap::new()),
|
||||||
navigation_start: None,
|
navigation_start: None,
|
||||||
|
@ -98,24 +264,30 @@ impl PaintTimeMetrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_navigation_start(&mut self, time: f64) {
|
pub fn maybe_set_first_paint<T>(&self, profiler_metadata_factory: &T)
|
||||||
self.navigation_start = Some(time);
|
where
|
||||||
|
T: ProfilerMetadataFactory,
|
||||||
|
{
|
||||||
|
if self.first_paint.get().is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_metric(
|
||||||
|
self,
|
||||||
|
profiler_metadata_factory.new_metadata(),
|
||||||
|
ProgressiveWebMetricType::FirstPaint,
|
||||||
|
ProfilerCategory::TimeToFirstPaint,
|
||||||
|
&self.first_paint,
|
||||||
|
None,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
make_time_setter!(first_paint, set_first_paint,
|
pub fn maybe_observe_paint_time<T>(
|
||||||
TimeToFirstPaint,
|
&self,
|
||||||
"first-paint",
|
profiler_metadata_factory: &T,
|
||||||
PaintMetricType::FirstPaint);
|
epoch: Epoch,
|
||||||
make_time_setter!(first_contentful_paint, set_first_contentful_paint,
|
display_list: &DisplayList)
|
||||||
TimeToFirstContentfulPaint,
|
where T: ProfilerMetadataFactory {
|
||||||
"first-contentful-paint",
|
|
||||||
PaintMetricType::FirstContentfulPaint);
|
|
||||||
|
|
||||||
pub fn maybe_observe_paint_time<T>(&self,
|
|
||||||
profiler_metadata_factory: &T,
|
|
||||||
epoch: Epoch,
|
|
||||||
display_list: &DisplayList)
|
|
||||||
where 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;
|
||||||
|
@ -131,15 +303,15 @@ impl PaintTimeMetrics {
|
||||||
&DisplayItem::Image(_) => {
|
&DisplayItem::Image(_) => {
|
||||||
is_contentful = true;
|
is_contentful = true;
|
||||||
break;
|
break;
|
||||||
},
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.pending_metrics.borrow_mut().insert(
|
self.pending_metrics.borrow_mut().insert(epoch, (
|
||||||
epoch,
|
profiler_metadata_factory.new_metadata(),
|
||||||
(profiler_metadata_factory.new_metadata(), is_contentful)
|
is_contentful,
|
||||||
);
|
));
|
||||||
|
|
||||||
// Send the pending metric information to the compositor thread.
|
// Send the pending metric information to the compositor thread.
|
||||||
// The compositor will record the current time after painting the
|
// The compositor will record the current time after painting the
|
||||||
|
@ -150,9 +322,9 @@ impl PaintTimeMetrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_set_metric(&mut 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.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;
|
||||||
|
@ -160,16 +332,26 @@ impl PaintTimeMetrics {
|
||||||
|
|
||||||
if let Some(pending_metric) = self.pending_metrics.borrow_mut().remove(&epoch) {
|
if let Some(pending_metric) = self.pending_metrics.borrow_mut().remove(&epoch) {
|
||||||
let profiler_metadata = pending_metric.0;
|
let profiler_metadata = pending_metric.0;
|
||||||
self.set_first_paint(profiler_metadata.clone(), paint_time);
|
set_metric(
|
||||||
|
self,
|
||||||
|
profiler_metadata.clone(),
|
||||||
|
ProgressiveWebMetricType::FirstPaint,
|
||||||
|
ProfilerCategory::TimeToFirstPaint,
|
||||||
|
&self.first_paint,
|
||||||
|
Some(paint_time),
|
||||||
|
);
|
||||||
|
|
||||||
if pending_metric.1 {
|
if pending_metric.1 {
|
||||||
self.set_first_contentful_paint(profiler_metadata, paint_time);
|
set_metric(
|
||||||
|
self,
|
||||||
|
profiler_metadata,
|
||||||
|
ProgressiveWebMetricType::FirstContentfulPaint,
|
||||||
|
ProfilerCategory::TimeToFirstContentfulPaint,
|
||||||
|
&self.first_contentful_paint,
|
||||||
|
Some(paint_time),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_navigation_start(&self) -> Option<f64> {
|
|
||||||
self.navigation_start
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_first_paint(&self) -> Option<f64> {
|
pub fn get_first_paint(&self) -> Option<f64> {
|
||||||
|
@ -180,3 +362,24 @@ impl PaintTimeMetrics {
|
||||||
self.first_contentful_paint.get()
|
self.first_contentful_paint.get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ProgressiveWebMetric for PaintTimeMetrics {
|
||||||
|
fn get_navigation_start(&self) -> Option<f64> {
|
||||||
|
self.navigation_start
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_navigation_start(&mut self, time: f64) {
|
||||||
|
self.navigation_start = Some(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_queued_constellation_msg(&self, name: ProgressiveWebMetricType, time: f64) {
|
||||||
|
let msg = ConstellationControlMsg::PaintMetric(self.pipeline_id, name, time);
|
||||||
|
if let Err(e) = self.script_chan.send(msg) {
|
||||||
|
warn!("Sending metric to script thread failed ({}).", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_time_profiler_chan(&self) -> &ProfilerChan {
|
||||||
|
&self.time_profiler_chan
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -157,6 +157,7 @@ impl Formattable for ProfilerCategory {
|
||||||
ProfilerCategory::ScriptPerformanceEvent => "Script Performance Event",
|
ProfilerCategory::ScriptPerformanceEvent => "Script Performance Event",
|
||||||
ProfilerCategory::TimeToFirstPaint => "Time To First Paint",
|
ProfilerCategory::TimeToFirstPaint => "Time To First Paint",
|
||||||
ProfilerCategory::TimeToFirstContentfulPaint => "Time To First Contentful Paint",
|
ProfilerCategory::TimeToFirstContentfulPaint => "Time To First Contentful Paint",
|
||||||
|
ProfilerCategory::TimeToInteractive => "Time to Interactive",
|
||||||
ProfilerCategory::ApplicationHeartbeat => "Application Heartbeat",
|
ProfilerCategory::ApplicationHeartbeat => "Application Heartbeat",
|
||||||
};
|
};
|
||||||
format!("{}{}", padding, name)
|
format!("{}{}", padding, name)
|
||||||
|
|
|
@ -12,8 +12,8 @@ use signpost;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
pub struct TimerMetadata {
|
pub struct TimerMetadata {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub iframe: TimerMetadataFrameType,
|
pub iframe: TimerMetadataFrameType,
|
||||||
pub incremental: TimerMetadataReflowType,
|
pub incremental: TimerMetadataReflowType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ pub enum ProfilerCategory {
|
||||||
ScriptPerformanceEvent = 0x7b,
|
ScriptPerformanceEvent = 0x7b,
|
||||||
TimeToFirstPaint = 0x80,
|
TimeToFirstPaint = 0x80,
|
||||||
TimeToFirstContentfulPaint = 0x81,
|
TimeToFirstContentfulPaint = 0x81,
|
||||||
|
TimeToInteractive = 0x82,
|
||||||
ApplicationHeartbeat = 0x90,
|
ApplicationHeartbeat = 0x90,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ pub fn profile<T, F>(category: ProfilerCategory,
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
callback: F)
|
callback: F)
|
||||||
-> T
|
-> T
|
||||||
where F: FnOnce() -> T
|
where F: FnOnce() -> T,
|
||||||
{
|
{
|
||||||
if opts::get().signpost {
|
if opts::get().signpost {
|
||||||
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
|
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
|
||||||
|
|
|
@ -61,6 +61,7 @@ use js::glue::{CallObjectTracer, CallValueTracer};
|
||||||
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
|
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
|
||||||
use js::jsval::JSVal;
|
use js::jsval::JSVal;
|
||||||
use js::rust::Runtime;
|
use js::rust::Runtime;
|
||||||
|
use metrics::{InteractiveMetrics, InteractiveWindow};
|
||||||
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, TopLevelBrowsingContextId};
|
use msg::constellation_msg::{BrowsingContextId, FrameType, PipelineId, TopLevelBrowsingContextId};
|
||||||
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads};
|
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceThreads};
|
||||||
use net_traits::filemanager_thread::RelativePos;
|
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>
|
unsafe impl<K, V, S> JSTraceable for HashMap<K, V, S>
|
||||||
where K: Hash + Eq + JSTraceable,
|
where K: Hash + Eq + JSTraceable,
|
||||||
V: JSTraceable,
|
V: JSTraceable,
|
||||||
S: BuildHasher
|
S: BuildHasher,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
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>
|
unsafe impl<T, S> JSTraceable for HashSet<T, S>
|
||||||
where T: Hash + Eq + JSTraceable,
|
where T: Hash + Eq + JSTraceable,
|
||||||
S: BuildHasher
|
S: BuildHasher,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn trace(&self, trc: *mut JSTracer) {
|
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!(MediaList);
|
||||||
unsafe_no_jsmanaged_fields!(WebVRGamepadHand);
|
unsafe_no_jsmanaged_fields!(WebVRGamepadHand);
|
||||||
unsafe_no_jsmanaged_fields!(ScriptToConstellationChan);
|
unsafe_no_jsmanaged_fields!(ScriptToConstellationChan);
|
||||||
|
unsafe_no_jsmanaged_fields!(InteractiveMetrics);
|
||||||
|
unsafe_no_jsmanaged_fields!(InteractiveWindow);
|
||||||
|
|
||||||
unsafe impl<'a> JSTraceable for &'a str {
|
unsafe impl<'a> JSTraceable for &'a str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -195,7 +195,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
println!("error loading script {}", serialized_worker_url);
|
println!("error loading script {}", serialized_worker_url);
|
||||||
parent_sender.send(CommonScriptMsg::Task(
|
parent_sender.send(CommonScriptMsg::Task(
|
||||||
WorkerEvent,
|
WorkerEvent,
|
||||||
Box::new(SimpleWorkerErrorHandler::new(worker))
|
Box::new(SimpleWorkerErrorHandler::new(worker)),
|
||||||
|
pipeline_id
|
||||||
)).unwrap();
|
)).unwrap();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -357,6 +358,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 = 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();
|
||||||
|
@ -382,7 +384,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
// TODO: Should use the DOM manipulation task source.
|
// 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 {
|
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 = 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);
|
||||||
}));
|
}));
|
||||||
self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task)).unwrap();
|
self.parent_sender.send(CommonScriptMsg::Task(WorkerEvent, task, Some(pipeline_id))).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,6 +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};
|
||||||
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};
|
||||||
|
@ -108,6 +109,7 @@ use net_traits::pub_domains::is_pub_domain;
|
||||||
use net_traits::request::RequestInit;
|
use net_traits::request::RequestInit;
|
||||||
use net_traits::response::HttpsState;
|
use net_traits::response::HttpsState;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
use profile_traits::time::{TimerMetadata, TimerMetadataFrameType, TimerMetadataReflowType};
|
||||||
use script_layout_interface::message::{Msg, NodesFromPointQueryType, ReflowGoal};
|
use script_layout_interface::message::{Msg, NodesFromPointQueryType, ReflowGoal};
|
||||||
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
|
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
|
||||||
use script_thread::{MainThreadScriptMsg, ScriptThread};
|
use script_thread::{MainThreadScriptMsg, ScriptThread};
|
||||||
|
@ -360,6 +362,8 @@ pub struct Document {
|
||||||
/// is inserted or removed from the document.
|
/// is inserted or removed from the document.
|
||||||
/// See https://html.spec.whatwg.org/multipage/#form-owner
|
/// See https://html.spec.whatwg.org/multipage/#form-owner
|
||||||
form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
|
form_id_listener_map: DomRefCell<HashMap<Atom, HashSet<Dom<Element>>>>,
|
||||||
|
interactive_time: DomRefCell<InteractiveMetrics>,
|
||||||
|
tti_window: DomRefCell<InteractiveWindow>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
@ -1834,6 +1838,9 @@ impl Document {
|
||||||
window.reflow(ReflowGoal::Full, ReflowReason::DOMContentLoaded);
|
window.reflow(ReflowGoal::Full, ReflowReason::DOMContentLoaded);
|
||||||
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
|
||||||
|
self.interactive_time.borrow().maybe_set_tti(self, InteractiveFlag::DOMContentLoaded);
|
||||||
|
|
||||||
// Step 4.2.
|
// Step 4.2.
|
||||||
// TODO: client message queue.
|
// TODO: client message queue.
|
||||||
}
|
}
|
||||||
|
@ -1916,6 +1923,14 @@ impl Document {
|
||||||
self.dom_interactive.get()
|
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 {
|
pub fn get_dom_content_loaded_event_start(&self) -> u64 {
|
||||||
self.dom_content_loaded_event_start.get()
|
self.dom_content_loaded_event_start.get()
|
||||||
}
|
}
|
||||||
|
@ -1936,6 +1951,22 @@ impl Document {
|
||||||
self.load_event_end.get()
|
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
|
// 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>) {
|
fn fire_focus_event(&self, focus_event_type: FocusEventType, node: &Node, related_target: Option<&EventTarget>) {
|
||||||
let (event_name, does_bubble) = match focus_event_type {
|
let (event_name, does_bubble) = match focus_event_type {
|
||||||
|
@ -2145,6 +2176,8 @@ impl Document {
|
||||||
(DocumentReadyState::Complete, true)
|
(DocumentReadyState::Complete, true)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let interactive_time = InteractiveMetrics::new(window.time_profiler_chan().clone());
|
||||||
|
|
||||||
Document {
|
Document {
|
||||||
node: Node::new_document_node(),
|
node: Node::new_document_node(),
|
||||||
window: Dom::from_ref(window),
|
window: Dom::from_ref(window),
|
||||||
|
@ -2236,6 +2269,8 @@ impl Document {
|
||||||
dom_count: Cell::new(1),
|
dom_count: Cell::new(1),
|
||||||
fullscreen_element: MutNullableDom::new(None),
|
fullscreen_element: MutNullableDom::new(None),
|
||||||
form_id_listener_map: Default::default(),
|
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);
|
self.send_to_constellation(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pipeline_id = self.window().pipeline_id();
|
||||||
|
|
||||||
// Step 7
|
// Step 7
|
||||||
let trusted_pending = Trusted::new(pending);
|
let trusted_pending = Trusted::new(pending);
|
||||||
let trusted_promise = TrustedPromise::new(promise.clone());
|
let trusted_promise = TrustedPromise::new(promise.clone());
|
||||||
let handler = ElementPerformFullscreenEnter::new(trusted_pending, trusted_promise, error);
|
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);
|
let msg = MainThreadScriptMsg::Common(script_msg);
|
||||||
window.main_thread_script_chan().send(msg).unwrap();
|
window.main_thread_script_chan().send(msg).unwrap();
|
||||||
|
|
||||||
|
@ -2615,7 +2652,8 @@ impl Document {
|
||||||
let trusted_element = Trusted::new(element.r());
|
let trusted_element = Trusted::new(element.r());
|
||||||
let trusted_promise = TrustedPromise::new(promise.clone());
|
let trusted_promise = TrustedPromise::new(promise.clone());
|
||||||
let handler = ElementPerformFullscreenExit::new(trusted_element, trusted_promise);
|
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);
|
let msg = MainThreadScriptMsg::Common(script_msg);
|
||||||
window.main_thread_script_chan().send(msg).unwrap();
|
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 {
|
impl DocumentMethods for Document {
|
||||||
// https://drafts.csswg.org/cssom/#dom-document-stylesheets
|
// https://drafts.csswg.org/cssom/#dom-document-stylesheets
|
||||||
fn StyleSheets(&self) -> DomRoot<StyleSheetList> {
|
fn StyleSheets(&self) -> DomRoot<StyleSheetList> {
|
||||||
|
|
|
@ -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::PaintMetricType;
|
use script_traits::ProgressiveWebMetricType;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct PerformancePaintTiming {
|
pub struct PerformancePaintTiming {
|
||||||
|
@ -17,11 +17,11 @@ pub struct PerformancePaintTiming {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PerformancePaintTiming {
|
impl PerformancePaintTiming {
|
||||||
fn new_inherited(metric_type: PaintMetricType, start_time: f64)
|
fn new_inherited(metric_type: ProgressiveWebMetricType, start_time: f64) -> PerformancePaintTiming {
|
||||||
-> PerformancePaintTiming {
|
|
||||||
let name = match metric_type {
|
let name = match metric_type {
|
||||||
PaintMetricType::FirstPaint => DOMString::from("first-paint"),
|
ProgressiveWebMetricType::FirstPaint => DOMString::from("first-paint"),
|
||||||
PaintMetricType::FirstContentfulPaint => DOMString::from("first-contentful-paint"),
|
ProgressiveWebMetricType::FirstContentfulPaint => DOMString::from("first-contentful-paint"),
|
||||||
|
_ => DOMString::from(""),
|
||||||
};
|
};
|
||||||
PerformancePaintTiming {
|
PerformancePaintTiming {
|
||||||
entry: PerformanceEntry::new_inherited(name,
|
entry: PerformanceEntry::new_inherited(name,
|
||||||
|
@ -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: PaintMetricType,
|
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)
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -515,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)).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());
|
||||||
|
|
|
@ -262,9 +262,10 @@ impl WebSocket {
|
||||||
address: address,
|
address: address,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let pipeline_id = self.global().pipeline_id();
|
||||||
self.global()
|
self.global()
|
||||||
.script_chan()
|
.script_chan()
|
||||||
.send(CommonScriptMsg::Task(WebSocketEvent, task))
|
.send(CommonScriptMsg::Task(WebSocketEvent, task, Some(pipeline_id)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
pub fn origin(&self) -> &MutableOrigin {
|
||||||
self.globalscope.origin()
|
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.
|
/// Cancels all the tasks associated with that window.
|
||||||
///
|
///
|
||||||
/// This sets the current `ignore_further_async_events` sentinel value to
|
/// This sets the current `ignore_further_async_events` sentinel value to
|
||||||
|
@ -1854,6 +1863,10 @@ impl Window {
|
||||||
WindowBinding::Wrap(runtime.cx(), win)
|
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 {
|
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(
|
let _ = self.script_chan.send(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::DomEvent,
|
ScriptThreadEventCategory::DomEvent,
|
||||||
Box::new(self.task_canceller().wrap_task(task)),
|
Box::new(self.task_canceller().wrap_task(task)),
|
||||||
|
self.pipeline_id()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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};
|
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit};
|
||||||
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 {
|
||||||
|
@ -363,15 +368,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>) {
|
||||||
|
@ -385,7 +390,7 @@ impl WorkerGlobalScope {
|
||||||
|
|
||||||
pub fn process_event(&self, msg: CommonScriptMsg) {
|
pub fn process_event(&self, msg: CommonScriptMsg) {
|
||||||
match msg {
|
match msg {
|
||||||
CommonScriptMsg::Task(_, task) => {
|
CommonScriptMsg::Task(_, task, _) => {
|
||||||
task.run_box()
|
task.run_box()
|
||||||
},
|
},
|
||||||
CommonScriptMsg::CollectReports(reports_chan) => {
|
CommonScriptMsg::CollectReports(reports_chan) => {
|
||||||
|
|
|
@ -644,7 +644,7 @@ impl WorkletThread {
|
||||||
where
|
where
|
||||||
T: TaskBox + 'static,
|
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);
|
let msg = MainThreadScriptMsg::Common(msg);
|
||||||
self.global_init.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
|
self.global_init.to_script_thread_sender.send(msg).expect("Worklet thread outlived script thread.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1286,7 +1286,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)
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,6 +22,7 @@ use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqu
|
||||||
use js::panic::wrap_panic;
|
use js::panic::wrap_panic;
|
||||||
use js::rust::Runtime as RustRuntime;
|
use js::rust::Runtime as RustRuntime;
|
||||||
use microtask::{EnqueuedPromiseCallback, Microtask};
|
use microtask::{EnqueuedPromiseCallback, Microtask};
|
||||||
|
use msg::constellation_msg::PipelineId;
|
||||||
use profile_traits::mem::{Report, ReportKind, ReportsChan};
|
use profile_traits::mem::{Report, ReportKind, ReportsChan};
|
||||||
use script_thread::trace_thread;
|
use script_thread::trace_thread;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
|
@ -44,14 +45,14 @@ pub enum CommonScriptMsg {
|
||||||
/// supplied channel.
|
/// supplied channel.
|
||||||
CollectReports(ReportsChan),
|
CollectReports(ReportsChan),
|
||||||
/// Generic message that encapsulates event handling.
|
/// Generic message that encapsulates event handling.
|
||||||
Task(ScriptThreadEventCategory, Box<TaskBox>),
|
Task(ScriptThreadEventCategory, Box<TaskBox>, Option<PipelineId>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for CommonScriptMsg {
|
impl fmt::Debug for CommonScriptMsg {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"),
|
CommonScriptMsg::CollectReports(_) => write!(f, "CollectReports(...)"),
|
||||||
CommonScriptMsg::Task(ref category, ref task) => {
|
CommonScriptMsg::Task(ref category, ref task, _) => {
|
||||||
f.debug_tuple("Task").field(category).field(task).finish()
|
f.debug_tuple("Task").field(category).field(task).finish()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,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::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};
|
||||||
|
@ -91,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::{PaintMetricType, 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};
|
||||||
|
@ -345,6 +345,10 @@ impl Documents {
|
||||||
self.map.get(&pipeline_id).map(|doc| DomRoot::from_ref(&**doc))
|
self.map.get(&pipeline_id).map(|doc| DomRoot::from_ref(&**doc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.map.len()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_window(&self, pipeline_id: PipelineId) -> Option<DomRoot<Window>> {
|
pub fn find_window(&self, pipeline_id: PipelineId) -> Option<DomRoot<Window>> {
|
||||||
self.find_document(pipeline_id).map(|doc| DomRoot::from_ref(doc.window()))
|
self.find_document(pipeline_id).map(|doc| DomRoot::from_ref(doc.window()))
|
||||||
}
|
}
|
||||||
|
@ -410,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>,
|
||||||
|
@ -681,7 +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 };
|
||||||
script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, || {
|
let pipeline_id = Some(new_layout_info.new_pipeline_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);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -727,8 +732,8 @@ impl ScriptThread {
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
name: Atom,
|
name: Atom,
|
||||||
properties: Vec<Atom>,
|
properties: Vec<Atom>,
|
||||||
painter: Box<Painter>,
|
painter: Box<Painter>)
|
||||||
) {
|
{
|
||||||
let window = self.documents.borrow().find_window(pipeline_id);
|
let window = self.documents.borrow().find_window(pipeline_id);
|
||||||
let window = match window {
|
let window = match window {
|
||||||
Some(window) => window,
|
Some(window) => window,
|
||||||
|
@ -830,17 +835,18 @@ 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,
|
||||||
script_sender: state.script_to_constellation_chan.sender.clone(),
|
script_sender: state.script_to_constellation_chan.sender.clone(),
|
||||||
time_profiler_chan: state.time_profiler_chan,
|
time_profiler_chan: state.time_profiler_chan.clone(),
|
||||||
mem_profiler_chan: state.mem_profiler_chan,
|
mem_profiler_chan: state.mem_profiler_chan,
|
||||||
|
|
||||||
devtools_chan: state.devtools_chan,
|
devtools_chan: state.devtools_chan,
|
||||||
|
@ -964,7 +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)) => {
|
||||||
self.profile_event(ScriptThreadEventCategory::AttachLayout, || {
|
let pipeline_id = new_layout_info.new_pipeline_id;
|
||||||
|
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" {
|
||||||
|
@ -986,17 +993,17 @@ impl ScriptThread {
|
||||||
}
|
}
|
||||||
FromConstellation(ConstellationControlMsg::Resize(id, size, size_type)) => {
|
FromConstellation(ConstellationControlMsg::Resize(id, size, size_type)) => {
|
||||||
// step 7.7
|
// step 7.7
|
||||||
self.profile_event(ScriptThreadEventCategory::Resize, || {
|
self.profile_event(ScriptThreadEventCategory::Resize, Some(id), || {
|
||||||
self.handle_resize(id, size, size_type);
|
self.handle_resize(id, size, size_type);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
FromConstellation(ConstellationControlMsg::Viewport(id, rect)) => {
|
FromConstellation(ConstellationControlMsg::Viewport(id, rect)) => {
|
||||||
self.profile_event(ScriptThreadEventCategory::SetViewport, || {
|
self.profile_event(ScriptThreadEventCategory::SetViewport, Some(id), || {
|
||||||
self.handle_viewport(id, rect);
|
self.handle_viewport(id, rect);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
FromConstellation(ConstellationControlMsg::SetScrollState(id, scroll_state)) => {
|
FromConstellation(ConstellationControlMsg::SetScrollState(id, scroll_state)) => {
|
||||||
self.profile_event(ScriptThreadEventCategory::SetScrollState, || {
|
self.profile_event(ScriptThreadEventCategory::SetScrollState, Some(id), || {
|
||||||
self.handle_set_scroll_state(id, &scroll_state);
|
self.handle_set_scroll_state(id, &scroll_state);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1051,9 +1058,11 @@ impl ScriptThread {
|
||||||
debug!("Processing events.");
|
debug!("Processing events.");
|
||||||
for msg in sequential {
|
for msg in sequential {
|
||||||
debug!("Processing event {:?}.", msg);
|
debug!("Processing event {:?}.", msg);
|
||||||
let category = self.categorize_msg(&msg);
|
|
||||||
|
|
||||||
let result = self.profile_event(category, move || {
|
let category = self.categorize_msg(&msg);
|
||||||
|
let pipeline_id = self.message_to_pipeline(&msg);
|
||||||
|
|
||||||
|
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();
|
||||||
|
@ -1118,11 +1127,12 @@ 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) => {
|
||||||
match *inner_msg {
|
match *inner_msg {
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::Task(category, _)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::Task(category, ..)) => {
|
||||||
category
|
category
|
||||||
},
|
},
|
||||||
MainThreadScriptMsg::RegisterPaintWorklet { .. } => {
|
MainThreadScriptMsg::RegisterPaintWorklet { .. } => {
|
||||||
|
@ -1135,9 +1145,70 @@ impl ScriptThread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn profile_event<F, R>(&self, category: ScriptThreadEventCategory, f: F) -> R
|
fn message_to_pipeline(&self, msg: &MixedMessage) -> Option<PipelineId> {
|
||||||
|
use script_traits::ConstellationControlMsg::*;
|
||||||
|
match *msg {
|
||||||
|
MixedMessage::FromConstellation(ref inner_msg) => {
|
||||||
|
match *inner_msg {
|
||||||
|
NavigationResponse(id, _) => Some(id),
|
||||||
|
AttachLayout(ref new_layout_info) => Some(new_layout_info.new_pipeline_id),
|
||||||
|
Resize(id, ..) => Some(id),
|
||||||
|
ResizeInactive(id, ..) => Some(id),
|
||||||
|
ExitPipeline(id, ..) => Some(id),
|
||||||
|
ExitScriptThread => None,
|
||||||
|
SendEvent(id, ..) => Some(id),
|
||||||
|
Viewport(id, ..) => Some(id),
|
||||||
|
SetScrollState(id, ..) => Some(id),
|
||||||
|
GetTitle(id) => Some(id),
|
||||||
|
SetDocumentActivity(id, ..) => Some(id),
|
||||||
|
ChangeFrameVisibilityStatus(id, ..) => Some(id),
|
||||||
|
NotifyVisibilityChange(id, ..) => Some(id),
|
||||||
|
Navigate(id, ..) => Some(id),
|
||||||
|
PostMessage(id, ..) => Some(id),
|
||||||
|
MozBrowserEvent(id, ..) => Some(id),
|
||||||
|
UpdatePipelineId(_, _, id, _) => Some(id),
|
||||||
|
FocusIFrame(id, ..) => Some(id),
|
||||||
|
WebDriverScriptCommand(id, ..) => Some(id),
|
||||||
|
TickAllAnimations(id) => Some(id),
|
||||||
|
// FIXME https://github.com/servo/servo/issues/15079
|
||||||
|
TransitionEnd(..) => None,
|
||||||
|
WebFontLoaded(id) => Some(id),
|
||||||
|
DispatchIFrameLoadEvent { target: _, parent: id, child: _ } => Some(id),
|
||||||
|
DispatchStorageEvent(id, ..) => Some(id),
|
||||||
|
ReportCSSError(id, ..) => Some(id),
|
||||||
|
Reload(id, ..) => Some(id),
|
||||||
|
WebVREvents(id, ..) => Some(id),
|
||||||
|
PaintMetric(..) => None,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MixedMessage::FromDevtools(_) => None,
|
||||||
|
MixedMessage::FromScript(ref inner_msg) => {
|
||||||
|
match *inner_msg {
|
||||||
|
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, _, pipeline_id)) =>
|
||||||
|
pipeline_id,
|
||||||
|
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(_)) => None,
|
||||||
|
MainThreadScriptMsg::ExitWindow(pipeline_id) => Some(pipeline_id),
|
||||||
|
MainThreadScriptMsg::Navigate(pipeline_id, ..) => Some(pipeline_id),
|
||||||
|
MainThreadScriptMsg::WorkletLoaded(pipeline_id) => Some(pipeline_id),
|
||||||
|
MainThreadScriptMsg::RegisterPaintWorklet { pipeline_id, .. } => Some(pipeline_id),
|
||||||
|
MainThreadScriptMsg::DispatchJobQueue { .. } => None,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MixedMessage::FromImageCache((pipeline_id, _)) => Some(pipeline_id),
|
||||||
|
MixedMessage::FromScheduler(ref timer_event) => {
|
||||||
|
let TimerEvent(source, _) = *timer_event;
|
||||||
|
match source {
|
||||||
|
TimerSource::FromWindow(pipeline_id) => Some(pipeline_id),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
@ -1172,7 +1243,17 @@ impl ScriptThread {
|
||||||
profile(profiler_cat, None, self.time_profiler_chan.clone(), f)
|
profile(profiler_cat, None, self.time_profiler_chan.clone(), f)
|
||||||
} 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) {
|
||||||
|
@ -1257,7 +1338,7 @@ impl ScriptThread {
|
||||||
MainThreadScriptMsg::ExitWindow(id) => {
|
MainThreadScriptMsg::ExitWindow(id) => {
|
||||||
self.handle_exit_window_msg(id)
|
self.handle_exit_window_msg(id)
|
||||||
},
|
},
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, task)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, task, _)) => {
|
||||||
task.run_box()
|
task.run_box()
|
||||||
}
|
}
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => {
|
||||||
|
@ -1725,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.
|
||||||
|
@ -2018,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();
|
||||||
|
@ -2041,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(),
|
||||||
|
@ -2563,7 +2654,7 @@ impl ScriptThread {
|
||||||
|
|
||||||
fn handle_paint_metric(&self,
|
fn handle_paint_metric(&self,
|
||||||
pipeline_id: PipelineId,
|
pipeline_id: PipelineId,
|
||||||
metric_type: PaintMetricType,
|
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 {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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,6 +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)),
|
||||||
|
Some(self.1)
|
||||||
));
|
));
|
||||||
self.0.send(msg).map_err(|_| ())
|
self.0.send(msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,6 +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)),
|
||||||
|
Some(self.1),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,6 +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)),
|
||||||
|
Some(self.1),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +43,7 @@ impl NetworkingTaskSource {
|
||||||
self.0.send(CommonScriptMsg::Task(
|
self.0.send(CommonScriptMsg::Task(
|
||||||
ScriptThreadEventCategory::NetworkEvent,
|
ScriptThreadEventCategory::NetworkEvent,
|
||||||
Box::new(task),
|
Box::new(task),
|
||||||
|
Some(self.1),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ 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)),
|
||||||
|
Some(self.1)
|
||||||
);
|
);
|
||||||
self.0.send(msg).map_err(|_| ())
|
self.0.send(msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,6 +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)),
|
||||||
|
Some(self.1)
|
||||||
));
|
));
|
||||||
self.0.send(msg).map_err(|_| ())
|
self.0.send(msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,13 +231,15 @@ pub enum DocumentActivity {
|
||||||
FullyActive,
|
FullyActive,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type of recorded paint metric.
|
/// Type of recorded progressive web metric
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
pub enum PaintMetricType {
|
pub enum ProgressiveWebMetricType {
|
||||||
/// Time to First Paint type.
|
/// Time to first Paint
|
||||||
FirstPaint,
|
FirstPaint,
|
||||||
/// Time to First Contentful Paint type.
|
/// Time to first contentful paint
|
||||||
FirstContentfulPaint,
|
FirstContentfulPaint,
|
||||||
|
/// Time to interactive
|
||||||
|
TimeToInteractive,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The reason why the pipeline id of an iframe is being updated.
|
/// The reason why the pipeline id of an iframe is being updated.
|
||||||
|
@ -322,7 +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, PaintMetricType, f64),
|
PaintMetric(PipelineId, ProgressiveWebMetricType, f64),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ConstellationControlMsg {
|
impl fmt::Debug for ConstellationControlMsg {
|
||||||
|
|
112
tests/unit/metrics/interactive_time.rs
Normal file
112
tests/unit/metrics/interactive_time.rs
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
/* 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 ipc_channel::ipc;
|
||||||
|
use metrics::{InteractiveMetrics, InteractiveFlag, InteractiveWindow};
|
||||||
|
use metrics::{ProfilerMetadataFactory, ProgressiveWebMetric};
|
||||||
|
use profile_traits::time::{ProfilerChan, TimerMetadata};
|
||||||
|
use time;
|
||||||
|
|
||||||
|
struct DummyProfilerMetadataFactory {}
|
||||||
|
impl ProfilerMetadataFactory for DummyProfilerMetadataFactory {
|
||||||
|
fn new_metadata(&self) -> Option<TimerMetadata> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn test_interactive() -> InteractiveMetrics {
|
||||||
|
let (sender, _) = ipc::channel().unwrap();
|
||||||
|
let profiler_chan = ProfilerChan(sender);
|
||||||
|
let mut interactive = InteractiveMetrics::new(profiler_chan);
|
||||||
|
|
||||||
|
assert_eq!((&interactive).get_navigation_start(), None);
|
||||||
|
assert_eq!(interactive.get_tti(), None);
|
||||||
|
|
||||||
|
interactive.set_navigation_start(time::precise_time_ns() as f64);
|
||||||
|
|
||||||
|
interactive
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_dcl() {
|
||||||
|
let profiler_metadata_factory = DummyProfilerMetadataFactory {};
|
||||||
|
|
||||||
|
let interactive = test_interactive();
|
||||||
|
interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
|
||||||
|
let dcl = interactive.get_dom_content_loaded();
|
||||||
|
assert!(dcl.is_some());
|
||||||
|
|
||||||
|
//try to overwrite
|
||||||
|
interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
|
||||||
|
assert_eq!(interactive.get_dom_content_loaded(), dcl);
|
||||||
|
assert_eq!(interactive.get_tti(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_mta() {
|
||||||
|
let profiler_metadata_factory = DummyProfilerMetadataFactory {};
|
||||||
|
|
||||||
|
let interactive = test_interactive();
|
||||||
|
let t = time::precise_time_ns();
|
||||||
|
interactive.maybe_set_tti(
|
||||||
|
&profiler_metadata_factory,
|
||||||
|
InteractiveFlag::TimeToInteractive(t as f64),
|
||||||
|
);
|
||||||
|
let mta = interactive.get_main_thread_available();
|
||||||
|
assert!(mta.is_some());
|
||||||
|
assert_eq!(mta, Some(t as f64));
|
||||||
|
|
||||||
|
//try to overwrite
|
||||||
|
interactive.maybe_set_tti(
|
||||||
|
&profiler_metadata_factory,
|
||||||
|
InteractiveFlag::TimeToInteractive(time::precise_time_ns() as f64),
|
||||||
|
);
|
||||||
|
assert_eq!(interactive.get_main_thread_available(), mta);
|
||||||
|
assert_eq!(interactive.get_tti(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_tti_dcl() {
|
||||||
|
let profiler_metadata_factory = DummyProfilerMetadataFactory {};
|
||||||
|
|
||||||
|
let interactive = test_interactive();
|
||||||
|
let t = time::precise_time_ns();
|
||||||
|
interactive.maybe_set_tti(
|
||||||
|
&profiler_metadata_factory,
|
||||||
|
InteractiveFlag::TimeToInteractive(t as f64),
|
||||||
|
);
|
||||||
|
let mta = interactive.get_main_thread_available();
|
||||||
|
assert!(mta.is_some());
|
||||||
|
|
||||||
|
interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
|
||||||
|
let dcl = interactive.get_dom_content_loaded();
|
||||||
|
assert!(dcl.is_some());
|
||||||
|
|
||||||
|
let interactive_time = dcl.unwrap() - (&interactive).get_navigation_start().unwrap();
|
||||||
|
assert_eq!(interactive.get_tti(), Some(interactive_time));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_tti_mta() {
|
||||||
|
let profiler_metadata_factory = DummyProfilerMetadataFactory {};
|
||||||
|
|
||||||
|
let interactive = test_interactive();
|
||||||
|
interactive.maybe_set_tti(&profiler_metadata_factory, InteractiveFlag::DOMContentLoaded);
|
||||||
|
let dcl = interactive.get_dom_content_loaded();
|
||||||
|
assert!(dcl.is_some());
|
||||||
|
|
||||||
|
let t = time::precise_time_ns();
|
||||||
|
interactive.maybe_set_tti(
|
||||||
|
&profiler_metadata_factory,
|
||||||
|
InteractiveFlag::TimeToInteractive(t as f64),
|
||||||
|
);
|
||||||
|
let mta = interactive.get_main_thread_available();
|
||||||
|
assert!(mta.is_some());
|
||||||
|
|
||||||
|
let interactive_time = mta.unwrap() - (&interactive).get_navigation_start().unwrap();
|
||||||
|
assert_eq!(interactive.get_tti(), Some(interactive_time));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO InteractiveWindow tests
|
|
@ -13,5 +13,7 @@ extern crate profile_traits;
|
||||||
extern crate style;
|
extern crate style;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod interactive_time;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod paint_time;
|
mod paint_time;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use gfx::display_list::{BaseDisplayItem, WebRenderImageInfo};
|
||||||
use gfx::display_list::{DisplayItem, DisplayList, ImageDisplayItem};
|
use gfx::display_list::{DisplayItem, DisplayList, ImageDisplayItem};
|
||||||
use gfx_traits::Epoch;
|
use gfx_traits::Epoch;
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory, ProgressiveWebMetric};
|
||||||
use msg::constellation_msg::TEST_PIPELINE_ID;
|
use msg::constellation_msg::TEST_PIPELINE_ID;
|
||||||
use net_traits::image::base::PixelFormat;
|
use net_traits::image::base::PixelFormat;
|
||||||
use profile_traits::time::{ProfilerChan, TimerMetadata};
|
use profile_traits::time::{ProfilerChan, TimerMetadata};
|
||||||
|
@ -27,10 +27,27 @@ fn test_paint_metrics_construction() {
|
||||||
let profiler_chan = ProfilerChan(sender);
|
let profiler_chan = ProfilerChan(sender);
|
||||||
let (layout_sender, _) = ipc::channel().unwrap();
|
let (layout_sender, _) = ipc::channel().unwrap();
|
||||||
let (script_sender, _) = ipc::channel().unwrap();
|
let (script_sender, _) = ipc::channel().unwrap();
|
||||||
let paint_time_metrics = PaintTimeMetrics::new(TEST_PIPELINE_ID, profiler_chan, layout_sender, script_sender);
|
let paint_time_metrics = PaintTimeMetrics::new(
|
||||||
assert_eq!(paint_time_metrics.get_navigation_start(), None, "navigation start is None");
|
TEST_PIPELINE_ID,
|
||||||
assert_eq!(paint_time_metrics.get_first_paint(), None, "first paint is None");
|
profiler_chan,
|
||||||
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None");
|
layout_sender,
|
||||||
|
script_sender,
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
(&paint_time_metrics).get_navigation_start(),
|
||||||
|
None,
|
||||||
|
"navigation start is None"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
paint_time_metrics.get_first_paint(),
|
||||||
|
None,
|
||||||
|
"first paint is None"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
paint_time_metrics.get_first_contentful_paint(),
|
||||||
|
None,
|
||||||
|
"first contentful paint is None"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_common(display_list: &DisplayList, epoch: Epoch) -> PaintTimeMetrics {
|
fn test_common(display_list: &DisplayList, epoch: Epoch) -> PaintTimeMetrics {
|
||||||
|
@ -38,22 +55,40 @@ fn test_common(display_list: &DisplayList, epoch: Epoch) -> PaintTimeMetrics {
|
||||||
let profiler_chan = ProfilerChan(sender);
|
let profiler_chan = ProfilerChan(sender);
|
||||||
let (layout_sender, _) = ipc::channel().unwrap();
|
let (layout_sender, _) = ipc::channel().unwrap();
|
||||||
let (script_sender, _) = ipc::channel().unwrap();
|
let (script_sender, _) = ipc::channel().unwrap();
|
||||||
let mut paint_time_metrics = PaintTimeMetrics::new(TEST_PIPELINE_ID, profiler_chan, layout_sender, script_sender);
|
let mut paint_time_metrics = PaintTimeMetrics::new(
|
||||||
|
TEST_PIPELINE_ID,
|
||||||
|
profiler_chan,
|
||||||
|
layout_sender,
|
||||||
|
script_sender,
|
||||||
|
);
|
||||||
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {};
|
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {};
|
||||||
|
|
||||||
paint_time_metrics.maybe_observe_paint_time(&dummy_profiler_metadata_factory,
|
paint_time_metrics.maybe_observe_paint_time(
|
||||||
epoch,
|
&dummy_profiler_metadata_factory,
|
||||||
&display_list);
|
epoch,
|
||||||
|
&display_list,
|
||||||
|
);
|
||||||
|
|
||||||
// Should not set any metric until navigation start is set.
|
// Should not set any metric until navigation start is set.
|
||||||
paint_time_metrics.maybe_set_metric(epoch, 0.);
|
paint_time_metrics.maybe_set_metric(epoch, 0.);
|
||||||
assert_eq!(paint_time_metrics.get_first_paint(), None, "first paint is None");
|
assert_eq!(
|
||||||
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None");
|
paint_time_metrics.get_first_paint(),
|
||||||
|
None,
|
||||||
|
"first paint is None"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
paint_time_metrics.get_first_contentful_paint(),
|
||||||
|
None,
|
||||||
|
"first contentful paint is None"
|
||||||
|
);
|
||||||
|
|
||||||
let navigation_start = time::precise_time_ns() as f64;
|
let navigation_start = time::precise_time_ns() as f64;
|
||||||
paint_time_metrics.set_navigation_start(navigation_start);
|
paint_time_metrics.set_navigation_start(navigation_start);
|
||||||
assert_eq!(paint_time_metrics.get_navigation_start().unwrap(),
|
assert_eq!(
|
||||||
navigation_start, "navigation start is set");
|
(&paint_time_metrics).get_navigation_start().unwrap(),
|
||||||
|
navigation_start,
|
||||||
|
"navigation start is set"
|
||||||
|
);
|
||||||
|
|
||||||
paint_time_metrics
|
paint_time_metrics
|
||||||
}
|
}
|
||||||
|
@ -65,11 +100,18 @@ 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!(paint_time_metrics.get_first_paint().is_some(), "first paint is set");
|
assert!(
|
||||||
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None");
|
paint_time_metrics.get_first_paint().is_some(),
|
||||||
|
"first paint is set"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
paint_time_metrics.get_first_contentful_paint(),
|
||||||
|
None,
|
||||||
|
"first contentful paint is None"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -92,9 +134,15 @@ 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!(paint_time_metrics.get_first_contentful_paint().is_some(), "first contentful paint is set");
|
assert!(
|
||||||
assert!(paint_time_metrics.get_first_paint().is_some(), "first paint is set");
|
paint_time_metrics.get_first_contentful_paint().is_some(),
|
||||||
|
"first contentful paint is set"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
paint_time_metrics.get_first_paint().is_some(),
|
||||||
|
"first paint is set"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue