Fix float conversion of paint timing metrics

This commit is contained in:
Fernando Jiménez Moreno 2017-12-05 20:07:45 +01:00
parent 462409ada5
commit 4d8660c918
3 changed files with 15 additions and 4 deletions

View file

@ -46,6 +46,15 @@ pub const MAX_TASK_NS: u64 = 50000000;
/// 10 second window (in ns) /// 10 second window (in ns)
const INTERACTIVE_WINDOW_SECONDS_IN_NS: u64 = 10000000000; const INTERACTIVE_WINDOW_SECONDS_IN_NS: u64 = 10000000000;
pub trait ToMs<T> {
fn to_ms(&self) -> T;
}
impl ToMs<f64> for u64 {
fn to_ms(&self) -> f64 {
*self as f64 / 1000000.
}
}
fn set_metric<U: ProgressiveWebMetric>( fn set_metric<U: ProgressiveWebMetric>(
pwm: &U, pwm: &U,
@ -85,8 +94,8 @@ fn set_metric<U: ProgressiveWebMetric>(
// Print the metric to console if the print-pwm option was given. // Print the metric to console if the print-pwm option was given.
if opts::get().print_pwm { if opts::get().print_pwm {
println!("Navigation start: {}", pwm.get_navigation_start().unwrap()); println!("Navigation start: {}", pwm.get_navigation_start().unwrap().to_ms());
println!("{:?} {:?}", metric_type, time); println!("{:?} {:?}", metric_type, time.to_ms());
} }
} }

View file

@ -20,6 +20,7 @@ use dom::performanceobserver::PerformanceObserver as DOMPerformanceObserver;
use dom::performancetiming::PerformanceTiming; use dom::performancetiming::PerformanceTiming;
use dom::window::Window; use dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use metrics::ToMs;
use std::cell::Cell; use std::cell::Cell;
use std::cmp::Ordering; use std::cmp::Ordering;
use time; use time;
@ -260,7 +261,7 @@ impl Performance {
Some(ref timing) => timing.navigation_start_precise(), Some(ref timing) => timing.navigation_start_precise(),
None => self.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()
} }
} }

View file

@ -9,6 +9,7 @@ use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom::performanceentry::PerformanceEntry; use dom::performanceentry::PerformanceEntry;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use metrics::ToMs;
use script_traits::ProgressiveWebMetricType; use script_traits::ProgressiveWebMetricType;
#[dom_struct] #[dom_struct]
@ -26,7 +27,7 @@ impl PerformancePaintTiming {
PerformancePaintTiming { PerformancePaintTiming {
entry: PerformanceEntry::new_inherited(name, entry: PerformanceEntry::new_inherited(name,
DOMString::from("paint"), DOMString::from("paint"),
start_time as f64, start_time.to_ms(),
0.) 0.)
} }
} }