mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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>
This commit is contained in:
parent
5b2305784a
commit
603ae44bcd
3 changed files with 46 additions and 5 deletions
|
@ -97,14 +97,15 @@ pub fn new_resource_threads(
|
||||||
let (public_core, private_core) = new_core_resource_thread(
|
let (public_core, private_core) = new_core_resource_thread(
|
||||||
devtools_sender,
|
devtools_sender,
|
||||||
time_profiler_chan,
|
time_profiler_chan,
|
||||||
mem_profiler_chan,
|
mem_profiler_chan.clone(),
|
||||||
embedder_proxy,
|
embedder_proxy,
|
||||||
config_dir.clone(),
|
config_dir.clone(),
|
||||||
ca_certificates,
|
ca_certificates,
|
||||||
ignore_certificate_errors,
|
ignore_certificate_errors,
|
||||||
protocols,
|
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(public_core, storage.clone()),
|
||||||
ResourceThreads::new(private_core, storage),
|
ResourceThreads::new(private_core, storage),
|
||||||
|
|
|
@ -8,7 +8,12 @@ use std::path::PathBuf;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||||
|
use malloc_size_of::MallocSizeOf;
|
||||||
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
|
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 servo_url::ServoUrl;
|
||||||
|
|
||||||
use crate::resource_thread;
|
use crate::resource_thread;
|
||||||
|
@ -16,17 +21,26 @@ use crate::resource_thread;
|
||||||
const QUOTA_SIZE_LIMIT: usize = 5 * 1024 * 1024;
|
const QUOTA_SIZE_LIMIT: usize = 5 * 1024 * 1024;
|
||||||
|
|
||||||
pub trait StorageThreadFactory {
|
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> {
|
impl StorageThreadFactory for IpcSender<StorageThreadMsg> {
|
||||||
/// Create a storage thread
|
/// 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 (chan, port) = ipc::channel().unwrap();
|
||||||
|
let chan2 = chan.clone();
|
||||||
thread::Builder::new()
|
thread::Builder::new()
|
||||||
.name("StorageManager".to_owned())
|
.name("StorageManager".to_owned())
|
||||||
.spawn(move || {
|
.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");
|
.expect("Thread spawning failed");
|
||||||
chan
|
chan
|
||||||
|
@ -83,6 +97,10 @@ impl StorageManager {
|
||||||
self.clear(sender, url, storage_type);
|
self.clear(sender, url, storage_type);
|
||||||
self.save_state()
|
self.save_state()
|
||||||
},
|
},
|
||||||
|
StorageThreadMsg::CollectMemoryReport(sender) => {
|
||||||
|
let reports = self.collect_memory_reports();
|
||||||
|
sender.send(ProcessReports::new(reports));
|
||||||
|
},
|
||||||
StorageThreadMsg::Exit(sender) => {
|
StorageThreadMsg::Exit(sender) => {
|
||||||
// Nothing to do since we save localstorage set eagerly.
|
// Nothing to do since we save localstorage set eagerly.
|
||||||
let _ = sender.send(());
|
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) {
|
fn save_state(&self) {
|
||||||
if let Some(ref config_dir) = self.config_dir {
|
if let Some(ref config_dir) = self.config_dir {
|
||||||
resource_thread::write_json_to_file(&self.local_data, config_dir, "local_data.json");
|
resource_thread::write_json_to_file(&self.local_data, config_dir, "local_data.json");
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
|
use profile_traits::mem::ReportsChan;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
|
||||||
|
@ -45,4 +46,7 @@ pub enum StorageThreadMsg {
|
||||||
|
|
||||||
/// send a reply when done cleaning up thread resources and then shut it down
|
/// send a reply when done cleaning up thread resources and then shut it down
|
||||||
Exit(IpcSender<()>),
|
Exit(IpcSender<()>),
|
||||||
|
|
||||||
|
/// Measure memory used by this thread and send the report over the provided channel.
|
||||||
|
CollectMemoryReport(ReportsChan),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue