mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Measure paint task buffer maps in the memory profiler.
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.
This commit is contained in:
parent
2ce7b78907
commit
a21f6c407c
5 changed files with 53 additions and 2 deletions
|
@ -136,12 +136,15 @@ impl Pipeline {
|
||||||
};
|
};
|
||||||
|
|
||||||
PaintTask::create(id,
|
PaintTask::create(id,
|
||||||
|
load_data.url.clone(),
|
||||||
|
paint_chan.clone(),
|
||||||
paint_port,
|
paint_port,
|
||||||
compositor_proxy,
|
compositor_proxy,
|
||||||
constellation_chan.clone(),
|
constellation_chan.clone(),
|
||||||
font_cache_task.clone(),
|
font_cache_task.clone(),
|
||||||
failure.clone(),
|
failure.clone(),
|
||||||
time_profiler_chan.clone(),
|
time_profiler_chan.clone(),
|
||||||
|
mem_profiler_chan.clone(),
|
||||||
paint_shutdown_chan);
|
paint_shutdown_chan);
|
||||||
|
|
||||||
LayoutTaskFactory::create(None::<&mut LTF>,
|
LayoutTaskFactory::create(None::<&mut LTF>,
|
||||||
|
|
|
@ -160,4 +160,8 @@ impl BufferMap {
|
||||||
}
|
}
|
||||||
self.mem = 0
|
self.mem = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mem(&self) -> usize {
|
||||||
|
self.mem
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ extern crate layers;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate stb_image;
|
extern crate stb_image;
|
||||||
extern crate png;
|
extern crate png;
|
||||||
|
#[macro_use]
|
||||||
extern crate profile_traits;
|
extern crate profile_traits;
|
||||||
extern crate script_traits;
|
extern crate script_traits;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
|
|
@ -26,14 +26,16 @@ use msg::compositor_msg::{LayerProperties, PaintListener, ScrollPolicy};
|
||||||
use msg::constellation_msg::Msg as ConstellationMsg;
|
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||||
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
|
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
|
||||||
use msg::constellation_msg::PipelineExitType;
|
use msg::constellation_msg::PipelineExitType;
|
||||||
|
use profile_traits::mem::{self, Report, Reporter, ReportsChan};
|
||||||
use profile_traits::time::{self, profile};
|
use profile_traits::time::{self, profile};
|
||||||
use rand::{self, Rng};
|
use rand::{self, Rng};
|
||||||
use skia::SkiaGrGLNativeContextRef;
|
use skia::SkiaGrGLNativeContextRef;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::mem;
|
use std::mem as std_mem;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use url::Url;
|
||||||
use util::geometry::{Au, ZERO_POINT};
|
use util::geometry::{Au, ZERO_POINT};
|
||||||
use util::opts;
|
use util::opts;
|
||||||
use util::task::spawn_named_with_send_on_failure;
|
use util::task::spawn_named_with_send_on_failure;
|
||||||
|
@ -76,6 +78,7 @@ pub enum Msg {
|
||||||
UnusedBuffer(Vec<Box<LayerBuffer>>),
|
UnusedBuffer(Vec<Box<LayerBuffer>>),
|
||||||
PaintPermissionGranted,
|
PaintPermissionGranted,
|
||||||
PaintPermissionRevoked,
|
PaintPermissionRevoked,
|
||||||
|
CollectReports(ReportsChan),
|
||||||
Exit(Option<Sender<()>>, PipelineExitType),
|
Exit(Option<Sender<()>>, 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<C> {
|
pub struct PaintTask<C> {
|
||||||
id: PipelineId,
|
id: PipelineId,
|
||||||
|
url: Url,
|
||||||
port: Receiver<Msg>,
|
port: Receiver<Msg>,
|
||||||
compositor: C,
|
compositor: C,
|
||||||
constellation_chan: ConstellationChan,
|
constellation_chan: ConstellationChan,
|
||||||
|
@ -107,6 +119,12 @@ pub struct PaintTask<C> {
|
||||||
/// A channel to the time profiler.
|
/// A channel to the time profiler.
|
||||||
time_profiler_chan: time::ProfilerChan,
|
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.
|
/// The native graphics context.
|
||||||
native_graphics_context: Option<NativePaintingGraphicsContext>,
|
native_graphics_context: Option<NativePaintingGraphicsContext>,
|
||||||
|
|
||||||
|
@ -143,12 +161,15 @@ macro_rules! native_graphics_context(
|
||||||
|
|
||||||
impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
|
impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
|
||||||
pub fn create(id: PipelineId,
|
pub fn create(id: PipelineId,
|
||||||
|
url: Url,
|
||||||
|
chan: PaintChan,
|
||||||
port: Receiver<Msg>,
|
port: Receiver<Msg>,
|
||||||
compositor: C,
|
compositor: C,
|
||||||
constellation_chan: ConstellationChan,
|
constellation_chan: ConstellationChan,
|
||||||
font_cache_task: FontCacheTask,
|
font_cache_task: FontCacheTask,
|
||||||
failure_msg: Failure,
|
failure_msg: Failure,
|
||||||
time_profiler_chan: time::ProfilerChan,
|
time_profiler_chan: time::ProfilerChan,
|
||||||
|
mem_profiler_chan: mem::ProfilerChan,
|
||||||
shutdown_chan: Sender<()>) {
|
shutdown_chan: Sender<()>) {
|
||||||
let ConstellationChan(c) = constellation_chan.clone();
|
let ConstellationChan(c) = constellation_chan.clone();
|
||||||
spawn_named_with_send_on_failure(format!("PaintTask {:?}", id), task_state::PAINT, move || {
|
spawn_named_with_send_on_failure(format!("PaintTask {:?}", id), task_state::PAINT, move || {
|
||||||
|
@ -162,13 +183,22 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
|
||||||
font_cache_task,
|
font_cache_task,
|
||||||
time_profiler_chan.clone());
|
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
|
// FIXME: rust/#5967
|
||||||
let mut paint_task = PaintTask {
|
let mut paint_task = PaintTask {
|
||||||
id: id,
|
id: id,
|
||||||
|
url: url,
|
||||||
port: port,
|
port: port,
|
||||||
compositor: compositor,
|
compositor: compositor,
|
||||||
constellation_chan: constellation_chan,
|
constellation_chan: constellation_chan,
|
||||||
time_profiler_chan: time_profiler_chan,
|
time_profiler_chan: time_profiler_chan,
|
||||||
|
mem_profiler_chan: mem_profiler_chan,
|
||||||
|
reporter_name: reporter_name,
|
||||||
native_graphics_context: native_graphics_context,
|
native_graphics_context: native_graphics_context,
|
||||||
root_stacking_context: None,
|
root_stacking_context: None,
|
||||||
paint_permission: false,
|
paint_permission: false,
|
||||||
|
@ -286,7 +316,19 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
|
||||||
Msg::PaintPermissionRevoked => {
|
Msg::PaintPermissionRevoked => {
|
||||||
self.paint_permission = false;
|
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) => {
|
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
|
// Ask the compositor to return any used buffers it
|
||||||
// is holding for this paint task. This previously was
|
// is holding for this paint task. This previously was
|
||||||
// sent from the constellation. However, it needs to be sent
|
// sent from the constellation. However, it needs to be sent
|
||||||
|
@ -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-
|
// Divide up the layer into tiles and distribute them to workers via a simple round-
|
||||||
// robin strategy.
|
// robin strategy.
|
||||||
let tiles = mem::replace(&mut tiles, Vec::new());
|
let tiles = std_mem::replace(&mut tiles, Vec::new());
|
||||||
let tile_count = tiles.len();
|
let tile_count = tiles.len();
|
||||||
for (i, tile) in tiles.into_iter().enumerate() {
|
for (i, tile) in tiles.into_iter().enumerate() {
|
||||||
let thread_id = i % self.worker_threads.len();
|
let thread_id = i % self.worker_threads.len();
|
||||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -479,6 +479,7 @@ dependencies = [
|
||||||
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
|
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
|
||||||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
|
"net 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"url 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue