aboutsummaryrefslogtreecommitdiffstats
path: root/components/net
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2025-05-20 10:50:02 -0400
committerGitHub <noreply@github.com>2025-05-20 14:50:02 +0000
commit603ae44bcd72c67d19db0b2c74e7644e4d202c6f (patch)
tree609c3a55a08e8777f4795d9b509bff7712a1003e /components/net
parent5b2305784aa45439ba5e8584ab450507c90a64bd (diff)
downloadservo-603ae44bcd72c67d19db0b2c74e7644e4d202c6f.tar.gz
servo-603ae44bcd72c67d19db0b2c74e7644e4d202c6f.zip
net: Measure memory usage of storage thread. (#37053)
Our persistent localstorage data can be meaningfully large after testing real world sites. This change ensures it shows up in about:memory. Testing: Opened about:memory after launching the browser with a persistent config Fixes: Part of #11559 Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Diffstat (limited to 'components/net')
-rw-r--r--components/net/resource_thread.rs5
-rw-r--r--components/net/storage_thread.rs42
2 files changed, 42 insertions, 5 deletions
diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs
index 8e9cc8236f3..94592d19bed 100644
--- a/components/net/resource_thread.rs
+++ b/components/net/resource_thread.rs
@@ -97,14 +97,15 @@ pub fn new_resource_threads(
let (public_core, private_core) = new_core_resource_thread(
devtools_sender,
time_profiler_chan,
- mem_profiler_chan,
+ mem_profiler_chan.clone(),
embedder_proxy,
config_dir.clone(),
ca_certificates,
ignore_certificate_errors,
protocols,
);
- let storage: IpcSender<StorageThreadMsg> = StorageThreadFactory::new(config_dir);
+ let storage: IpcSender<StorageThreadMsg> =
+ StorageThreadFactory::new(config_dir, mem_profiler_chan);
(
ResourceThreads::new(public_core, storage.clone()),
ResourceThreads::new(private_core, storage),
diff --git a/components/net/storage_thread.rs b/components/net/storage_thread.rs
index dd058f17170..899214a450c 100644
--- a/components/net/storage_thread.rs
+++ b/components/net/storage_thread.rs
@@ -8,7 +8,12 @@ use std::path::PathBuf;
use std::thread;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
+use malloc_size_of::MallocSizeOf;
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
+use profile_traits::mem::{
+ ProcessReports, ProfilerChan as MemProfilerChan, Report, ReportKind, perform_memory_report,
+};
+use profile_traits::path;
use servo_url::ServoUrl;
use crate::resource_thread;
@@ -16,17 +21,26 @@ use crate::resource_thread;
const QUOTA_SIZE_LIMIT: usize = 5 * 1024 * 1024;
pub trait StorageThreadFactory {
- fn new(config_dir: Option<PathBuf>) -> Self;
+ fn new(config_dir: Option<PathBuf>, mem_profiler_chan: MemProfilerChan) -> Self;
}
impl StorageThreadFactory for IpcSender<StorageThreadMsg> {
/// Create a storage thread
- fn new(config_dir: Option<PathBuf>) -> IpcSender<StorageThreadMsg> {
+ fn new(
+ config_dir: Option<PathBuf>,
+ mem_profiler_chan: MemProfilerChan,
+ ) -> IpcSender<StorageThreadMsg> {
let (chan, port) = ipc::channel().unwrap();
+ let chan2 = chan.clone();
thread::Builder::new()
.name("StorageManager".to_owned())
.spawn(move || {
- StorageManager::new(port, config_dir).start();
+ mem_profiler_chan.run_with_memory_reporting(
+ || StorageManager::new(port, config_dir).start(),
+ String::from("storage-reporter"),
+ chan2,
+ StorageThreadMsg::CollectMemoryReport,
+ );
})
.expect("Thread spawning failed");
chan
@@ -83,6 +97,10 @@ impl StorageManager {
self.clear(sender, url, storage_type);
self.save_state()
},
+ StorageThreadMsg::CollectMemoryReport(sender) => {
+ let reports = self.collect_memory_reports();
+ sender.send(ProcessReports::new(reports));
+ },
StorageThreadMsg::Exit(sender) => {
// Nothing to do since we save localstorage set eagerly.
let _ = sender.send(());
@@ -92,6 +110,24 @@ impl StorageManager {
}
}
+ fn collect_memory_reports(&self) -> Vec<Report> {
+ let mut reports = vec![];
+ perform_memory_report(|ops| {
+ reports.push(Report {
+ path: path!["storage", "local"],
+ kind: ReportKind::ExplicitJemallocHeapSize,
+ size: self.local_data.size_of(ops),
+ });
+
+ reports.push(Report {
+ path: path!["storage", "session"],
+ kind: ReportKind::ExplicitJemallocHeapSize,
+ size: self.session_data.size_of(ops),
+ });
+ });
+ reports
+ }
+
fn save_state(&self) {
if let Some(ref config_dir) = self.config_dir {
resource_thread::write_json_to_file(&self.local_data, config_dir, "local_data.json");