aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-08-31 00:31:31 -0500
committerGitHub <noreply@github.com>2017-08-31 00:31:31 -0500
commitd795ceae17b2ce5346d4f211f73c62e5c25dce79 (patch)
treefa09e6aea66f66c58c0c207c80daaf041348bf95
parent5624c0e3f16e0057bb228627eaf9018ef88e7786 (diff)
parente08829703afe44fffb2940ceaddd2b893647ea48 (diff)
downloadservo-d795ceae17b2ce5346d4f211f73c62e5c25dce79.tar.gz
servo-d795ceae17b2ce5346d4f211f73c62e5c25dce79.zip
Auto merge of #18310 - nnethercote:bug-1394729, r=heycam
Measure memory usage of Stylo's Rule Tree. <!-- Please describe your changes on the following line: --> This is for https://bugzilla.mozilla.org/show_bug.cgi?id=1394729, which was r=heycam. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because tests exist in Gecko. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18310) <!-- Reviewable:end -->
-rw-r--r--components/style/gecko/data.rs14
-rw-r--r--components/style/gecko/generated/bindings.rs6
-rw-r--r--components/style/gecko/generated/structs_debug.rs32
-rw-r--r--components/style/gecko/generated/structs_release.rs32
-rw-r--r--components/style/rule_tree/mod.rs16
-rw-r--r--components/style/stylist.rs17
-rw-r--r--ports/geckolib/glue.rs19
7 files changed, 126 insertions, 10 deletions
diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs
index 7c1bb6f68e3..67bbcc26a44 100644
--- a/components/style/gecko/data.rs
+++ b/components/style/gecko/data.rs
@@ -7,8 +7,8 @@
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use dom::TElement;
use gecko_bindings::bindings::{self, RawServoStyleSet};
-use gecko_bindings::structs::{ServoStyleSheet, StyleSheetInfo, ServoStyleSheetInner};
-use gecko_bindings::structs::RawGeckoPresContextOwned;
+use gecko_bindings::structs::{RawGeckoPresContextOwned, ServoStyleSetSizes, ServoStyleSheet};
+use gecko_bindings::structs::{StyleSheetInfo, ServoStyleSheetInner};
use gecko_bindings::structs::nsIDocument;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
@@ -16,7 +16,7 @@ use media_queries::{Device, MediaList};
use properties::ComputedValues;
use servo_arc::Arc;
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
-use stylesheets::{PerOrigin, StylesheetContents, StylesheetInDocument};
+use stylesheets::{MallocSizeOfFn, PerOrigin, StylesheetContents, StylesheetInDocument};
use stylist::{ExtraStyleData, Stylist};
/// Little wrapper to a Gecko style sheet.
@@ -184,6 +184,14 @@ impl PerDocumentStyleDataImpl {
pub fn visited_styles_enabled(&self) -> bool {
self.visited_links_enabled() && !self.is_private_browsing_enabled()
}
+
+ /// Measures heap usage.
+ pub fn malloc_add_size_of_children(&self, malloc_size_of: MallocSizeOfFn,
+ sizes: &mut ServoStyleSetSizes) {
+ self.stylist.malloc_add_size_of_children(malloc_size_of, sizes);
+
+ // We may measure more fields in the future if DMD says it's worth it.
+ }
}
unsafe impl HasFFI for PerDocumentStyleData {
diff --git a/components/style/gecko/generated/bindings.rs b/components/style/gecko/generated/bindings.rs
index c76b1d11ce1..a0da289b765 100644
--- a/components/style/gecko/generated/bindings.rs
+++ b/components/style/gecko/generated/bindings.rs
@@ -61,6 +61,7 @@ use gecko_bindings::structs::SeenPtrs;
use gecko_bindings::structs::ServoBundledURI;
use gecko_bindings::structs::ServoElementSnapshot;
use gecko_bindings::structs::ServoElementSnapshotTable;
+use gecko_bindings::structs::ServoStyleSetSizes;
use gecko_bindings::structs::SheetParsingMode;
use gecko_bindings::structs::StyleBasicShape;
use gecko_bindings::structs::StyleBasicShapeType;
@@ -2068,6 +2069,11 @@ extern "C" {
-> ServoStyleContextStrong;
}
extern "C" {
+ pub fn Servo_StyleSet_AddSizeOfExcludingThis(malloc_size_of: MallocSizeOf,
+ sizes: *mut ServoStyleSetSizes,
+ set: RawServoStyleSetBorrowed);
+}
+extern "C" {
pub fn Servo_StyleContext_AddRef(ctx: ServoStyleContextBorrowed);
}
extern "C" {
diff --git a/components/style/gecko/generated/structs_debug.rs b/components/style/gecko/generated/structs_debug.rs
index ff7d3d0436d..ba87266ca7d 100644
--- a/components/style/gecko/generated/structs_debug.rs
+++ b/components/style/gecko/generated/structs_debug.rs
@@ -5456,6 +5456,38 @@ pub mod root {
"Alignment of field: " , stringify ! ( GeckoEffects )
, "::" , stringify ! ( gecko ) ));
}
+ #[repr(C)]
+ #[derive(Debug, Copy)]
+ pub struct ServoStyleSetSizes {
+ pub mStylistRuleTree: usize,
+ pub mOther: usize,
+ }
+ #[test]
+ fn bindgen_test_layout_ServoStyleSetSizes() {
+ assert_eq!(::std::mem::size_of::<ServoStyleSetSizes>() , 16usize ,
+ concat ! (
+ "Size of: " , stringify ! ( ServoStyleSetSizes ) ));
+ assert_eq! (::std::mem::align_of::<ServoStyleSetSizes>() , 8usize
+ , concat ! (
+ "Alignment of " , stringify ! ( ServoStyleSetSizes )
+ ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const ServoStyleSetSizes ) ) .
+ mStylistRuleTree as * const _ as usize } , 0usize ,
+ concat ! (
+ "Alignment of field: " , stringify ! (
+ ServoStyleSetSizes ) , "::" , stringify ! (
+ mStylistRuleTree ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const ServoStyleSetSizes ) ) . mOther
+ as * const _ as usize } , 8usize , concat ! (
+ "Alignment of field: " , stringify ! (
+ ServoStyleSetSizes ) , "::" , stringify ! ( mOther )
+ ));
+ }
+ impl Clone for ServoStyleSetSizes {
+ fn clone(&self) -> Self { *self }
+ }
#[repr(u8)]
/// Enumeration that represents one of the two supported style system backends.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
diff --git a/components/style/gecko/generated/structs_release.rs b/components/style/gecko/generated/structs_release.rs
index 6a7e959abc6..0f735b985d3 100644
--- a/components/style/gecko/generated/structs_release.rs
+++ b/components/style/gecko/generated/structs_release.rs
@@ -5344,6 +5344,38 @@ pub mod root {
"Alignment of field: " , stringify ! ( GeckoEffects )
, "::" , stringify ! ( gecko ) ));
}
+ #[repr(C)]
+ #[derive(Debug, Copy)]
+ pub struct ServoStyleSetSizes {
+ pub mStylistRuleTree: usize,
+ pub mOther: usize,
+ }
+ #[test]
+ fn bindgen_test_layout_ServoStyleSetSizes() {
+ assert_eq!(::std::mem::size_of::<ServoStyleSetSizes>() , 16usize ,
+ concat ! (
+ "Size of: " , stringify ! ( ServoStyleSetSizes ) ));
+ assert_eq! (::std::mem::align_of::<ServoStyleSetSizes>() , 8usize
+ , concat ! (
+ "Alignment of " , stringify ! ( ServoStyleSetSizes )
+ ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const ServoStyleSetSizes ) ) .
+ mStylistRuleTree as * const _ as usize } , 0usize ,
+ concat ! (
+ "Alignment of field: " , stringify ! (
+ ServoStyleSetSizes ) , "::" , stringify ! (
+ mStylistRuleTree ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const ServoStyleSetSizes ) ) . mOther
+ as * const _ as usize } , 8usize , concat ! (
+ "Alignment of field: " , stringify ! (
+ ServoStyleSetSizes ) , "::" , stringify ! ( mOther )
+ ));
+ }
+ impl Clone for ServoStyleSetSizes {
+ fn clone(&self) -> Self { *self }
+ }
#[repr(u8)]
/// Enumeration that represents one of the two supported style system backends.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs
index ceb94aa15f6..7e76d3b34d4 100644
--- a/components/style/rule_tree/mod.rs
+++ b/components/style/rule_tree/mod.rs
@@ -17,7 +17,7 @@ use std::io::{self, Write};
use std::mem;
use std::ptr;
use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
-use stylesheets::StyleRule;
+use stylesheets::{MallocSizeOf, MallocSizeOfFn, StyleRule};
use thread_state;
/// The rule tree, the structure servo uses to preserve the results of selector
@@ -62,6 +62,12 @@ impl Drop for RuleTree {
}
}
+impl MallocSizeOf for RuleTree {
+ fn malloc_size_of_children(&self, malloc_size_of: MallocSizeOfFn) -> usize {
+ self.root.get().malloc_size_of_including_self(malloc_size_of)
+ }
+}
+
/// A style source for the rule node. It can either be a CSS style rule or a
/// declaration block.
///
@@ -781,6 +787,14 @@ impl RuleNode {
}
}
}
+
+ fn malloc_size_of_including_self(&self, malloc_size_of: MallocSizeOfFn) -> usize {
+ let mut n = unsafe { malloc_size_of(self as *const _ as *const _) };
+ for child in self.iter_children() {
+ n += unsafe { (*child.ptr()).malloc_size_of_including_self(malloc_size_of) };
+ }
+ n
+ }
}
#[derive(Clone)]
diff --git a/components/style/stylist.rs b/components/style/stylist.rs
index d330c58cef3..3e9aea16f39 100644
--- a/components/style/stylist.rs
+++ b/components/style/stylist.rs
@@ -12,7 +12,7 @@ use dom::TElement;
use element_state::ElementState;
use font_metrics::FontMetricsProvider;
#[cfg(feature = "gecko")]
-use gecko_bindings::structs::{nsIAtom, StyleRuleInclusion};
+use gecko_bindings::structs::{nsIAtom, ServoStyleSetSizes, StyleRuleInclusion};
use invalidation::element::invalidation_map::InvalidationMap;
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
use media_queries::Device;
@@ -41,8 +41,11 @@ use style_traits::viewport::ViewportConstraints;
use stylesheet_set::{OriginValidity, SheetRebuildKind, StylesheetSet, StylesheetIterator, StylesheetFlusher};
#[cfg(feature = "gecko")]
use stylesheets::{CounterStyleRule, FontFaceRule, FontFeatureValuesRule};
-use stylesheets::{CssRule, StyleRule};
-use stylesheets::{StylesheetInDocument, Origin, OriginSet, PerOrigin, PerOriginIter};
+use stylesheets::{CssRule, Origin, OriginSet, PerOrigin, PerOriginIter};
+#[cfg(feature = "gecko")]
+use stylesheets::{MallocSizeOf, MallocSizeOfFn};
+use stylesheets::StyleRule;
+use stylesheets::StylesheetInDocument;
use stylesheets::UserAgentStylesheets;
use stylesheets::keyframes_rule::KeyframesAnimation;
use stylesheets::viewport_rule::{self, MaybeNew, ViewportRule};
@@ -1560,6 +1563,14 @@ impl Stylist {
pub fn rule_tree(&self) -> &RuleTree {
&self.rule_tree
}
+
+ /// Measures heap usage.
+ #[cfg(feature = "gecko")]
+ pub fn malloc_add_size_of_children(&self, malloc_size_of: MallocSizeOfFn,
+ sizes: &mut ServoStyleSetSizes) {
+ // XXX: need to measure other fields
+ sizes.mStylistRuleTree += self.rule_tree.malloc_size_of_children(malloc_size_of);
+ }
}
/// This struct holds data which users of Stylist may want to extract
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs
index 354bd3c194a..58ee5d3ec1f 100644
--- a/ports/geckolib/glue.rs
+++ b/ports/geckolib/glue.rs
@@ -77,7 +77,7 @@ use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsIAtom,
use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair};
use style::gecko_bindings::structs::IterationCompositeOperation;
-use style::gecko_bindings::structs::MallocSizeOf;
+use style::gecko_bindings::structs::MallocSizeOf as GeckoMallocSizeOf;
use style::gecko_bindings::structs::OriginFlags;
use style::gecko_bindings::structs::OriginFlags_Author;
use style::gecko_bindings::structs::OriginFlags_User;
@@ -86,6 +86,7 @@ use style::gecko_bindings::structs::RawGeckoGfxMatrix4x4;
use style::gecko_bindings::structs::RawGeckoPresContextOwned;
use style::gecko_bindings::structs::SeenPtrs;
use style::gecko_bindings::structs::ServoElementSnapshotTable;
+use style::gecko_bindings::structs::ServoStyleSetSizes;
use style::gecko_bindings::structs::ServoTraversalFlags;
use style::gecko_bindings::structs::StyleRuleInclusion;
use style::gecko_bindings::structs::URLExtraData;
@@ -771,7 +772,7 @@ pub extern "C" fn Servo_Element_ClearData(element: RawGeckoElementBorrowed) {
}
#[no_mangle]
-pub extern "C" fn Servo_Element_SizeOfExcludingThisAndCVs(malloc_size_of: MallocSizeOf,
+pub extern "C" fn Servo_Element_SizeOfExcludingThisAndCVs(malloc_size_of: GeckoMallocSizeOf,
seen_ptrs: *mut SeenPtrs,
element: RawGeckoElementBorrowed) -> usize {
let malloc_size_of = malloc_size_of.unwrap();
@@ -1055,7 +1056,7 @@ pub extern "C" fn Servo_StyleSheet_Clone(
#[no_mangle]
pub extern "C" fn Servo_StyleSheet_SizeOfIncludingThis(
- malloc_size_of: MallocSizeOf,
+ malloc_size_of: GeckoMallocSizeOf,
sheet: RawServoStyleSheetContentsBorrowed
) -> usize {
let global_style_data = &*GLOBAL_STYLE_DATA;
@@ -3584,6 +3585,18 @@ pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
}
#[no_mangle]
+pub extern "C" fn Servo_StyleSet_AddSizeOfExcludingThis(
+ malloc_size_of: GeckoMallocSizeOf,
+ sizes: *mut ServoStyleSetSizes,
+ raw_data: RawServoStyleSetBorrowed
+) {
+ let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
+ let malloc_size_of = malloc_size_of.unwrap();
+ let sizes = unsafe { sizes.as_mut() }.unwrap();
+ data.malloc_add_size_of_children(malloc_size_of, sizes);
+}
+
+#[no_mangle]
pub extern "C" fn Servo_StyleSet_MightHaveAttributeDependency(
raw_data: RawServoStyleSetBorrowed,
element: RawGeckoElementBorrowed,