aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-10-01 03:53:20 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-10-06 20:59:11 +0200
commitbfa7d045d0c83bf44acedd425262e39d29c0bffa (patch)
tree282628cd912cf27ffe23182759d3932cba6828f5 /components/script
parentfe6fca9e1fe94fcefb61a1cde1812d575f164ace (diff)
downloadservo-bfa7d045d0c83bf44acedd425262e39d29c0bffa.tar.gz
servo-bfa7d045d0c83bf44acedd425262e39d29c0bffa.zip
Introduce GlobalScope::mem_profiler_chan
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/global.rs10
-rw-r--r--components/script/dom/dedicatedworkerglobalscope.rs3
-rw-r--r--components/script/dom/globalscope.rs14
-rw-r--r--components/script/dom/serviceworkerglobalscope.rs3
-rw-r--r--components/script/dom/window.rs11
-rw-r--r--components/script/dom/workerglobalscope.rs15
6 files changed, 24 insertions, 32 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index b0a8f9cca75..adb0df51c61 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -26,7 +26,7 @@ use js::rust::CompileOptionsWrapper;
use libc;
use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
-use profile_traits::{mem, time};
+use profile_traits::time;
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
use script_runtime::{ScriptPort, maybe_take_panic_result};
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
@@ -89,14 +89,6 @@ impl<'a> GlobalRef<'a> {
}
}
- /// Get a `mem::ProfilerChan` to send messages to the memory profiler thread.
- pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
- match *self {
- GlobalRef::Window(window) => window.mem_profiler_chan(),
- GlobalRef::Worker(worker) => worker.mem_profiler_chan(),
- }
- }
-
/// Get a `time::ProfilerChan` to send messages to the time profiler thread.
pub fn time_profiler_chan(&self) -> &time::ProfilerChan {
match *self {
diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs
index f68d27a6871..6a07a303fcb 100644
--- a/components/script/dom/dedicatedworkerglobalscope.rs
+++ b/components/script/dom/dedicatedworkerglobalscope.rs
@@ -17,6 +17,7 @@ use dom::bindings::js::{Root, RootCollection};
use dom::bindings::reflector::Reflectable;
use dom::bindings::str::DOMString;
use dom::bindings::structuredclone::StructuredCloneData;
+use dom::globalscope::GlobalScope;
use dom::messageevent::MessageEvent;
use dom::worker::{TrustedWorkerAddress, WorkerErrorHandler, WorkerMessageHandler};
use dom::workerglobalscope::WorkerGlobalScope;
@@ -212,7 +213,7 @@ impl DedicatedWorkerGlobalScope {
}
let reporter_name = format!("dedicated-worker-reporter-{}", random::<u64>());
- scope.mem_profiler_chan().run_with_memory_reporting(|| {
+ scope.upcast::<GlobalScope>().mem_profiler_chan().run_with_memory_reporting(|| {
while let Ok(event) = global.receive_event() {
if scope.is_closing() {
break;
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 6b5c3810da6..02409edc080 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -11,6 +11,7 @@ use dom::crypto::Crypto;
use dom::eventtarget::EventTarget;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
+use profile_traits::mem;
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
@@ -32,11 +33,16 @@ pub struct GlobalScope {
/// For providing instructions to an optional devtools server.
#[ignore_heap_size_of = "channels are hard"]
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
+
+ /// For sending messages to the memory profiler.
+ #[ignore_heap_size_of = "channels are hard"]
+ mem_profiler_chan: mem::ProfilerChan,
}
impl GlobalScope {
pub fn new_inherited(
- devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>)
+ devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
+ mem_profiler_chan: mem::ProfilerChan)
-> Self {
GlobalScope {
eventtarget: EventTarget::new_inherited(),
@@ -45,6 +51,7 @@ impl GlobalScope {
devtools_wants_updates: Default::default(),
console_timers: DOMRefCell::new(Default::default()),
devtools_chan: devtools_chan,
+ mem_profiler_chan: mem_profiler_chan,
}
}
@@ -105,6 +112,11 @@ impl GlobalScope {
pub fn devtools_chan(&self) -> Option<&IpcSender<ScriptToDevtoolsControlMsg>> {
self.devtools_chan.as_ref()
}
+
+ /// Get a sender to the memory profiler thread.
+ pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
+ &self.mem_profiler_chan
+ }
}
fn timestamp_in_ms(time: Timespec) -> u64 {
diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs
index a65eb325138..87f9741a205 100644
--- a/components/script/dom/serviceworkerglobalscope.rs
+++ b/components/script/dom/serviceworkerglobalscope.rs
@@ -17,6 +17,7 @@ use dom::event::Event;
use dom::eventtarget::EventTarget;
use dom::extendableevent::ExtendableEvent;
use dom::extendablemessageevent::ExtendableMessageEvent;
+use dom::globalscope::GlobalScope;
use dom::workerglobalscope::WorkerGlobalScope;
use ipc_channel::ipc::{self, IpcSender, IpcReceiver};
use ipc_channel::router::ROUTER;
@@ -192,7 +193,7 @@ impl ServiceWorkerGlobalScope {
global.dispatch_activate();
let reporter_name = format!("service-worker-reporter-{}", random::<u64>());
- scope.mem_profiler_chan().run_with_memory_reporting(|| {
+ scope.upcast::<GlobalScope>().mem_profiler_chan().run_with_memory_reporting(|| {
while let Ok(event) = global.receive_event() {
if !global.handle_event(event) {
break;
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index f07e395a709..848f6b0d72f 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -176,10 +176,6 @@ pub struct Window {
/// For sending messages to the memory profiler.
#[ignore_heap_size_of = "channels are hard"]
- mem_profiler_chan: mem::ProfilerChan,
-
- /// For sending messages to the memory profiler.
- #[ignore_heap_size_of = "channels are hard"]
time_profiler_chan: ProfilerChan,
/// For sending timeline markers. Will be ignored if
@@ -1380,10 +1376,6 @@ impl Window {
&self.resource_threads
}
- pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
- &self.mem_profiler_chan
- }
-
pub fn time_profiler_chan(&self) -> &ProfilerChan {
&self.time_profiler_chan
}
@@ -1601,7 +1593,7 @@ impl Window {
};
let current_time = time::get_time();
let win = box Window {
- globalscope: GlobalScope::new_inherited(devtools_chan),
+ globalscope: GlobalScope::new_inherited(devtools_chan, mem_profiler_chan),
script_chan: script_chan,
dom_manipulation_task_source: dom_task_source,
user_interaction_task_source: user_task_source,
@@ -1611,7 +1603,6 @@ impl Window {
image_cache_chan: image_cache_chan,
navigator: Default::default(),
image_cache_thread: image_cache_thread,
- mem_profiler_chan: mem_profiler_chan,
time_profiler_chan: time_profiler_chan,
history: Default::default(),
browsing_context: Default::default(),
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index af707508abf..071b68fa274 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -35,7 +35,7 @@ use js::rust::Runtime;
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use net_traits::{IpcSend, LoadOrigin};
use net_traits::{LoadContext, ResourceThreads, load_whole_resource};
-use profile_traits::{mem, time};
+use profile_traits::time;
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
use script_thread::{Runnable, RunnableWrapper};
@@ -58,9 +58,10 @@ pub fn prepare_workerscope_init(global: GlobalRef,
let global_scope = global.as_global_scope();
let worker_id = global_scope.get_next_worker_id();
let to_devtools_sender = global_scope.devtools_chan().cloned();
+ let mem_profiler_chan = global_scope.mem_profiler_chan().clone();
let init = WorkerGlobalScopeInit {
resource_threads: global.resource_threads(),
- mem_profiler_chan: global.mem_profiler_chan().clone(),
+ mem_profiler_chan: mem_profiler_chan,
to_devtools_sender: to_devtools_sender,
time_profiler_chan: global.time_profiler_chan().clone(),
from_devtools_sender: devtools_sender,
@@ -92,8 +93,6 @@ pub struct WorkerGlobalScope {
timers: OneshotTimers,
#[ignore_heap_size_of = "Defined in std"]
- mem_profiler_chan: mem::ProfilerChan,
- #[ignore_heap_size_of = "Defined in std"]
time_profiler_chan: time::ProfilerChan,
#[ignore_heap_size_of = "Defined in ipc-channel"]
@@ -127,7 +126,8 @@ impl WorkerGlobalScope {
closing: Option<Arc<AtomicBool>>)
-> WorkerGlobalScope {
WorkerGlobalScope {
- globalscope: GlobalScope::new_inherited(init.to_devtools_sender),
+ globalscope:
+ GlobalScope::new_inherited(init.to_devtools_sender, init.mem_profiler_chan),
worker_id: init.worker_id,
pipeline_id: init.pipeline_id,
worker_url: worker_url,
@@ -137,7 +137,6 @@ impl WorkerGlobalScope {
location: Default::default(),
navigator: Default::default(),
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()),
- mem_profiler_chan: init.mem_profiler_chan,
time_profiler_chan: init.time_profiler_chan,
from_devtools_sender: init.from_devtools_sender,
from_devtools_receiver: from_devtools_receiver,
@@ -148,10 +147,6 @@ impl WorkerGlobalScope {
}
}
- pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
- &self.mem_profiler_chan
- }
-
pub fn time_profiler_chan(&self) -> &time::ProfilerChan {
&self.time_profiler_chan
}