mirror of
https://github.com/servo/servo.git
synced 2025-07-03 05:23:38 +01:00
Introduce GlobalScope::mem_profiler_chan
This commit is contained in:
parent
fe6fca9e1f
commit
bfa7d045d0
6 changed files with 24 additions and 32 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -174,10 +174,6 @@ pub struct Window {
|
|||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
timers: OneshotTimers,
|
||||
|
||||
/// 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,
|
||||
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
@ -91,8 +92,6 @@ pub struct WorkerGlobalScope {
|
|||
navigator: MutNullableHeap<JS<WorkerNavigator>>,
|
||||
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,
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue