Auto merge of #17876 - ferjm:pwm.webrender, r=jdm

Wait for actual paint before setting paint related metrics

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- 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/17876)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-22 10:06:30 -05:00 committed by GitHub
commit 43d1f45b73
16 changed files with 203 additions and 72 deletions

View file

@ -12,6 +12,7 @@ doctest = false
[dependencies]
euclid = "0.15"
gfx = {path = "../../../components/gfx"}
gfx_traits = {path = "../../../components/gfx_traits"}
ipc-channel = "0.8"
metrics = {path = "../../../components/metrics"}
msg = {path = "../../../components/msg"}

View file

@ -4,6 +4,7 @@
extern crate euclid;
extern crate gfx;
extern crate gfx_traits;
extern crate ipc_channel;
extern crate metrics;
extern crate msg;

View file

@ -5,6 +5,7 @@
use euclid::Size2D;
use gfx::display_list::{BaseDisplayItem, WebRenderImageInfo};
use gfx::display_list::{DisplayItem, DisplayList, ImageDisplayItem};
use gfx_traits::Epoch;
use ipc_channel::ipc;
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
@ -22,57 +23,62 @@ impl ProfilerMetadataFactory for DummyProfilerMetadataFactory {
#[test]
fn test_paint_metrics_construction() {
let pipeline_id = PipelineId {
namespace_id: PipelineNamespaceId(1),
index: PipelineIndex(1),
};
let (sender, _) = ipc::channel().unwrap();
let profiler_chan = ProfilerChan(sender);
let paint_time_metrics = PaintTimeMetrics::new(profiler_chan);
let (layout_sender, _) = ipc::channel().unwrap();
let paint_time_metrics = PaintTimeMetrics::new(pipeline_id, profiler_chan, layout_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");
}
#[test]
fn test_first_paint_setter() {
fn test_common(display_list: &DisplayList, epoch: Epoch) -> PaintTimeMetrics {
let pipeline_id = PipelineId {
namespace_id: PipelineNamespaceId(1),
index: PipelineIndex(1),
};
let (sender, _) = ipc::channel().unwrap();
let profiler_chan = ProfilerChan(sender);
let mut paint_time_metrics = PaintTimeMetrics::new(profiler_chan);
let (layout_sender, _) = ipc::channel().unwrap();
let mut paint_time_metrics = PaintTimeMetrics::new(pipeline_id, profiler_chan, layout_sender);
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {};
paint_time_metrics.maybe_observe_paint_time(&dummy_profiler_metadata_factory,
epoch,
&display_list);
// Should not set any metric until navigation start is set.
paint_time_metrics.maybe_set_first_paint(&dummy_profiler_metadata_factory);
paint_time_metrics.maybe_set_metric(epoch, 0.);
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");
let navigation_start = time::precise_time_ns() as f64;
paint_time_metrics.set_navigation_start(navigation_start);
assert_eq!(paint_time_metrics.get_navigation_start().unwrap(),
navigation_start, "navigation start is set");
paint_time_metrics.maybe_set_first_paint(&dummy_profiler_metadata_factory);
paint_time_metrics
}
#[test]
fn test_first_paint_setter() {
let empty_display_list = DisplayList {
list: Vec::new()
};
let epoch = Epoch(0);
let mut paint_time_metrics = test_common(&empty_display_list, epoch);
let now = time::precise_time_ns() as f64;
paint_time_metrics.maybe_set_metric(epoch, now);
assert!(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]
fn test_first_contentful_paint_setter() {
let (sender, _) = ipc::channel().unwrap();
let profiler_chan = ProfilerChan(sender);
let mut paint_time_metrics = PaintTimeMetrics::new(profiler_chan);
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {};
let empty_display_list = DisplayList {
list: Vec::new()
};
// Should not set any metric until navigation start is set.
paint_time_metrics.maybe_set_first_contentful_paint(&dummy_profiler_metadata_factory,
&empty_display_list);
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None");
// Should not set first contentful paint if no appropriate display item is present.
let navigation_start = time::precise_time_ns() as f64;
paint_time_metrics.set_navigation_start(navigation_start);
paint_time_metrics.maybe_set_first_contentful_paint(&dummy_profiler_metadata_factory,
&empty_display_list);
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None");
let pipeline_id = PipelineId {
namespace_id: PipelineNamespaceId(1),
index: PipelineIndex(1),
@ -93,8 +99,10 @@ fn test_first_contentful_paint_setter() {
let display_list = DisplayList {
list: vec![image]
};
paint_time_metrics.maybe_set_first_contentful_paint(&dummy_profiler_metadata_factory,
&display_list);
let epoch = Epoch(0);
let mut paint_time_metrics = test_common(&display_list, epoch);
let now = time::precise_time_ns() as f64;
paint_time_metrics.maybe_set_metric(epoch, now);
assert!(paint_time_metrics.get_first_contentful_paint().is_some(), "first contentful paint is set");
assert_eq!(paint_time_metrics.get_first_paint(), None, "first paint is None");
assert!(paint_time_metrics.get_first_paint().is_some(), "first paint is set");
}