зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #6572 - Wire up the JS engine's memory reporting (from nnethercote:js-reporting); r=jdm
SpiderMonkey provides an extremely fine-grained breakdown of memory usage, but for Servo we aggregate the measurements into a small number of coarse buckets, which seems appropriate for the current level of detail provided by Servo's memory profiler. Sample output: ``` | 17.41 MiB -- url(file:///home/njn/moz/servo/../servo-static-suite/wikipedia/Guardians%20of%20the%20Galaxy%20(film)%20-%20Wikipedia,%20the%20free%20encyclopedia.html) | 7.32 MiB -- js | 3.07 MiB -- malloc-heap | 3.00 MiB -- gc-heap | 2.48 MiB -- used | 0.34 MiB -- decommitted | 0.09 MiB -- unused | 0.09 MiB -- admin | 1.25 MiB -- non-heap ``` Most of the changes are plumbing to get the script task communicating with the memory profiler task. Source-Repo: https://github.com/servo/servo Source-Revision: 2b0bdbe1c195f2f6dd7671981999d622c505fbc5
This commit is contained in:
Родитель
42d8e855bf
Коммит
8de763bdb1
|
@ -318,6 +318,7 @@ impl PipelineContent {
|
|||
self.resource_task,
|
||||
self.storage_task.clone(),
|
||||
self.image_cache_task.clone(),
|
||||
self.mem_profiler_chan.clone(),
|
||||
self.devtools_chan,
|
||||
self.window_size,
|
||||
self.load_data.clone());
|
||||
|
|
|
@ -19,6 +19,7 @@ use script_task::{ScriptChan, ScriptPort, ScriptMsg, ScriptTask};
|
|||
|
||||
use msg::constellation_msg::{PipelineId, WorkerId};
|
||||
use net_traits::ResourceTask;
|
||||
use profile_traits::mem;
|
||||
|
||||
use js::{JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
|
||||
use js::jsapi::{GetGlobalForObjectCrossCompartment};
|
||||
|
@ -82,7 +83,15 @@ impl<'a> GlobalRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get `DevtoolsControlChan` to send messages to Devtools
|
||||
/// Get a `mem::ProfilerChan` to send messages to the memory profiler task.
|
||||
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 `DevtoolsControlChan` to send messages to Devtools
|
||||
/// task when available.
|
||||
pub fn devtools_chan(&self) -> Option<DevtoolsControlChan> {
|
||||
match *self {
|
||||
|
|
|
@ -60,6 +60,7 @@ use smallvec::SmallVec1;
|
|||
use msg::compositor_msg::ScriptListener;
|
||||
use msg::constellation_msg::ConstellationChan;
|
||||
use net_traits::image::base::Image;
|
||||
use profile_traits::mem::ProfilerChan;
|
||||
use util::str::{LengthOrPercentageOrAuto};
|
||||
use std::cell::{Cell, UnsafeCell, RefCell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
@ -299,6 +300,7 @@ no_jsmanaged_fields!(CanvasGradientStop, LinearGradientStyle, RadialGradientStyl
|
|||
no_jsmanaged_fields!(LineCapStyle, LineJoinStyle, CompositionOrBlending);
|
||||
no_jsmanaged_fields!(RepetitionStyle);
|
||||
no_jsmanaged_fields!(WebGLError);
|
||||
no_jsmanaged_fields!(ProfilerChan);
|
||||
|
||||
impl JSTraceable for Box<ScriptChan+Send> {
|
||||
#[inline]
|
||||
|
|
|
@ -29,6 +29,7 @@ use msg::constellation_msg::PipelineId;
|
|||
use devtools_traits::DevtoolsControlChan;
|
||||
|
||||
use net_traits::{load_whole_resource, ResourceTask};
|
||||
use profile_traits::mem::{self, Reporter, ReportsChan};
|
||||
use util::task::spawn_named;
|
||||
use util::task_state;
|
||||
use util::task_state::{SCRIPT, IN_WORKER};
|
||||
|
@ -39,6 +40,7 @@ use js::jsval::UndefinedValue;
|
|||
use js::rust::Runtime;
|
||||
use url::Url;
|
||||
|
||||
use rand::random;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{Sender, Receiver, channel};
|
||||
|
||||
|
@ -64,6 +66,13 @@ impl ScriptChan for SendableWorkerScriptChan {
|
|||
}
|
||||
}
|
||||
|
||||
impl Reporter for SendableWorkerScriptChan {
|
||||
// Just injects an appropriate event into the worker task's queue.
|
||||
fn collect_reports(&self, reports_chan: ReportsChan) -> bool {
|
||||
self.send(ScriptMsg::CollectReports(reports_chan)).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
|
||||
/// value for the duration of this object's lifetime. This ensures that the related Worker
|
||||
/// object only lives as long as necessary (ie. while events are being executed), while
|
||||
|
@ -105,6 +114,7 @@ pub struct DedicatedWorkerGlobalScope {
|
|||
impl DedicatedWorkerGlobalScope {
|
||||
fn new_inherited(worker_url: Url,
|
||||
id: PipelineId,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
runtime: Rc<Runtime>,
|
||||
resource_task: ResourceTask,
|
||||
|
@ -115,7 +125,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
DedicatedWorkerGlobalScope {
|
||||
workerglobalscope: WorkerGlobalScope::new_inherited(
|
||||
WorkerGlobalScopeTypeId::DedicatedGlobalScope, worker_url,
|
||||
runtime, resource_task, devtools_chan),
|
||||
runtime, resource_task, mem_profiler_chan, devtools_chan),
|
||||
id: id,
|
||||
receiver: receiver,
|
||||
own_sender: own_sender,
|
||||
|
@ -126,6 +136,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
|
||||
pub fn new(worker_url: Url,
|
||||
id: PipelineId,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
runtime: Rc<Runtime>,
|
||||
resource_task: ResourceTask,
|
||||
|
@ -134,7 +145,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
receiver: Receiver<(TrustedWorkerAddress, ScriptMsg)>)
|
||||
-> Root<DedicatedWorkerGlobalScope> {
|
||||
let scope = box DedicatedWorkerGlobalScope::new_inherited(
|
||||
worker_url, id, devtools_chan, runtime.clone(), resource_task,
|
||||
worker_url, id, mem_profiler_chan, devtools_chan, runtime.clone(), resource_task,
|
||||
parent_sender, own_sender, receiver);
|
||||
DedicatedWorkerGlobalScopeBinding::Wrap(runtime.cx(), scope)
|
||||
}
|
||||
|
@ -143,6 +154,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
impl DedicatedWorkerGlobalScope {
|
||||
pub fn run_worker_scope(worker_url: Url,
|
||||
id: PipelineId,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
worker: TrustedWorkerAddress,
|
||||
resource_task: ResourceTask,
|
||||
|
@ -171,8 +183,12 @@ impl DedicatedWorkerGlobalScope {
|
|||
let runtime = Rc::new(ScriptTask::new_rt_and_cx());
|
||||
let serialized_url = url.serialize();
|
||||
let global = DedicatedWorkerGlobalScope::new(
|
||||
url, id, devtools_chan, runtime.clone(), resource_task,
|
||||
url, id, mem_profiler_chan.clone(), devtools_chan, runtime.clone(), resource_task,
|
||||
parent_sender, own_sender, receiver);
|
||||
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
|
||||
// registration (#6631), so we instead use a random number and cross our fingers.
|
||||
let reporter_name = format!("worker-reporter-{}", random::<u64>());
|
||||
println!("reporter_name = {}", reporter_name);
|
||||
|
||||
{
|
||||
let _ar = AutoWorkerReset::new(global.r(), worker);
|
||||
|
@ -188,6 +204,12 @@ impl DedicatedWorkerGlobalScope {
|
|||
report_pending_exception(runtime.cx(), global.r().reflector().get_jsobject().get());
|
||||
}
|
||||
}
|
||||
|
||||
// Register this task as a memory reporter. This needs to be done within the
|
||||
// scope of `_ar` otherwise script_chan_as_reporter() will panic.
|
||||
let reporter = global.script_chan_as_reporter();
|
||||
let msg = mem::ProfilerMsg::RegisterReporter(reporter_name.clone(), reporter);
|
||||
mem_profiler_chan.send(msg);
|
||||
}
|
||||
|
||||
loop {
|
||||
|
@ -199,12 +221,17 @@ impl DedicatedWorkerGlobalScope {
|
|||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
// Unregister this task as a memory reporter.
|
||||
let msg = mem::ProfilerMsg::UnregisterReporter(reporter_name);
|
||||
mem_profiler_chan.send(msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DedicatedWorkerGlobalScopeHelpers {
|
||||
fn script_chan(self) -> Box<ScriptChan+Send>;
|
||||
fn script_chan_as_reporter(self) -> Box<Reporter+Send>;
|
||||
fn pipeline(self) -> PipelineId;
|
||||
fn new_script_pair(self) -> (Box<ScriptChan+Send>, Box<ScriptPort+Send>);
|
||||
fn process_event(self, msg: ScriptMsg);
|
||||
|
@ -218,6 +245,14 @@ impl<'a> DedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalScope {
|
|||
}
|
||||
}
|
||||
|
||||
fn script_chan_as_reporter(self) -> Box<Reporter+Send> {
|
||||
box SendableWorkerScriptChan {
|
||||
sender: self.own_sender.clone(),
|
||||
worker: self.worker.borrow().as_ref().unwrap().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn pipeline(self) -> PipelineId {
|
||||
self.id
|
||||
}
|
||||
|
@ -263,6 +298,13 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS
|
|||
let scope = WorkerGlobalScopeCast::from_ref(self);
|
||||
scope.handle_fire_timer(timer_id);
|
||||
}
|
||||
ScriptMsg::CollectReports(reports_chan) => {
|
||||
let scope = WorkerGlobalScopeCast::from_ref(self);
|
||||
let cx = scope.get_cx();
|
||||
let path_seg = format!("url({})", scope.get_url());
|
||||
let reports = ScriptTask::get_reports(cx, path_seg);
|
||||
reports_chan.send(reports);
|
||||
}
|
||||
_ => panic!("Unexpected message"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
|||
use net_traits::ResourceTask;
|
||||
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask};
|
||||
use net_traits::storage_task::{StorageTask, StorageType};
|
||||
use profile_traits::mem;
|
||||
use util::geometry::{self, Au, MAX_RECT};
|
||||
use util::opts;
|
||||
use util::str::{DOMString,HTML_SPACE_CHARACTERS};
|
||||
|
@ -64,7 +65,7 @@ use std::cell::{Cell, Ref, RefMut, RefCell};
|
|||
use std::collections::HashSet;
|
||||
use std::default::Default;
|
||||
use std::ffi::CString;
|
||||
use std::mem;
|
||||
use std::mem as std_mem;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
use std::sync::mpsc::TryRecvError::{Empty, Disconnected};
|
||||
|
@ -118,6 +119,9 @@ pub struct Window {
|
|||
|
||||
next_worker_id: Cell<WorkerId>,
|
||||
|
||||
/// For sending messages to the memory profiler.
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
|
||||
/// For providing instructions to an optional devtools server.
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
/// For sending timeline markers. Will be ignored if
|
||||
|
@ -538,6 +542,7 @@ pub trait WindowHelpers {
|
|||
fn window_size(self) -> Option<WindowSizeData>;
|
||||
fn get_url(self) -> Url;
|
||||
fn resource_task(self) -> ResourceTask;
|
||||
fn mem_profiler_chan(self) -> mem::ProfilerChan;
|
||||
fn devtools_chan(self) -> Option<DevtoolsControlChan>;
|
||||
fn layout_chan(self) -> LayoutChan;
|
||||
fn constellation_chan(self) -> ConstellationChan;
|
||||
|
@ -721,7 +726,7 @@ impl<'a> WindowHelpers for &'a Window {
|
|||
/// layout task has finished any pending request messages.
|
||||
fn join_layout(self) {
|
||||
let mut layout_join_port = self.layout_join_port.borrow_mut();
|
||||
if let Some(join_port) = mem::replace(&mut *layout_join_port, None) {
|
||||
if let Some(join_port) = std_mem::replace(&mut *layout_join_port, None) {
|
||||
match join_port.try_recv() {
|
||||
Err(Empty) => {
|
||||
info!("script: waiting on layout");
|
||||
|
@ -823,6 +828,10 @@ impl<'a> WindowHelpers for &'a Window {
|
|||
self.resource_task.clone()
|
||||
}
|
||||
|
||||
fn mem_profiler_chan(self) -> mem::ProfilerChan {
|
||||
self.mem_profiler_chan.clone()
|
||||
}
|
||||
|
||||
fn devtools_chan(self) -> Option<DevtoolsControlChan> {
|
||||
self.devtools_chan.clone()
|
||||
}
|
||||
|
@ -968,6 +977,7 @@ impl Window {
|
|||
image_cache_task: ImageCacheTask,
|
||||
resource_task: ResourceTask,
|
||||
storage_task: StorageTask,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
constellation_chan: ConstellationChan,
|
||||
layout_chan: LayoutChan,
|
||||
|
@ -993,6 +1003,7 @@ impl Window {
|
|||
page: page,
|
||||
navigator: Default::default(),
|
||||
image_cache_task: image_cache_task,
|
||||
mem_profiler_chan: mem_profiler_chan,
|
||||
devtools_chan: devtools_chan,
|
||||
browser_context: DOMRefCell::new(None),
|
||||
performance: Default::default(),
|
||||
|
|
|
@ -90,8 +90,8 @@ impl Worker {
|
|||
}
|
||||
|
||||
DedicatedWorkerGlobalScope::run_worker_scope(
|
||||
worker_url, global.pipeline(), global.devtools_chan(), worker_ref, resource_task, global.script_chan(),
|
||||
sender, receiver);
|
||||
worker_url, global.pipeline(), global.mem_profiler_chan(), global.devtools_chan(),
|
||||
worker_ref, resource_task, global.script_chan(), sender, receiver);
|
||||
|
||||
Ok(worker)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ use timers::{IsInterval, TimerId, TimerManager, TimerCallback};
|
|||
use devtools_traits::DevtoolsControlChan;
|
||||
|
||||
use msg::constellation_msg::{PipelineId, WorkerId};
|
||||
use profile_traits::mem;
|
||||
use net_traits::{load_whole_resource, ResourceTask};
|
||||
use util::str::DOMString;
|
||||
|
||||
|
@ -52,6 +53,7 @@ pub struct WorkerGlobalScope {
|
|||
console: MutNullableHeap<JS<Console>>,
|
||||
crypto: MutNullableHeap<JS<Crypto>>,
|
||||
timers: TimerManager,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
}
|
||||
|
||||
|
@ -60,6 +62,7 @@ impl WorkerGlobalScope {
|
|||
worker_url: Url,
|
||||
runtime: Rc<Runtime>,
|
||||
resource_task: ResourceTask,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>) -> WorkerGlobalScope {
|
||||
WorkerGlobalScope {
|
||||
eventtarget: EventTarget::new_inherited(EventTargetTypeId::WorkerGlobalScope(type_id)),
|
||||
|
@ -72,10 +75,15 @@ impl WorkerGlobalScope {
|
|||
console: Default::default(),
|
||||
crypto: Default::default(),
|
||||
timers: TimerManager::new(),
|
||||
mem_profiler_chan: mem_profiler_chan,
|
||||
devtools_chan: devtools_chan,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mem_profiler_chan(&self) -> mem::ProfilerChan {
|
||||
self.mem_profiler_chan.clone()
|
||||
}
|
||||
|
||||
pub fn devtools_chan(&self) -> Option<DevtoolsControlChan> {
|
||||
self.devtools_chan.clone()
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ extern crate time;
|
|||
extern crate canvas;
|
||||
extern crate canvas_traits;
|
||||
extern crate rand;
|
||||
#[macro_use]
|
||||
extern crate profile_traits;
|
||||
extern crate script_traits;
|
||||
extern crate selectors;
|
||||
|
|
|
@ -70,6 +70,7 @@ use net_traits::{ResourceTask, LoadConsumer, ControlMsg, Metadata};
|
|||
use net_traits::LoadData as NetLoadData;
|
||||
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask, ImageCacheResult};
|
||||
use net_traits::storage_task::StorageTask;
|
||||
use profile_traits::mem::{self, Report, Reporter, ReportsChan};
|
||||
use string_cache::Atom;
|
||||
use util::str::DOMString;
|
||||
use util::task::spawn_named_with_send_on_failure;
|
||||
|
@ -78,9 +79,10 @@ use util::task_state;
|
|||
use euclid::Rect;
|
||||
use euclid::point::Point2D;
|
||||
use hyper::header::{LastModified, Headers};
|
||||
use js::glue::CollectServoSizes;
|
||||
use js::jsapi::{JS_SetWrapObjectCallbacks, JS_AddExtraGCRootsTracer, DisableIncrementalGC};
|
||||
use js::jsapi::{JSContext, JSRuntime, JSTracer};
|
||||
use js::jsapi::{JS_SetGCCallback, JSGCStatus, JSAutoRequest, SetDOMCallbacks};
|
||||
use js::jsapi::{JS_GetRuntime, JS_SetGCCallback, JSGCStatus, JSAutoRequest, SetDOMCallbacks};
|
||||
use js::jsapi::{SetDOMProxyInformation, DOMProxyShadowsResult, HandleObject, HandleId, RootedValue};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::Runtime;
|
||||
|
@ -91,7 +93,7 @@ use std::any::Any;
|
|||
use std::borrow::ToOwned;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashSet;
|
||||
use std::mem;
|
||||
use std::mem as std_mem;
|
||||
use std::option::Option;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
@ -196,6 +198,9 @@ pub enum ScriptMsg {
|
|||
RefcountCleanup(TrustedReference),
|
||||
/// Notify a document that all pending loads are complete.
|
||||
DocumentLoadsComplete(PipelineId),
|
||||
/// Requests that the script task measure its memory usage. The results are sent back via the
|
||||
/// supplied channel.
|
||||
CollectReports(ReportsChan),
|
||||
}
|
||||
|
||||
/// A cloneable interface for communicating with an event loop.
|
||||
|
@ -247,6 +252,18 @@ impl NonWorkerScriptChan {
|
|||
let (chan, port) = channel();
|
||||
(port, box NonWorkerScriptChan(chan))
|
||||
}
|
||||
|
||||
fn clone_as_reporter(&self) -> Box<Reporter+Send> {
|
||||
let NonWorkerScriptChan(ref chan) = *self;
|
||||
box NonWorkerScriptChan((*chan).clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Reporter for NonWorkerScriptChan {
|
||||
// Just injects an appropriate event into the script task's queue.
|
||||
fn collect_reports(&self, reports_chan: ReportsChan) -> bool {
|
||||
self.send(ScriptMsg::CollectReports(reports_chan)).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StackRootTLS;
|
||||
|
@ -307,6 +324,9 @@ pub struct ScriptTask {
|
|||
/// The channel on which the image cache can send messages to ourself.
|
||||
image_cache_channel: ImageCacheChan,
|
||||
|
||||
/// For providing contact with the memory profiler.
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
|
||||
/// For providing instructions to an optional devtools server.
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
/// For receiving commands from an optional devtools server. Will be ignored if
|
||||
|
@ -387,6 +407,7 @@ impl ScriptTaskFactory for ScriptTask {
|
|||
resource_task: ResourceTask,
|
||||
storage_task: StorageTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
window_size: Option<WindowSizeData>,
|
||||
load_data: LoadData) {
|
||||
|
@ -396,15 +417,18 @@ impl ScriptTaskFactory for ScriptTask {
|
|||
spawn_named_with_send_on_failure(format!("ScriptTask {:?}", id), task_state::SCRIPT, move || {
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
let chan = NonWorkerScriptChan(script_chan);
|
||||
let reporter = chan.clone_as_reporter();
|
||||
let script_task = ScriptTask::new(compositor,
|
||||
script_port,
|
||||
NonWorkerScriptChan(script_chan),
|
||||
chan,
|
||||
control_chan,
|
||||
control_port,
|
||||
constellation_chan,
|
||||
resource_task,
|
||||
storage_task,
|
||||
image_cache_task,
|
||||
mem_profiler_chan.clone(),
|
||||
devtools_chan);
|
||||
|
||||
SCRIPT_TASK_ROOT.with(|root| {
|
||||
|
@ -417,8 +441,17 @@ 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 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);
|
||||
|
||||
// This must always be the very last operation performed before the task completes
|
||||
failsafe.neuter();
|
||||
}, ConstellationMsg::Failure(failure_msg), const_chan);
|
||||
|
@ -473,6 +506,7 @@ impl ScriptTask {
|
|||
resource_task: ResourceTask,
|
||||
storage_task: StorageTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>)
|
||||
-> ScriptTask {
|
||||
let runtime = ScriptTask::new_rt_and_cx();
|
||||
|
@ -502,6 +536,8 @@ impl ScriptTask {
|
|||
control_port: control_port,
|
||||
constellation_chan: constellation_chan,
|
||||
compositor: DOMRefCell::new(compositor),
|
||||
mem_profiler_chan: mem_profiler_chan,
|
||||
|
||||
devtools_chan: devtools_chan,
|
||||
devtools_port: devtools_receiver,
|
||||
devtools_sender: devtools_sender,
|
||||
|
@ -783,6 +819,8 @@ impl ScriptTask {
|
|||
LiveDOMReferences::cleanup(addr),
|
||||
ScriptMsg::DocumentLoadsComplete(id) =>
|
||||
self.handle_loads_complete(id),
|
||||
ScriptMsg::CollectReports(reports_chan) =>
|
||||
self.collect_reports(reports_chan),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -989,6 +1027,40 @@ impl ScriptTask {
|
|||
chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap();
|
||||
}
|
||||
|
||||
pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec<Report> {
|
||||
let mut reports = vec![];
|
||||
|
||||
unsafe {
|
||||
let rt = JS_GetRuntime(cx);
|
||||
let mut stats = ::std::mem::zeroed();
|
||||
if CollectServoSizes(rt, &mut stats) {
|
||||
let mut report = |mut path_suffix, size| {
|
||||
let mut path = path!["pages", path_seg, "js"];
|
||||
path.append(&mut path_suffix);
|
||||
reports.push(Report { path: path, size: size as usize })
|
||||
};
|
||||
|
||||
report(path!["gc-heap", "used"], stats.gcHeapUsed);
|
||||
report(path!["gc-heap", "unused"], stats.gcHeapUnused);
|
||||
report(path!["gc-heap", "admin"], stats.gcHeapAdmin);
|
||||
report(path!["gc-heap", "decommitted"], stats.gcHeapDecommitted);
|
||||
report(path!["malloc-heap"], stats.mallocHeap);
|
||||
report(path!["non-heap"], stats.nonHeap);
|
||||
}
|
||||
}
|
||||
reports
|
||||
}
|
||||
|
||||
fn collect_reports(&self, reports_chan: ReportsChan) {
|
||||
let mut urls = vec![];
|
||||
for it_page in self.root_page().iter() {
|
||||
urls.push(it_page.document().url().serialize());
|
||||
}
|
||||
let path_seg = format!("url({})", urls.connect(", "));
|
||||
let reports = ScriptTask::get_reports(self.get_cx(), path_seg);
|
||||
reports_chan.send(reports);
|
||||
}
|
||||
|
||||
/// Handles a timer that fired.
|
||||
fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) {
|
||||
let page = self.root_page();
|
||||
|
@ -1287,6 +1359,7 @@ impl ScriptTask {
|
|||
self.image_cache_task.clone(),
|
||||
self.resource_task.clone(),
|
||||
self.storage_task.clone(),
|
||||
self.mem_profiler_chan.clone(),
|
||||
self.devtools_chan.clone(),
|
||||
self.constellation_chan.clone(),
|
||||
incomplete.layout_chan,
|
||||
|
@ -1429,9 +1502,9 @@ impl ScriptTask {
|
|||
// We temporarily steal the list of targets over which the mouse is to pass it to
|
||||
// handle_mouse_move_event() in a safe RootedVec container.
|
||||
let mut mouse_over_targets = RootedVec::new();
|
||||
mem::swap(&mut *self.mouse_over_targets.borrow_mut(), &mut *mouse_over_targets);
|
||||
std_mem::swap(&mut *self.mouse_over_targets.borrow_mut(), &mut *mouse_over_targets);
|
||||
document.r().handle_mouse_move_event(self.js_runtime.rt(), point, &mut mouse_over_targets);
|
||||
mem::swap(&mut *self.mouse_over_targets.borrow_mut(), &mut *mouse_over_targets);
|
||||
std_mem::swap(&mut *self.mouse_over_targets.borrow_mut(), &mut *mouse_over_targets);
|
||||
}
|
||||
|
||||
KeyEvent(key, state, modifiers) => {
|
||||
|
|
|
@ -13,6 +13,9 @@ path = "../msg"
|
|||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
||||
[dependencies.profile_traits]
|
||||
path = "../profile_traits"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ extern crate ipc_channel;
|
|||
extern crate libc;
|
||||
extern crate msg;
|
||||
extern crate net_traits;
|
||||
extern crate profile_traits;
|
||||
extern crate serde;
|
||||
extern crate util;
|
||||
extern crate url;
|
||||
|
@ -32,6 +33,7 @@ use msg::webdriver_msg::WebDriverScriptCommand;
|
|||
use net_traits::ResourceTask;
|
||||
use net_traits::image_cache_task::ImageCacheTask;
|
||||
use net_traits::storage_task::StorageTask;
|
||||
use profile_traits::mem;
|
||||
use std::any::Any;
|
||||
use std::sync::mpsc::{Sender, Receiver};
|
||||
use url::Url;
|
||||
|
@ -190,6 +192,7 @@ pub trait ScriptTaskFactory {
|
|||
resource_task: ResourceTask,
|
||||
storage_task: StorageTask,
|
||||
image_cache_task: ImageCacheTask,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<DevtoolsControlChan>,
|
||||
window_size: Option<WindowSizeData>,
|
||||
load_data: LoadData);
|
||||
|
|
|
@ -648,7 +648,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "js"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-mozjs#f59c04795c84b82e00fdbd694bed90c56fa6567a"
|
||||
source = "git+https://github.com/servo/rust-mozjs#9509978ed1e767c6cbf3da1886ab618f3fa58585"
|
||||
dependencies = [
|
||||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -821,7 +821,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs_sys"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/servo/mozjs#2c918d1fb803673f5e5aca230034f77e85455448"
|
||||
source = "git+https://github.com/servo/mozjs#065c9a4268ae51288e946b9dbf1c233f1dcf5ca3"
|
||||
|
||||
[[package]]
|
||||
name = "msg"
|
||||
|
@ -1178,6 +1178,7 @@ dependencies = [
|
|||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"serde 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -111,8 +111,8 @@ impl Browser {
|
|||
let constellation_chan = create_constellation(opts.clone(),
|
||||
compositor_proxy.clone_compositor_proxy(),
|
||||
time_profiler_chan.clone(),
|
||||
devtools_chan,
|
||||
mem_profiler_chan.clone(),
|
||||
devtools_chan,
|
||||
supports_clipboard);
|
||||
|
||||
if let Some(port) = opts.webdriver_port {
|
||||
|
@ -157,8 +157,8 @@ impl Browser {
|
|||
fn create_constellation(opts: opts::Opts,
|
||||
compositor_proxy: Box<CompositorProxy+Send>,
|
||||
time_profiler_chan: time::ProfilerChan,
|
||||
devtools_chan: Option<Sender<devtools_traits::DevtoolsControlMsg>>,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<Sender<devtools_traits::DevtoolsControlMsg>>,
|
||||
supports_clipboard: bool) -> ConstellationChan {
|
||||
let resource_task = new_resource_task(opts.user_agent.clone(), devtools_chan.clone());
|
||||
|
||||
|
|
|
@ -640,7 +640,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "js"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-mozjs#f59c04795c84b82e00fdbd694bed90c56fa6567a"
|
||||
source = "git+https://github.com/servo/rust-mozjs#9509978ed1e767c6cbf3da1886ab618f3fa58585"
|
||||
dependencies = [
|
||||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -813,7 +813,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs_sys"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/servo/mozjs#2c918d1fb803673f5e5aca230034f77e85455448"
|
||||
source = "git+https://github.com/servo/mozjs#065c9a4268ae51288e946b9dbf1c233f1dcf5ca3"
|
||||
|
||||
[[package]]
|
||||
name = "msg"
|
||||
|
@ -1150,6 +1150,7 @@ dependencies = [
|
|||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"serde 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -574,7 +574,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "js"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/servo/rust-mozjs#f59c04795c84b82e00fdbd694bed90c56fa6567a"
|
||||
source = "git+https://github.com/servo/rust-mozjs#9509978ed1e767c6cbf3da1886ab618f3fa58585"
|
||||
dependencies = [
|
||||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -739,7 +739,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs_sys"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/servo/mozjs#2c918d1fb803673f5e5aca230034f77e85455448"
|
||||
source = "git+https://github.com/servo/mozjs#065c9a4268ae51288e946b9dbf1c233f1dcf5ca3"
|
||||
|
||||
[[package]]
|
||||
name = "msg"
|
||||
|
@ -1058,6 +1058,7 @@ dependencies = [
|
|||
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
"profile_traits 0.0.1",
|
||||
"serde 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
Загрузка…
Ссылка в новой задаче