From 4d8660c91819fc13deafc7561432bceb41c4ad2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Tue, 5 Dec 2017 20:07:45 +0100 Subject: [PATCH] Fix float conversion of paint timing metrics --- components/metrics/lib.rs | 13 +++++++++++-- components/script/dom/performance.rs | 3 ++- components/script/dom/performancepainttiming.rs | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/components/metrics/lib.rs b/components/metrics/lib.rs index bd2d488f100..72706d0a0a7 100644 --- a/components/metrics/lib.rs +++ b/components/metrics/lib.rs @@ -46,6 +46,15 @@ pub const MAX_TASK_NS: u64 = 50000000; /// 10 second window (in ns) const INTERACTIVE_WINDOW_SECONDS_IN_NS: u64 = 10000000000; +pub trait ToMs { + fn to_ms(&self) -> T; +} + +impl ToMs for u64 { + fn to_ms(&self) -> f64 { + *self as f64 / 1000000. + } +} fn set_metric( pwm: &U, @@ -85,8 +94,8 @@ fn set_metric( // Print the metric to console if the print-pwm option was given. if opts::get().print_pwm { - println!("Navigation start: {}", pwm.get_navigation_start().unwrap()); - println!("{:?} {:?}", metric_type, time); + println!("Navigation start: {}", pwm.get_navigation_start().unwrap().to_ms()); + println!("{:?} {:?}", metric_type, time.to_ms()); } } diff --git a/components/script/dom/performance.rs b/components/script/dom/performance.rs index 5e1f7e6fb92..3ff1d32b5d6 100644 --- a/components/script/dom/performance.rs +++ b/components/script/dom/performance.rs @@ -20,6 +20,7 @@ use dom::performanceobserver::PerformanceObserver as DOMPerformanceObserver; use dom::performancetiming::PerformanceTiming; use dom::window::Window; use dom_struct::dom_struct; +use metrics::ToMs; use std::cell::Cell; use std::cmp::Ordering; use time; @@ -260,7 +261,7 @@ impl Performance { Some(ref timing) => timing.navigation_start_precise(), None => self.navigation_start_precise, }; - (time::precise_time_ns() - nav_start) as f64 / 1000000. + (time::precise_time_ns() - nav_start).to_ms() } } diff --git a/components/script/dom/performancepainttiming.rs b/components/script/dom/performancepainttiming.rs index 567f5e77ef4..4dc4adb4993 100644 --- a/components/script/dom/performancepainttiming.rs +++ b/components/script/dom/performancepainttiming.rs @@ -9,6 +9,7 @@ use dom::bindings::str::DOMString; use dom::globalscope::GlobalScope; use dom::performanceentry::PerformanceEntry; use dom_struct::dom_struct; +use metrics::ToMs; use script_traits::ProgressiveWebMetricType; #[dom_struct] @@ -26,7 +27,7 @@ impl PerformancePaintTiming { PerformancePaintTiming { entry: PerformanceEntry::new_inherited(name, DOMString::from("paint"), - start_time as f64, + start_time.to_ms(), 0.) } }