Introduce GlobalScope::time_profiler_chan

This commit is contained in:
Anthony Ramine 2016-10-01 04:00:23 +02:00
parent bfa7d045d0
commit ae3763e7b3
5 changed files with 23 additions and 33 deletions

View file

@ -89,14 +89,6 @@ impl<'a> GlobalRef<'a> {
}
}
/// Get a `time::ProfilerChan` to send messages to the time profiler thread.
pub fn time_profiler_chan(&self) -> &time::ProfilerChan {
match *self {
GlobalRef::Window(window) => window.time_profiler_chan(),
GlobalRef::Worker(worker) => worker.time_profiler_chan(),
}
}
/// Get a `IpcSender` to send messages to the constellation when available.
pub fn constellation_chan(&self) -> &IpcSender<ConstellationMsg> {
match *self {
@ -214,7 +206,7 @@ impl<'a> GlobalRef<'a> {
time::profile(
time::ProfilerCategory::ScriptEvaluate,
Some(metadata),
self.time_profiler_chan().clone(),
self.as_global_scope().time_profiler_chan().clone(),
|| {
let cx = self.get_cx();
let globalhandle = self.reflector().get_jsobject();

View file

@ -11,7 +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 profile_traits::{mem, time};
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
@ -37,12 +37,17 @@ pub struct GlobalScope {
/// For sending messages to the memory profiler.
#[ignore_heap_size_of = "channels are hard"]
mem_profiler_chan: mem::ProfilerChan,
/// For sending messages to the time profiler.
#[ignore_heap_size_of = "channels are hard"]
time_profiler_chan: time::ProfilerChan,
}
impl GlobalScope {
pub fn new_inherited(
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
mem_profiler_chan: mem::ProfilerChan)
mem_profiler_chan: mem::ProfilerChan,
time_profiler_chan: time::ProfilerChan)
-> Self {
GlobalScope {
eventtarget: EventTarget::new_inherited(),
@ -52,6 +57,7 @@ impl GlobalScope {
console_timers: DOMRefCell::new(Default::default()),
devtools_chan: devtools_chan,
mem_profiler_chan: mem_profiler_chan,
time_profiler_chan: time_profiler_chan,
}
}
@ -117,6 +123,11 @@ impl GlobalScope {
pub fn mem_profiler_chan(&self) -> &mem::ProfilerChan {
&self.mem_profiler_chan
}
/// Get a sender to the time profiler thread.
pub fn time_profiler_chan(&self) -> &time::ProfilerChan {
&self.time_profiler_chan
}
}
fn timestamp_in_ms(time: Timespec) -> u64 {

View file

@ -11,12 +11,14 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::Bindings::ServoHTMLParserBinding;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, Root};
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::bindings::trace::JSTraceable;
use dom::document::Document;
use dom::globalscope::GlobalScope;
use dom::htmlimageelement::HTMLImageElement;
use dom::node::Node;
use dom::window::Window;
@ -343,7 +345,7 @@ impl ServoHTMLParser {
};
profile(ProfilerCategory::ScriptParseHTML,
Some(metadata),
self.document.window().time_profiler_chan().clone(),
self.document.window().upcast::<GlobalScope>().time_profiler_chan().clone(),
|| self.do_parse_sync())
}

View file

@ -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"]
time_profiler_chan: ProfilerChan,
/// For sending timeline markers. Will be ignored if
/// no devtools server
devtools_markers: DOMRefCell<HashSet<TimelineMarkerType>>,
@ -1376,10 +1372,6 @@ impl Window {
&self.resource_threads
}
pub fn time_profiler_chan(&self) -> &ProfilerChan {
&self.time_profiler_chan
}
pub fn layout_chan(&self) -> &Sender<Msg> {
&self.layout_chan
}
@ -1593,7 +1585,8 @@ impl Window {
};
let current_time = time::get_time();
let win = box Window {
globalscope: GlobalScope::new_inherited(devtools_chan, mem_profiler_chan),
globalscope:
GlobalScope::new_inherited(devtools_chan, mem_profiler_chan, time_profiler_chan),
script_chan: script_chan,
dom_manipulation_task_source: dom_task_source,
user_interaction_task_source: user_task_source,
@ -1603,7 +1596,6 @@ impl Window {
image_cache_chan: image_cache_chan,
navigator: Default::default(),
image_cache_thread: image_cache_thread,
time_profiler_chan: time_profiler_chan,
history: Default::default(),
browsing_context: Default::default(),
performance: Default::default(),

View file

@ -35,7 +35,6 @@ 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::time;
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
use script_thread::{Runnable, RunnableWrapper};
@ -59,11 +58,12 @@ pub fn prepare_workerscope_init(global: GlobalRef,
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 time_profiler_chan = global_scope.time_profiler_chan().clone();
let init = WorkerGlobalScopeInit {
resource_threads: global.resource_threads(),
mem_profiler_chan: mem_profiler_chan,
to_devtools_sender: to_devtools_sender,
time_profiler_chan: global.time_profiler_chan().clone(),
time_profiler_chan: time_profiler_chan,
from_devtools_sender: devtools_sender,
constellation_chan: global.constellation_chan().clone(),
scheduler_chan: global.scheduler_chan().clone(),
@ -92,9 +92,6 @@ pub struct WorkerGlobalScope {
navigator: MutNullableHeap<JS<WorkerNavigator>>,
timers: OneshotTimers,
#[ignore_heap_size_of = "Defined in std"]
time_profiler_chan: time::ProfilerChan,
#[ignore_heap_size_of = "Defined in ipc-channel"]
/// Optional `IpcSender` for sending the `DevtoolScriptControlMsg`
/// to the server from within the worker
@ -127,7 +124,8 @@ impl WorkerGlobalScope {
-> WorkerGlobalScope {
WorkerGlobalScope {
globalscope:
GlobalScope::new_inherited(init.to_devtools_sender, init.mem_profiler_chan),
GlobalScope::new_inherited(
init.to_devtools_sender, init.mem_profiler_chan, init.time_profiler_chan),
worker_id: init.worker_id,
pipeline_id: init.pipeline_id,
worker_url: worker_url,
@ -137,7 +135,6 @@ impl WorkerGlobalScope {
location: Default::default(),
navigator: Default::default(),
timers: OneshotTimers::new(timer_event_chan, init.scheduler_chan.clone()),
time_profiler_chan: init.time_profiler_chan,
from_devtools_sender: init.from_devtools_sender,
from_devtools_receiver: from_devtools_receiver,
constellation_chan: init.constellation_chan,
@ -147,10 +144,6 @@ impl WorkerGlobalScope {
}
}
pub fn time_profiler_chan(&self) -> &time::ProfilerChan {
&self.time_profiler_chan
}
pub fn from_devtools_sender(&self) -> Option<IpcSender<DevtoolScriptControlMsg>> {
self.from_devtools_sender.clone()
}