diff --git a/components/compositing/pipeline.rs b/components/compositing/pipeline.rs index 4adf2ae5ebda..c9cfa6ee37d7 100644 --- a/components/compositing/pipeline.rs +++ b/components/compositing/pipeline.rs @@ -136,12 +136,15 @@ impl Pipeline { }; PaintTask::create(id, + load_data.url.clone(), + paint_chan.clone(), paint_port, compositor_proxy, constellation_chan.clone(), font_cache_task.clone(), failure.clone(), time_profiler_chan.clone(), + mem_profiler_chan.clone(), paint_shutdown_chan); LayoutTaskFactory::create(None::<&mut LTF>, diff --git a/components/gfx/buffer_map.rs b/components/gfx/buffer_map.rs index cba6fa82b59c..a3d210627d12 100644 --- a/components/gfx/buffer_map.rs +++ b/components/gfx/buffer_map.rs @@ -160,4 +160,8 @@ impl BufferMap { } self.mem = 0 } + + pub fn mem(&self) -> usize { + self.mem + } } diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index 738174d13907..236eafd83d86 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -24,6 +24,7 @@ extern crate layers; extern crate libc; extern crate stb_image; extern crate png; +#[macro_use] extern crate profile_traits; extern crate script_traits; extern crate rustc_serialize; diff --git a/components/gfx/paint_task.rs b/components/gfx/paint_task.rs index 29869f33c14f..f02077608b8e 100644 --- a/components/gfx/paint_task.rs +++ b/components/gfx/paint_task.rs @@ -26,14 +26,16 @@ use msg::compositor_msg::{LayerProperties, PaintListener, ScrollPolicy}; use msg::constellation_msg::Msg as ConstellationMsg; use msg::constellation_msg::{ConstellationChan, Failure, PipelineId}; use msg::constellation_msg::PipelineExitType; +use profile_traits::mem::{self, Report, Reporter, ReportsChan}; use profile_traits::time::{self, profile}; use rand::{self, Rng}; use skia::SkiaGrGLNativeContextRef; use std::borrow::ToOwned; -use std::mem; +use std::mem as std_mem; use std::sync::{Arc, Mutex}; use std::sync::mpsc::{Receiver, Sender, channel}; use std::collections::HashMap; +use url::Url; use util::geometry::{Au, ZERO_POINT}; use util::opts; use util::task::spawn_named_with_send_on_failure; @@ -76,6 +78,7 @@ pub enum Msg { UnusedBuffer(Vec>), PaintPermissionGranted, PaintPermissionRevoked, + CollectReports(ReportsChan), Exit(Option>, PipelineExitType), } @@ -98,8 +101,17 @@ impl PaintChan { } } +impl Reporter for PaintChan { + // Just injects an appropriate event into the paint task's queue. + fn collect_reports(&self, reports_chan: ReportsChan) -> bool { + let PaintChan(ref c) = *self; + c.send(Msg::CollectReports(reports_chan)).is_ok() + } +} + pub struct PaintTask { id: PipelineId, + url: Url, port: Receiver, compositor: C, constellation_chan: ConstellationChan, @@ -107,6 +119,12 @@ pub struct PaintTask { /// A channel to the time profiler. time_profiler_chan: time::ProfilerChan, + /// A channel to the memory profiler. + mem_profiler_chan: mem::ProfilerChan, + + /// The name used for the task's memory reporter. + pub reporter_name: String, + /// The native graphics context. native_graphics_context: Option, @@ -143,12 +161,15 @@ macro_rules! native_graphics_context( impl PaintTask where C: PaintListener + Send + 'static { pub fn create(id: PipelineId, + url: Url, + chan: PaintChan, port: Receiver, compositor: C, constellation_chan: ConstellationChan, font_cache_task: FontCacheTask, failure_msg: Failure, time_profiler_chan: time::ProfilerChan, + mem_profiler_chan: mem::ProfilerChan, shutdown_chan: Sender<()>) { let ConstellationChan(c) = constellation_chan.clone(); spawn_named_with_send_on_failure(format!("PaintTask {:?}", id), task_state::PAINT, move || { @@ -162,13 +183,22 @@ impl PaintTask where C: PaintListener + Send + 'static { font_cache_task, time_profiler_chan.clone()); + // Register this thread as a memory reporter, via its own channel. + let reporter = box chan.clone(); + let reporter_name = format!("paint-reporter-{}", id.0); + mem_profiler_chan.send(mem::ProfilerMsg::RegisterReporter(reporter_name.clone(), + reporter)); + // FIXME: rust/#5967 let mut paint_task = PaintTask { id: id, + url: url, port: port, compositor: compositor, constellation_chan: constellation_chan, time_profiler_chan: time_profiler_chan, + mem_profiler_chan: mem_profiler_chan, + reporter_name: reporter_name, native_graphics_context: native_graphics_context, root_stacking_context: None, paint_permission: false, @@ -286,7 +316,19 @@ impl PaintTask where C: PaintListener + Send + 'static { Msg::PaintPermissionRevoked => { self.paint_permission = false; } + Msg::CollectReports(reports_chan) => { + // FIXME(njn): should eventually measure other parts of the paint task. + let mut reports = vec![]; + reports.push(Report { + path: path!["pages", format!("url({})", self.url), "paint-task", "buffer-map"], + size: self.buffer_map.mem(), + }); + reports_chan.send(reports); + } Msg::Exit(response_channel, exit_type) => { + let msg = mem::ProfilerMsg::UnregisterReporter(self.reporter_name.clone()); + self.mem_profiler_chan.send(msg); + // Ask the compositor to return any used buffers it // is holding for this paint task. This previously was // sent from the constellation. However, it needs to be sent @@ -378,7 +420,7 @@ impl PaintTask where C: PaintListener + Send + 'static { // Divide up the layer into tiles and distribute them to workers via a simple round- // robin strategy. - let tiles = mem::replace(&mut tiles, Vec::new()); + let tiles = std_mem::replace(&mut tiles, Vec::new()); let tile_count = tiles.len(); for (i, tile) in tiles.into_iter().enumerate() { let thread_id = i % self.worker_threads.len(); diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 2dd7e3791b5a..88584cb7b4c9 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -479,6 +479,7 @@ dependencies = [ "layers 0.1.0 (git+https://github.com/servo/rust-layers)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", + "net 0.0.1", "script_traits 0.0.1", "time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",