diff options
author | Josh Matthews <josh@joshmatthews.net> | 2025-04-16 09:11:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-16 13:11:44 +0000 |
commit | f16f625c9ba4aecf8a422c8ea5a2c9b18fe9944e (patch) | |
tree | 5a6a5a56521c8d48d19c52860d048be47ee4b408 /components/net | |
parent | 94a9588bcc2d6396f76cc5f7467d31f22c8b3791 (diff) | |
download | servo-f16f625c9ba4aecf8a422c8ea5a2c9b18fe9944e.tar.gz servo-f16f625c9ba4aecf8a422c8ea5a2c9b18fe9944e.zip |
net: Measure HSTS memory usage. (#36558)
Records the memory usage of the HSTS lists in the network thread.
Testing: Verified the presence of the new reports for servo.org.
Fixes: #35059
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Diffstat (limited to 'components/net')
-rw-r--r-- | components/net/hsts.rs | 5 | ||||
-rw-r--r-- | components/net/http_loader.rs | 18 | ||||
-rw-r--r-- | components/net/resource_thread.rs | 28 |
3 files changed, 27 insertions, 24 deletions
diff --git a/components/net/hsts.rs b/components/net/hsts.rs index 04282be2340..d74794ce60a 100644 --- a/components/net/hsts.rs +++ b/components/net/hsts.rs @@ -11,13 +11,14 @@ use embedder_traits::resources::{self, Resource}; use headers::{HeaderMapExt, StrictTransportSecurity}; use http::HeaderMap; use log::{error, info}; +use malloc_size_of_derive::MallocSizeOf; use net_traits::IncludeSubdomains; use net_traits::pub_domains::reg_suffix; use serde::{Deserialize, Serialize}; use servo_config::pref; use servo_url::{Host, ServoUrl}; -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)] pub struct HstsEntry { pub host: String, pub include_subdomains: bool, @@ -60,7 +61,7 @@ impl HstsEntry { } } -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, MallocSizeOf, Serialize)] pub struct HstsList { pub entries_map: HashMap<String, Vec<HstsEntry>>, } diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 29165a56015..35624bb8645 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -40,6 +40,7 @@ use hyper_util::client::legacy::Client; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; use log::{debug, error, info, log_enabled, warn}; +use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use net_traits::http_status::HttpStatus; use net_traits::pub_domains::reg_suffix; use net_traits::request::Origin::Origin as SpecificOrigin; @@ -55,6 +56,8 @@ use net_traits::{ CookieSource, DOCUMENT_ACCEPT_HEADER_VALUE, FetchMetadata, NetworkError, RedirectEndValue, RedirectStartValue, ReferrerPolicy, ResourceAttribute, ResourceFetchTiming, ResourceTimeValue, }; +use profile_traits::mem::{Report, ReportKind}; +use profile_traits::path; use servo_arc::Arc; use servo_url::{ImmutableOrigin, ServoUrl}; use tokio::sync::mpsc::{ @@ -105,6 +108,21 @@ pub struct HttpState { } impl HttpState { + pub(crate) fn memory_reports(&self, suffix: &str, ops: &mut MallocSizeOfOps) -> Vec<Report> { + vec![ + Report { + path: path!["memory-cache", suffix], + kind: ReportKind::ExplicitJemallocHeapSize, + size: self.http_cache.read().unwrap().size_of(ops), + }, + Report { + path: path!["hsts-list", suffix], + kind: ReportKind::ExplicitJemallocHeapSize, + size: self.hsts_list.read().unwrap().size_of(ops), + }, + ] + } + fn request_authentication( &self, request: &Request, diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs index 28934c94091..7235c362d66 100644 --- a/components/net/resource_thread.rs +++ b/components/net/resource_thread.rs @@ -21,7 +21,7 @@ use embedder_traits::EmbedderProxy; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcReceiver, IpcReceiverSet, IpcSender}; use log::{debug, trace, warn}; -use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; +use malloc_size_of::MallocSizeOfOps; use net_traits::blob_url_store::parse_blob_url; use net_traits::filemanager_thread::FileTokenCheck; use net_traits::request::{Destination, RequestBuilder, RequestId}; @@ -32,10 +32,7 @@ use net_traits::{ FetchChannels, FetchTaskTarget, ResourceFetchTiming, ResourceThreads, ResourceTimingType, WebSocketDomAction, WebSocketNetworkEvent, }; -use profile_traits::mem::{ - ProcessReports, ProfilerChan as MemProfilerChan, Report, ReportKind, ReportsChan, -}; -use profile_traits::path; +use profile_traits::mem::{ProcessReports, ProfilerChan as MemProfilerChan, ReportsChan}; use profile_traits::time::ProfilerChan; use rustls::RootCertStore; use serde::{Deserialize, Serialize}; @@ -257,7 +254,7 @@ impl ResourceChannelManager { // If message is memory report, get the size_of of public and private http caches if id == reporter_id { if let Ok(msg) = data.to() { - self.process_report(msg, &private_http_state, &public_http_state); + self.process_report(msg, &public_http_state, &private_http_state); continue; } } else { @@ -284,22 +281,9 @@ impl ResourceChannelManager { private_http_state: &Arc<HttpState>, ) { let mut ops = MallocSizeOfOps::new(servo_allocator::usable_size, None, None); - let public_cache = public_http_state.http_cache.read().unwrap(); - let private_cache = private_http_state.http_cache.read().unwrap(); - - let public_report = Report { - path: path!["memory-cache", "public"], - kind: ReportKind::ExplicitJemallocHeapSize, - size: public_cache.size_of(&mut ops), - }; - - let private_report = Report { - path: path!["memory-cache", "private"], - kind: ReportKind::ExplicitJemallocHeapSize, - size: private_cache.size_of(&mut ops), - }; - - msg.send(ProcessReports::new(vec![public_report, private_report])); + let mut reports = public_http_state.memory_reports("public", &mut ops); + reports.extend(private_http_state.memory_reports("private", &mut ops)); + msg.send(ProcessReports::new(reports)); } fn cancellation_listener(&self, request_id: RequestId) -> Option<Arc<CancellationListener>> { |