added time to interactive metrics, refactored metrics to use traits

changed task macro to take pipeline info
This commit is contained in:
ddh 2017-10-02 14:52:39 +01:00
parent 347176df25
commit 2ffbe53989
26 changed files with 730 additions and 138 deletions

View file

@ -7,7 +7,7 @@ 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 metrics::{PaintTimeMetrics, ProfilerMetadataFactory, ProgressiveWebMetric};
use msg::constellation_msg::TEST_PIPELINE_ID;
use net_traits::image::base::PixelFormat;
use profile_traits::time::{ProfilerChan, TimerMetadata};
@ -27,10 +27,27 @@ fn test_paint_metrics_construction() {
let profiler_chan = ProfilerChan(sender);
let (layout_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);
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");
let paint_time_metrics = PaintTimeMetrics::new(
TEST_PIPELINE_ID,
profiler_chan,
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 {
@ -38,22 +55,40 @@ fn test_common(display_list: &DisplayList, epoch: Epoch) -> PaintTimeMetrics {
let profiler_chan = ProfilerChan(sender);
let (layout_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 {};
paint_time_metrics.maybe_observe_paint_time(&dummy_profiler_metadata_factory,
epoch,
&display_list);
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_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");
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");
assert_eq!(
(&paint_time_metrics).get_navigation_start().unwrap(),
navigation_start,
"navigation start is set"
);
paint_time_metrics
}
@ -68,8 +103,15 @@ fn test_first_paint_setter() {
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");
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]
@ -95,6 +137,12 @@ fn test_first_contentful_paint_setter() {
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!(paint_time_metrics.get_first_paint().is_some(), "first paint is set");
assert!(
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"
);
}