Create a run_with_memory_reporting method to reduce the boilerplate associated with registering memory reporters.

This commit is contained in:
Ms2ger 2015-08-04 16:32:01 +02:00
parent 4726f58d15
commit bf3ecaa901
6 changed files with 68 additions and 80 deletions

View file

@ -47,7 +47,7 @@ use log;
use msg::compositor_msg::{Epoch, ScrollPolicy, LayerId};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId};
use profile_traits::mem::{self, Report, Reporter, ReporterRequest, ReportKind, ReportsChan};
use profile_traits::mem::{self, Report, ReportKind, ReportsChan};
use profile_traits::time::{self, ProfilerMetadata, profile};
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use net_traits::{load_bytes_iter, PendingAsyncLoad};
@ -257,25 +257,10 @@ impl LayoutTaskFactory for LayoutTask {
time_profiler_chan,
mem_profiler_chan.clone());
// Create a memory reporter thread.
let reporter_name = format!("layout-reporter-{}", id.0);
let (reporter_sender, reporter_receiver) =
ipc::channel::<ReporterRequest>().unwrap();
let layout_chan_for_reporter = layout_chan.clone();
ROUTER.add_route(reporter_receiver.to_opaque(), box move |message| {
// Just injects an appropriate event into the layout task's queue.
let request: ReporterRequest = message.to().unwrap();
layout_chan_for_reporter.0.send(Msg::CollectReports(request.reports_channel))
.unwrap();
});
mem_profiler_chan.send(mem::ProfilerMsg::RegisterReporter(
reporter_name.clone(),
Reporter(reporter_sender)));
layout.start();
let msg = mem::ProfilerMsg::UnregisterReporter(reporter_name);
mem_profiler_chan.send(msg);
mem_profiler_chan.run_with_memory_reporting(|| {
layout.start();
}, reporter_name, layout_chan.0, Msg::CollectReports);
}
shutdown_chan.send(()).unwrap();
}, ConstellationMsg::Failure(failure_msg), con_chan);