Skip to content

Commit

Permalink
Auto merge of #19498 - ferjm:pwm.f64, r=jdm
Browse files Browse the repository at this point in the history
Fix float conversion of paint timing metrics

This is a follow up of #19077

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19498)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Dec 7, 2017
2 parents 8e3056d + 4d8660c commit ff70c44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions components/metrics/lib.rs
Expand Up @@ -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<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>(
pwm: &U,
Expand Down Expand Up @@ -85,8 +94,8 @@ fn set_metric<U: ProgressiveWebMetric>(

// 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());
}

}
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/performance.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
}

Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/performancepainttiming.rs
Expand Up @@ -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]
Expand All @@ -26,7 +27,7 @@ impl PerformancePaintTiming {
PerformancePaintTiming {
entry: PerformanceEntry::new_inherited(name,
DOMString::from("paint"),
start_time as f64,
start_time.to_ms(),
0.)
}
}
Expand Down

0 comments on commit ff70c44

Please sign in to comment.