diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | components/malloc_size_of/lib.rs | 4 | ||||
-rw-r--r-- | components/metrics/Cargo.toml | 1 | ||||
-rw-r--r-- | components/metrics/lib.rs | 32 | ||||
-rw-r--r-- | components/script/dom/performanceresourcetiming.rs | 2 | ||||
-rw-r--r-- | components/shared/net/Cargo.toml | 1 | ||||
-rw-r--r-- | components/shared/net/lib.rs | 31 | ||||
-rw-r--r-- | tests/unit/metrics/interactive_time.rs | 7 |
8 files changed, 53 insertions, 27 deletions
diff --git a/Cargo.lock b/Cargo.lock index 59d6ffc9b0a..33e4602589f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3644,7 +3644,6 @@ dependencies = [ "script_traits", "servo_config", "servo_url", - "time 0.1.45", ] [[package]] @@ -3928,7 +3927,6 @@ dependencies = [ "servo_arc", "servo_rand", "servo_url", - "time 0.1.45", "url", "uuid", "webrender_api", diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index d9aff95912d..32bcfd9145f 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -892,6 +892,10 @@ impl MallocSizeOf for xml5ever::QualName { malloc_size_of_is_0!(time::Duration); #[cfg(feature = "servo")] malloc_size_of_is_0!(time::Tm); +#[cfg(feature = "servo")] +malloc_size_of_is_0!(std::time::Duration); +#[cfg(feature = "servo")] +malloc_size_of_is_0!(std::time::SystemTime); #[cfg(feature = "servo")] impl<T> MallocSizeOf for hyper_serde::Serde<T> diff --git a/components/metrics/Cargo.toml b/components/metrics/Cargo.toml index 1b5dc9330c5..29579d9aacb 100644 --- a/components/metrics/Cargo.toml +++ b/components/metrics/Cargo.toml @@ -21,4 +21,3 @@ profile_traits = { workspace = true } script_traits = { workspace = true } servo_config = { path = "../config" } servo_url = { path = "../url" } -time = { workspace = true } diff --git a/components/metrics/lib.rs b/components/metrics/lib.rs index 8393ba36d44..f3ea4b26c51 100644 --- a/components/metrics/lib.rs +++ b/components/metrics/lib.rs @@ -5,6 +5,7 @@ use std::cell::{Cell, RefCell}; use std::cmp::Ordering; use std::collections::HashMap; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use gfx_traits::Epoch; use ipc_channel::ipc::IpcSender; @@ -15,7 +16,6 @@ use profile_traits::time::{send_profile_data, ProfilerCategory, ProfilerChan, Ti use script_traits::{ConstellationControlMsg, LayoutMsg, ProgressiveWebMetricType}; use servo_config::opts; use servo_url::ServoUrl; -use time::precise_time_ns; pub trait ProfilerMetadataFactory { fn new_metadata(&self) -> Option<TimerMetadata>; @@ -32,8 +32,8 @@ pub trait ProgressiveWebMetric { /// TODO make this configurable /// maximum task time is 50ms (in ns) pub const MAX_TASK_NS: u64 = 50000000; -/// 10 second window (in ns) -const INTERACTIVE_WINDOW_SECONDS_IN_NS: u64 = 10000000000; +/// 10 second window +const INTERACTIVE_WINDOW_SECONDS: Duration = Duration::from_secs(10); pub trait ToMs<T> { fn to_ms(&self) -> T; @@ -63,7 +63,10 @@ fn set_metric<U: ProgressiveWebMetric>( }; let now = match metric_time { Some(time) => time, - None => precise_time_ns(), + None => SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64, }; let time = now - navigation_start; attr.set(Some(time)); @@ -113,13 +116,13 @@ pub struct InteractiveMetrics { #[derive(Clone, Copy, Debug, MallocSizeOf)] pub struct InteractiveWindow { - start: u64, + start: SystemTime, } impl InteractiveWindow { pub fn new() -> InteractiveWindow { InteractiveWindow { - start: precise_time_ns(), + start: SystemTime::now(), } } @@ -128,16 +131,22 @@ impl InteractiveWindow { // restart: there was a task > 50ms // not all documents are interactive pub fn start_window(&mut self) { - self.start = precise_time_ns(); + self.start = SystemTime::now(); } /// check if 10s has elapsed since start pub fn needs_check(&self) -> bool { - precise_time_ns() - self.start >= INTERACTIVE_WINDOW_SECONDS_IN_NS + SystemTime::now() + .duration_since(self.start) + .unwrap_or_default() >= + INTERACTIVE_WINDOW_SECONDS } pub fn get_start(&self) -> u64 { self.start + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64 } } @@ -161,7 +170,12 @@ impl InteractiveMetrics { pub fn set_dom_content_loaded(&self) { if self.dom_content_loaded.get().is_none() { - self.dom_content_loaded.set(Some(precise_time_ns())); + self.dom_content_loaded.set(Some( + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64, + )); } } diff --git a/components/script/dom/performanceresourcetiming.rs b/components/script/dom/performanceresourcetiming.rs index be1773aa9ca..ff7b334f9bf 100644 --- a/components/script/dom/performanceresourcetiming.rs +++ b/components/script/dom/performanceresourcetiming.rs @@ -113,7 +113,7 @@ impl PerformanceResourceTiming { DOMString::from(url.into_string()), DOMString::from("resource"), resource_timing.start_time as f64, - resource_timing.response_end as f64 - resource_timing.start_time as f64, + (resource_timing.response_end - resource_timing.start_time) as f64, ), initiator_type: initiator_type, next_hop: next_hop, diff --git a/components/shared/net/Cargo.toml b/components/shared/net/Cargo.toml index 432c8676ccb..d65bf83c714 100644 --- a/components/shared/net/Cargo.toml +++ b/components/shared/net/Cargo.toml @@ -36,7 +36,6 @@ serde = { workspace = true } servo_arc = { path = "../../servo_arc" } servo_rand = { path = "../../rand" } servo_url = { path = "../../url" } -time = { workspace = true } url = { workspace = true } uuid = { workspace = true } webrender_api = { git = "https://github.com/servo/webrender" } diff --git a/components/shared/net/lib.rs b/components/shared/net/lib.rs index b8b32725a25..63f4e7d8710 100644 --- a/components/shared/net/lib.rs +++ b/components/shared/net/lib.rs @@ -4,6 +4,8 @@ #![deny(unsafe_code)] +use std::time::{SystemTime, UNIX_EPOCH}; + use cookie::Cookie; use headers::{ContentType, HeaderMapExt, ReferrerPolicy as ReferrerPolicyHeader}; use http::{Error as HttpError, HeaderMap, StatusCode}; @@ -18,11 +20,11 @@ use malloc_size_of::malloc_size_of_is_0; use malloc_size_of_derive::MallocSizeOf; use mime::Mime; use msg::constellation_msg::HistoryStateId; +use num_traits::Zero; use rustls::Certificate; use serde::{Deserialize, Serialize}; use servo_rand::RngCore; use servo_url::{ImmutableOrigin, ServoUrl}; -use time::precise_time_ns; use webrender_api::{ImageData, ImageDescriptor, ImageKey}; use crate::filemanager_thread::FileManagerThreadMsg; @@ -594,15 +596,19 @@ impl ResourceFetchTiming { if !self.timing_check_passed && !should_attribute_always_be_updated { return; } + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64; match attribute { - ResourceAttribute::DomainLookupStart => self.domain_lookup_start = precise_time_ns(), + ResourceAttribute::DomainLookupStart => self.domain_lookup_start = now, ResourceAttribute::RedirectCount(count) => self.redirect_count = count, - ResourceAttribute::RequestStart => self.request_start = precise_time_ns(), - ResourceAttribute::ResponseStart => self.response_start = precise_time_ns(), + ResourceAttribute::RequestStart => self.request_start = now, + ResourceAttribute::ResponseStart => self.response_start = now, ResourceAttribute::RedirectStart(val) => match val { RedirectStartValue::Zero => self.redirect_start = 0, RedirectStartValue::FetchStart => { - if self.redirect_start == 0 { + if self.redirect_start.is_zero() { self.redirect_start = self.fetch_start } }, @@ -611,16 +617,14 @@ impl ResourceFetchTiming { RedirectEndValue::Zero => self.redirect_end = 0, RedirectEndValue::ResponseEnd => self.redirect_end = self.response_end, }, - ResourceAttribute::FetchStart => self.fetch_start = precise_time_ns(), + ResourceAttribute::FetchStart => self.fetch_start = now, ResourceAttribute::ConnectStart(val) => self.connect_start = val, ResourceAttribute::ConnectEnd(val) => self.connect_end = val, - ResourceAttribute::SecureConnectionStart => { - self.secure_connection_start = precise_time_ns() - }, - ResourceAttribute::ResponseEnd => self.response_end = precise_time_ns(), + ResourceAttribute::SecureConnectionStart => self.secure_connection_start = now, + ResourceAttribute::ResponseEnd => self.response_end = now, ResourceAttribute::StartTime(val) => match val { ResourceTimeValue::RedirectStart - if self.redirect_start == 0 || !self.timing_check_passed => {}, + if self.redirect_start.is_zero() || !self.timing_check_passed => {}, _ => self.start_time = self.get_time_value(val), }, } @@ -629,7 +633,10 @@ impl ResourceFetchTiming { fn get_time_value(&self, time: ResourceTimeValue) -> u64 { match time { ResourceTimeValue::Zero => 0, - ResourceTimeValue::Now => precise_time_ns(), + ResourceTimeValue::Now => SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64, ResourceTimeValue::FetchStart => self.fetch_start, ResourceTimeValue::RedirectStart => self.redirect_start, } diff --git a/tests/unit/metrics/interactive_time.rs b/tests/unit/metrics/interactive_time.rs index 5fa624beafe..0bddb944ace 100644 --- a/tests/unit/metrics/interactive_time.rs +++ b/tests/unit/metrics/interactive_time.rs @@ -2,6 +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::time::{SystemTime, UNIX_EPOCH}; + use ipc_channel::ipc; use metrics::{InteractiveFlag, InteractiveMetrics, ProfilerMetadataFactory, ProgressiveWebMetric}; use profile_traits::time::{ProfilerChan, TimerMetadata}; @@ -108,7 +110,10 @@ fn test_set_tti_mta() { let dcl = interactive.get_dom_content_loaded(); assert!(dcl.is_some()); - let t = time::precise_time_ns(); + let t = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_nanos() as u64; interactive.maybe_set_tti( &profiler_metadata_factory, InteractiveFlag::TimeToInteractive(t), |