aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_task.rs
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2015-08-04 16:32:01 +0200
committerMs2ger <Ms2ger@gmail.com>2015-08-06 15:24:27 +0200
commitbf3ecaa90179535cacb22a39f324a45b64eb51c4 (patch)
tree93c7a5b98a8df114a01c81ba8bc705beba1bfc78 /components/script/script_task.rs
parent4726f58d15a6bfed9614b7ceaaab7765a5c01d03 (diff)
downloadservo-bf3ecaa90179535cacb22a39f324a45b64eb51c4.tar.gz
servo-bf3ecaa90179535cacb22a39f324a45b64eb51c4.zip
Create a run_with_memory_reporting method to reduce the boilerplate associated with registering memory reporters.
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r--components/script/script_task.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index 832024a1c03..9b57e9283b5 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -73,7 +73,7 @@ use net_traits::LoadData as NetLoadData;
use net_traits::{AsyncResponseTarget, ResourceTask, LoadConsumer, ControlMsg, Metadata};
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask, ImageCacheResult};
use net_traits::storage_task::StorageTask;
-use profile_traits::mem::{self, Report, Reporter, ReporterRequest, ReportKind, ReportsChan};
+use profile_traits::mem::{self, Report, ReportKind, ReportsChan, OpaqueSender};
use string_cache::Atom;
use util::str::DOMString;
use util::task::spawn_named_with_send_on_failure;
@@ -216,6 +216,12 @@ pub trait ScriptChan {
fn clone(&self) -> Box<ScriptChan+Send>;
}
+impl OpaqueSender<ScriptMsg> for Box<ScriptChan+Send> {
+ fn send(&self, msg: ScriptMsg) {
+ ScriptChan::send(&**self, msg).unwrap();
+ }
+}
+
/// An interface for receiving ScriptMsg values in an event loop. Used for synchronous DOM
/// APIs that need to abstract over multiple kinds of event loops (worker/main thread) with
/// different Receiver interfaces.
@@ -437,24 +443,10 @@ impl ScriptTaskFactory for ScriptTask {
load_data.url.clone());
script_task.start_page_load(new_load, load_data);
- // Register this task as a memory reporter.
let reporter_name = format!("script-reporter-{}", id.0);
- let (reporter_sender, reporter_receiver) = ipc::channel().unwrap();
- ROUTER.add_route(reporter_receiver.to_opaque(), box move |reporter_request| {
- // Just injects an appropriate event into the worker task's queue.
- let reporter_request: ReporterRequest = reporter_request.to().unwrap();
- channel_for_reporter.send(ScriptMsg::CollectReports(
- reporter_request.reports_channel)).unwrap()
- });
- let reporter = Reporter(reporter_sender);
- let msg = mem::ProfilerMsg::RegisterReporter(reporter_name.clone(), reporter);
- mem_profiler_chan.send(msg);
-
- script_task.start();
-
- // Unregister this task as a memory reporter.
- let msg = mem::ProfilerMsg::UnregisterReporter(reporter_name);
- mem_profiler_chan.send(msg);
+ mem_profiler_chan.run_with_memory_reporting(|| {
+ script_task.start();
+ }, reporter_name, channel_for_reporter, ScriptMsg::CollectReports);
// This must always be the very last operation performed before the task completes
failsafe.neuter();