Skip to content

Commit

Permalink
Measure paint task buffer maps in the memory profiler.
Browse files Browse the repository at this point in the history
Example output from the memory profiler:

```
|       1.04 MiB -- url(http://en.wikipedia.org/wiki/Main_Page)
|          0.26 MiB -- display-list
|          0.78 MiB -- paint-task       # new output line
|             0.78 MiB -- buffer-map    # new output line
```

The buffer maps aren't huge, but they're worth measuring, and it's good
to get the memory profiler plumbing into PaintTask.
  • Loading branch information
nnethercote committed May 28, 2015
1 parent 2ce7b78 commit a21f6c4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
3 changes: 3 additions & 0 deletions components/compositing/pipeline.rs
Expand Up @@ -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>,
Expand Down
4 changes: 4 additions & 0 deletions components/gfx/buffer_map.rs
Expand Up @@ -160,4 +160,8 @@ impl BufferMap {
}
self.mem = 0
}

pub fn mem(&self) -> usize {
self.mem
}
}
1 change: 1 addition & 0 deletions components/gfx/lib.rs
Expand Up @@ -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;
Expand Down
46 changes: 44 additions & 2 deletions components/gfx/paint_task.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +78,7 @@ pub enum Msg {
UnusedBuffer(Vec<Box<LayerBuffer>>),
PaintPermissionGranted,
PaintPermissionRevoked,
CollectReports(ReportsChan),
Exit(Option<Sender<()>>, PipelineExitType),
}

Expand All @@ -98,15 +101,30 @@ 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<C> {
id: PipelineId,
url: Url,
port: Receiver<Msg>,
compositor: C,
constellation_chan: ConstellationChan,

/// 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<NativePaintingGraphicsContext>,

Expand Down Expand Up @@ -143,12 +161,15 @@ macro_rules! native_graphics_context(

impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
pub fn create(id: PipelineId,
url: Url,
chan: PaintChan,
port: Receiver<Msg>,
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 || {
Expand All @@ -162,13 +183,22 @@ impl<C> PaintTask<C> 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,
Expand Down Expand Up @@ -286,7 +316,19 @@ impl<C> PaintTask<C> 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
Expand Down Expand Up @@ -378,7 +420,7 @@ impl<C> PaintTask<C> 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();
Expand Down
1 change: 1 addition & 0 deletions components/servo/Cargo.lock

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

0 comments on commit a21f6c4

Please sign in to comment.