Start reporting memory usage for Window and all nodes in all DOM trees for frame treese in script tasks.

This commit is contained in:
Josh Matthews 2015-07-31 12:46:36 -04:00
parent c2497fcd49
commit 8620fe5995
33 changed files with 317 additions and 107 deletions

View file

@ -21,6 +21,12 @@ path = "../plugins"
[dependencies.azure]
git = "https://github.com/servo/rust-azure"
[dependencies.js]
git = "https://github.com/servo/rust-mozjs"
[dependencies.layers]
git = "https://github.com/servo/rust-layers"
[dependencies.cssparser]
version = "0.3"
features = [ "serde-serialization" ]
@ -35,6 +41,7 @@ features = [ "serde_serialization" ]
[dependencies]
log = "0.3"
bitflags = "0.3"
html5ever = { version = "0.2.1", features = ["unstable"] }
libc = "0.1"
rand = "0.3"
rustc-serialize = "0.3"
@ -44,4 +51,5 @@ num = "0.1.24"
euclid = "0.1"
serde = "0.4"
serde_macros = "0.4"
string_cache = "0.1"
lazy_static = "0.1"

View file

@ -31,7 +31,10 @@ extern crate alloc;
#[macro_use] extern crate cssparser;
extern crate euclid;
extern crate getopts;
extern crate html5ever;
extern crate ipc_channel;
extern crate js;
extern crate layers;
extern crate libc;
extern crate num as num_lib;
extern crate num_cpus;
@ -39,6 +42,7 @@ extern crate rand;
extern crate rustc_serialize;
extern crate serde;
extern crate smallvec;
extern crate string_cache;
extern crate url;
use std::sync::Arc;

View file

@ -5,17 +5,30 @@
//! Data structure measurement.
use libc::{c_void, size_t};
use std::cell::RefCell;
use std::collections::LinkedList;
use std::mem::transmute;
use std::cell::{Cell, RefCell};
use std::collections::{HashMap, LinkedList, hash_state};
use std::hash::Hash;
use std::mem::{size_of, transmute};
use std::sync::Arc;
use std::rc::Rc;
use azure::azure_hl::Color;
use cssparser::Color as CSSParserColor;
use cssparser::RGBA;
use cursor::Cursor;
use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D, Matrix4};
use geometry::Au;
use euclid::length::Length;
use euclid::scale_factor::ScaleFactor;
use geometry::{PagePx, ViewportPx, Au};
use html5ever::tree_builder::QuirksMode;
use layers::geometry::DevicePixel;
use js::jsapi::Heap;
use js::rust::GCMethods;
use js::jsval::JSVal;
use logical_geometry::WritingMode;
use range::Range;
use string_cache::atom::Atom;
use url;
extern {
@ -129,6 +142,12 @@ impl HeapSizeOf for url::Host {
}
}
impl<T: HeapSizeOf, U: HeapSizeOf> HeapSizeOf for (T, U) {
fn heap_size_of_children(&self) -> usize {
self.0.heap_size_of_children() + self.1.heap_size_of_children()
}
}
impl<T: HeapSizeOf> HeapSizeOf for Arc<T> {
fn heap_size_of_children(&self) -> usize {
(**self).heap_size_of_children()
@ -141,6 +160,12 @@ impl<T: HeapSizeOf> HeapSizeOf for RefCell<T> {
}
}
impl<T: HeapSizeOf + Copy> HeapSizeOf for Cell<T> {
fn heap_size_of_children(&self) -> usize {
self.get().heap_size_of_children()
}
}
impl<T: HeapSizeOf> HeapSizeOf for Vec<T> {
fn heap_size_of_children(&self) -> usize {
heap_size_of(self.as_ptr() as *const c_void) +
@ -148,6 +173,25 @@ impl<T: HeapSizeOf> HeapSizeOf for Vec<T> {
}
}
impl<T> HeapSizeOf for Vec<Rc<T>> {
fn heap_size_of_children(&self) -> usize {
// The fate of measuring Rc<T> is still undecided, but we still want to measure
// the space used for storing them.
heap_size_of(self.as_ptr() as *const c_void)
}
}
impl<K: HeapSizeOf, V: HeapSizeOf, S> HeapSizeOf for HashMap<K, V, S>
where K: Eq + Hash, S: hash_state::HashState {
fn heap_size_of_children(&self) -> usize {
//TODO(#6908) measure actual bucket memory usage instead of approximating
let size = self.capacity() * (size_of::<V>() + size_of::<K>());
self.iter().fold(size, |n, (key, value)| {
n + key.heap_size_of_children() + value.heap_size_of_children()
})
}
}
// FIXME(njn): We can't implement HeapSizeOf accurately for LinkedList because it requires access
// to the private Node type. Eventually we'll want to add HeapSizeOf (or equivalent) to Rust
// itself. In the meantime, we use the dirty hack of transmuting LinkedList into an identical type
@ -242,7 +286,15 @@ known_heap_size!(0, u8, u16, u32, u64, usize);
known_heap_size!(0, i8, i16, i32, i64, isize);
known_heap_size!(0, bool, f32, f64);
known_heap_size!(0, Rect<T>, Point2D<T>, Size2D<T>, Matrix2D<T>, SideOffsets2D<T>);
known_heap_size!(0, Rect<T>, Point2D<T>, Size2D<T>, Matrix2D<T>, SideOffsets2D<T>, Range<T>);
known_heap_size!(0, Length<T, U>, ScaleFactor<T, U, V>);
known_heap_size!(0, Au, Color, Cursor, Matrix4);
known_heap_size!(0, Range<T>);
known_heap_size!(0, Au, WritingMode, CSSParserColor, Color, RGBA, Cursor, Matrix4, Atom);
known_heap_size!(0, JSVal, PagePx, ViewportPx, DevicePixel, QuirksMode);
// This is measured properly by the heap measurement implemented in SpiderMonkey.
impl<T: Copy + GCMethods<T>> HeapSizeOf for Heap<T> {
fn heap_size_of_children(&self) -> usize {
0
}
}