mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Measure memory usage of Stylo's Rule Tree.
This commit is contained in:
parent
5dee83d54d
commit
e08829703a
7 changed files with 126 additions and 10 deletions
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue