diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-06-03 16:37:53 +0000 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2019-06-25 13:11:25 +0200 |
commit | ef99ab1f08db3b9df7c6580b1984585cb7be6fff (patch) | |
tree | 6b8e1e94fb4956f9a47cd3d5a8a114988ef9643b /components/style/rule_tree/mod.rs | |
parent | 9721bd7d0d590050c35e507a1cf3e7a80b134e88 (diff) | |
download | servo-ef99ab1f08db3b9df7c6580b1984585cb7be6fff.tar.gz servo-ef99ab1f08db3b9df7c6580b1984585cb7be6fff.zip |
style: Report heap size of rule tree heap allocations as well.
Differential Revision: https://phabricator.services.mozilla.com/D33353
Diffstat (limited to 'components/style/rule_tree/mod.rs')
-rw-r--r-- | components/style/rule_tree/mod.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index f4d62e4ce2a..8f255898fc8 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -14,8 +14,7 @@ use crate::properties::{Importance, LonghandIdSet, PropertyDeclarationBlock}; use crate::shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards}; use crate::stylesheets::{Origin, StyleRule}; use crate::thread_state; -#[cfg(feature = "gecko")] -use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; +use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps}; use parking_lot::RwLock; use servo_arc::{Arc, ArcBorrow, ArcUnion, ArcUnionBorrow}; use smallvec::SmallVec; @@ -46,7 +45,6 @@ use std::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; /// logs from http://logs.glob.uno/?c=mozilla%23servo&s=3+Apr+2017&e=3+Apr+2017#c644094 /// to se a discussion about the different memory orderings used here. #[derive(Debug)] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] pub struct RuleTree { root: StrongRuleNode, } @@ -74,7 +72,6 @@ impl Drop for RuleTree { } } -#[cfg(feature = "gecko")] impl MallocSizeOf for RuleTree { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { let mut n = 0; @@ -83,9 +80,9 @@ impl MallocSizeOf for RuleTree { while let Some(node) = stack.pop() { n += unsafe { ops.malloc_size_of(node.ptr()) }; - unsafe { - (*node.ptr()).children.read().each(|c| stack.push(c.clone())); - } + let children = unsafe { (*node.ptr()).children.read() }; + children.shallow_size_of(ops); + children.each(|c| stack.push(c.clone())); } n @@ -769,6 +766,18 @@ enum RuleNodeChildren { Map(Box<FxHashMap<ChildKey, WeakRuleNode>>), } +impl MallocShallowSizeOf for RuleNodeChildren { + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + match *self { + RuleNodeChildren::One(..) | RuleNodeChildren::Empty => 0, + RuleNodeChildren::Map(ref m) => { + // Want to account for both the box and the hashmap. + m.shallow_size_of(ops) + (**m).shallow_size_of(ops) + }, + } + } +} + impl Default for RuleNodeChildren { fn default() -> Self { RuleNodeChildren::Empty |