mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Refactor common infrastructure for creating memory reports. (#36579)
This removes a bunch of duplicated code needed to support ConditionalMallocSizeOf correctly, and fixes multiple places where that code was subtly wrong (the seen pointers hashset was never cleared). Testing: Measuring https://www.nist.gov/image-gallery lots of times. Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
2a81987590
commit
5e2d42e944
11 changed files with 68 additions and 57 deletions
|
@ -2,10 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::{LazyCell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ffi::c_void;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{mem, thread};
|
||||
|
||||
|
@ -460,15 +458,8 @@ impl ImageCache for ImageCacheImpl {
|
|||
}
|
||||
}
|
||||
|
||||
fn memory_report(&self, prefix: &str) -> Report {
|
||||
let seen_pointer =
|
||||
move |ptr| SEEN_POINTERS.with(|pointers| !pointers.borrow_mut().insert(ptr));
|
||||
let mut ops = MallocSizeOfOps::new(
|
||||
servo_allocator::usable_size,
|
||||
None,
|
||||
Some(Box::new(seen_pointer)),
|
||||
);
|
||||
let size = self.store.lock().unwrap().size_of(&mut ops);
|
||||
fn memory_report(&self, prefix: &str, ops: &mut MallocSizeOfOps) -> Report {
|
||||
let size = self.store.lock().unwrap().size_of(ops);
|
||||
Report {
|
||||
path: path![prefix, "image-cache"],
|
||||
kind: ReportKind::ExplicitSystemHeapSize,
|
||||
|
@ -678,7 +669,3 @@ impl ImageCacheImpl {
|
|||
warn!("Couldn't find cached entry for listener {:?}", id);
|
||||
}
|
||||
}
|
||||
|
||||
thread_local!(static SEEN_POINTERS: LazyCell<RefCell<HashSet<*const c_void>>> = const {
|
||||
LazyCell::new(|| RefCell::new(HashSet::new()))
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue