Skip to content

Commit

Permalink
Implement basic Time To First Paint and First Contentful Paint PWMs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Jul 20, 2017
1 parent 20a3b02 commit 892b30e
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 10 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions components/config/opts.rs
Expand Up @@ -224,6 +224,9 @@ pub struct Opts {

/// Unminify Javascript.
pub unminify_js: bool,

/// Print Progressive Web Metrics to console.
pub print_pwm: bool,
}

fn print_usage(app: &str, opts: &Options) {
Expand Down Expand Up @@ -544,6 +547,7 @@ pub fn default_opts() -> Opts {
signpost: false,
certificate_path: None,
unminify_js: false,
print_pwm: false,
}
}

Expand Down Expand Up @@ -608,6 +612,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
opts.optopt("", "profiler-db-user", "Profiler database user", "");
opts.optopt("", "profiler-db-pass", "Profiler database password", "");
opts.optopt("", "profiler-db-name", "Profiler database name", "");
opts.optflag("", "print-pwm", "Print Progressive Web Metrics");

let opt_match = match opts.parse(args) {
Ok(m) => m,
Expand Down Expand Up @@ -843,6 +848,7 @@ pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
signpost: debug_options.signpost,
certificate_path: opt_match.opt_str("certificate-path"),
unminify_js: opt_match.opt_present("unminify-js"),
print_pwm: opt_match.opt_present("print-pwm"),
};

set_defaults(opts);
Expand Down
1 change: 1 addition & 0 deletions components/constellation/Cargo.toml
Expand Up @@ -26,6 +26,7 @@ ipc-channel = "0.8"
itertools = "0.5"
layout_traits = {path = "../layout_traits"}
log = "0.3.5"
metrics = {path = "../metrics"}
msg = {path = "../msg"}
net = {path = "../net"}
net_traits = {path = "../net_traits"}
Expand Down
1 change: 1 addition & 0 deletions components/constellation/lib.rs
Expand Up @@ -26,6 +26,7 @@ extern crate itertools;
extern crate layout_traits;
#[macro_use]
extern crate log;
extern crate metrics;
extern crate msg;
extern crate net;
extern crate net_traits;
Expand Down
7 changes: 5 additions & 2 deletions components/constellation/pipeline.rs
Expand Up @@ -14,6 +14,7 @@ use ipc_channel::Error;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout_traits::LayoutThreadFactory;
use metrics::PaintTimeMetrics;
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, FrameType, PipelineId, PipelineNamespaceId};
use net::image_cache::ImageCacheImpl;
use net_traits::{IpcSend, ResourceThreads};
Expand Down Expand Up @@ -471,6 +472,7 @@ impl UnprivilegedPipelineContent {
STF: ScriptThreadFactory<Message=Message>
{
let image_cache = Arc::new(ImageCacheImpl::new(self.webrender_api_sender.create_api()));
let paint_time_metrics = PaintTimeMetrics::new(self.time_profiler_chan.clone());
let layout_pair = STF::create(InitialScriptState {
id: self.id,
browsing_context_id: self.browsing_context_id,
Expand All @@ -490,7 +492,7 @@ impl UnprivilegedPipelineContent {
window_size: self.window_size,
pipeline_namespace_id: self.pipeline_namespace_id,
content_process_shutdown_chan: self.script_content_process_shutdown_chan,
webvr_thread: self.webvr_thread
webvr_thread: self.webvr_thread,
}, self.load_data.clone());

LTF::create(self.id,
Expand All @@ -508,7 +510,8 @@ impl UnprivilegedPipelineContent {
Some(self.layout_content_process_shutdown_chan),
self.webrender_api_sender,
self.prefs.get("layout.threads").expect("exists").value()
.as_u64().expect("count") as usize);
.as_u64().expect("count") as usize,
paint_time_metrics);

if wait_for_completion {
let _ = self.script_content_process_shutdown_port.recv();
Expand Down
1 change: 1 addition & 0 deletions components/layout_thread/Cargo.toml
Expand Up @@ -23,6 +23,7 @@ layout = {path = "../layout"}
layout_traits = {path = "../layout_traits"}
lazy_static = "0.2"
log = "0.3.5"
metrics = {path = "../metrics"}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
parking_lot = {version = "0.4", features = ["nightly"]}
Expand Down
36 changes: 30 additions & 6 deletions components/layout_thread/lib.rs
Expand Up @@ -27,6 +27,7 @@ extern crate layout_traits;
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate metrics;
extern crate msg;
extern crate net_traits;
extern crate parking_lot;
Expand Down Expand Up @@ -83,6 +84,7 @@ use layout::traversal::{ComputeAbsolutePositions, RecalcStyleAndConstructFlows};
use layout::webrender_helpers::WebRenderDisplayListConverter;
use layout::wrapper::LayoutNodeLayoutData;
use layout_traits::LayoutThreadFactory;
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
use msg::constellation_msg::PipelineId;
use msg::constellation_msg::TopLevelBrowsingContextId;
use net_traits::image_cache::{ImageCache, UsePlaceholder};
Expand Down Expand Up @@ -248,7 +250,10 @@ pub struct LayoutThread {
layout_threads: usize,

/// Which quirks mode are we rendering the document in?
quirks_mode: Option<QuirksMode>
quirks_mode: Option<QuirksMode>,

/// Paint time metrics.
paint_time_metrics: PaintTimeMetrics,
}

impl LayoutThreadFactory for LayoutThread {
Expand All @@ -269,7 +274,8 @@ impl LayoutThreadFactory for LayoutThread {
mem_profiler_chan: mem::ProfilerChan,
content_process_shutdown_chan: Option<IpcSender<()>>,
webrender_api_sender: webrender_api::RenderApiSender,
layout_threads: usize) {
layout_threads: usize,
paint_time_metrics: PaintTimeMetrics) {
thread::Builder::new().name(format!("LayoutThread {:?}", id)).spawn(move || {
thread_state::initialize(thread_state::LAYOUT);

Expand All @@ -291,7 +297,8 @@ impl LayoutThreadFactory for LayoutThread {
time_profiler_chan,
mem_profiler_chan.clone(),
webrender_api_sender,
layout_threads);
layout_threads,
paint_time_metrics);

let reporter_name = format!("layout-reporter-{}", id);
mem_profiler_chan.run_with_memory_reporting(|| {
Expand Down Expand Up @@ -452,7 +459,8 @@ impl LayoutThread {
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan,
webrender_api_sender: webrender_api::RenderApiSender,
layout_threads: usize)
layout_threads: usize,
paint_time_metrics: PaintTimeMetrics)
-> LayoutThread {
let device = Device::new(
MediaType::Screen,
Expand Down Expand Up @@ -551,6 +559,7 @@ impl LayoutThread {
},
layout_threads: layout_threads,
quirks_mode: None,
paint_time_metrics: paint_time_metrics,
}
}

Expand Down Expand Up @@ -733,7 +742,10 @@ impl LayoutThread {
debug!("layout: ExitNow received");
self.exit_now();
return false
}
},
Msg::SetNavigationStart(time) => {
self.paint_time_metrics.set_navigation_start(time);
},
}

true
Expand Down Expand Up @@ -785,7 +797,8 @@ impl LayoutThread {
self.mem_profiler_chan.clone(),
info.content_process_shutdown_chan,
self.webrender_api.clone_sender(),
info.layout_threads);
info.layout_threads,
info.paint_time_metrics);
}

/// Enters a quiescent state in which no new messages will be processed until an `ExitNow` is
Expand Down Expand Up @@ -1020,6 +1033,12 @@ impl LayoutThread {
self.epoch.set(epoch);

let viewport_size = webrender_api::LayoutSize::from_untyped(&viewport_size);

// Set paint metrics if needed right before sending the display list to WebRender.
// XXX At some point, we may want to set this metric from WebRender itself.
self.paint_time_metrics.maybe_set_first_paint(self);
self.paint_time_metrics.maybe_set_first_contentful_paint(self, &display_list);

self.webrender_api.set_display_list(
Some(get_root_flow_background_color(layout_root)),
webrender_api::Epoch(epoch.0),
Expand Down Expand Up @@ -1655,6 +1674,11 @@ impl LayoutThread {
}
}

impl ProfilerMetadataFactory for LayoutThread {
fn new_metadata(&self) -> Option<TimerMetadata> {
self.profiler_metadata()
}
}

// The default computed value for background-color is transparent (see
// http://dev.w3.org/csswg/css-backgrounds/#background-color). However, we
Expand Down
1 change: 1 addition & 0 deletions components/layout_traits/Cargo.toml
Expand Up @@ -12,6 +12,7 @@ path = "lib.rs"
[dependencies]
gfx = {path = "../gfx"}
ipc-channel = "0.8"
metrics = {path = "../metrics"}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
profile_traits = {path = "../profile_traits"}
Expand Down
5 changes: 4 additions & 1 deletion components/layout_traits/lib.rs
Expand Up @@ -6,6 +6,7 @@

extern crate gfx;
extern crate ipc_channel;
extern crate metrics;
extern crate msg;
extern crate net_traits;
extern crate profile_traits;
Expand All @@ -20,6 +21,7 @@ extern crate webrender_api;

use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use metrics::PaintTimeMetrics;
use msg::constellation_msg::PipelineId;
use msg::constellation_msg::TopLevelBrowsingContextId;
use net_traits::image_cache::ImageCache;
Expand Down Expand Up @@ -48,5 +50,6 @@ pub trait LayoutThreadFactory {
mem_profiler_chan: mem::ProfilerChan,
content_process_shutdown_chan: Option<IpcSender<()>>,
webrender_api_sender: webrender_api::RenderApiSender,
layout_threads: usize);
layout_threads: usize,
paint_time_metrics: PaintTimeMetrics);
}
16 changes: 16 additions & 0 deletions components/metrics/Cargo.toml
@@ -0,0 +1,16 @@
[package]
name = "metrics"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
publish = false

[lib]
name = "metrics"
path = "lib.rs"

[dependencies]
gfx = {path = "../gfx"}
profile_traits = {path = "../profile_traits"}
servo_config = {path = "../config"}
time = "0.1.12"

0 comments on commit 892b30e

Please sign in to comment.