Auto merge of #6629 - pcwalton:profiler-ipc, r=jdm

profile: Make the time and memory profilers run over IPC.

Uses a couple of extra threads to work around the lack of cross-process
boxed trait objects.

r? @nnethercote

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6629)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-24 18:55:05 -06:00
commit f778e0eecf
19 changed files with 212 additions and 168 deletions

View file

@ -15,6 +15,8 @@ use euclid::Matrix4;
use euclid::point::Point2D;
use euclid::rect::Rect;
use euclid::size::Size2D;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use layers::platform::surface::{NativeDisplay, NativeSurface};
use layers::layers::{BufferRequest, LayerBuffer, LayerBufferSet};
use canvas_traits::CanvasMsg;
@ -23,7 +25,7 @@ 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, Reporter, ReportsChan};
use profile_traits::mem::{self, Reporter, ReporterRequest, ReportsChan};
use profile_traits::time::{self, profile};
use rand::{self, Rng};
use std::borrow::ToOwned;
@ -97,14 +99,6 @@ 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,
@ -178,11 +172,20 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
canvas_map: HashMap::new()
};
// Register this thread as a memory reporter, via its own channel.
let reporter = box chan.clone();
// Register the memory reporter.
let reporter_name = format!("paint-reporter-{}", id.0);
let msg = mem::ProfilerMsg::RegisterReporter(reporter_name.clone(), reporter);
mem_profiler_chan.send(msg);
let (reporter_sender, reporter_receiver) =
ipc::channel::<ReporterRequest>().unwrap();
let paint_chan_for_reporter = chan.clone();
ROUTER.add_route(reporter_receiver.to_opaque(), box move |message| {
// Just injects an appropriate event into the paint task's queue.
let request: ReporterRequest = message.to().unwrap();
paint_chan_for_reporter.0.send(Msg::CollectReports(request.reports_channel))
.unwrap();
});
mem_profiler_chan.send(mem::ProfilerMsg::RegisterReporter(
reporter_name.clone(),
Reporter(reporter_sender)));
paint_task.start();
@ -260,8 +263,9 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
Msg::PaintPermissionRevoked => {
self.paint_permission = false;
}
Msg::CollectReports(_) => {
Msg::CollectReports(ref channel) => {
// FIXME(njn): should eventually measure the paint task.
channel.send(Vec::new())
}
Msg::Exit(response_channel, _) => {
// Ask the compositor to remove any layers it is holding for this paint task.