mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Move util::time::duration_from_seconds to profile::time
This commit is contained in:
parent
f8f00fac5b
commit
5a576e873e
4 changed files with 16 additions and 24 deletions
|
@ -12,8 +12,8 @@ use std::borrow::ToOwned;
|
|||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::thread;
|
||||
use time::duration_from_seconds;
|
||||
use util::thread::spawn_named;
|
||||
use util::time::duration_from_seconds;
|
||||
|
||||
pub struct Profiler {
|
||||
/// The port through which messages are received.
|
||||
|
|
|
@ -19,12 +19,11 @@ use std::io::{self, Write};
|
|||
use std::path;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use std::{thread, f64};
|
||||
use std::{f64, thread, u32, u64};
|
||||
use std_time::precise_time_ns;
|
||||
use trace_dump::TraceDump;
|
||||
use util::opts::OutputOptions;
|
||||
use util::thread::spawn_named;
|
||||
use util::time::duration_from_seconds;
|
||||
|
||||
pub trait Formattable {
|
||||
fn format(&self, output: &Option<OutputOptions>) -> String;
|
||||
|
@ -408,3 +407,17 @@ fn enforce_range<T>(min: T, max: T, value: T) -> T where T: Ord {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn duration_from_seconds(secs: f64) -> Duration {
|
||||
pub const NANOS_PER_SEC: u32 = 1_000_000_000;
|
||||
|
||||
// Get number of seconds and check that it fits in a u64.
|
||||
let whole_secs = secs.trunc();
|
||||
assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64);
|
||||
|
||||
// Get number of nanoseconds. This should always fit in a u32, but check anyway.
|
||||
let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc();
|
||||
assert!(nanos >= 0.0 && nanos <= u32::MAX as f64);
|
||||
|
||||
Duration::new(whole_secs as u64, nanos as u32)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ pub mod str;
|
|||
pub mod thread;
|
||||
pub mod thread_state;
|
||||
pub mod tid;
|
||||
#[cfg(feature = "servo")] pub mod time;
|
||||
pub mod vec;
|
||||
#[allow(unsafe_code)] pub mod workqueue;
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::time::Duration;
|
||||
use std::{u32, u64};
|
||||
|
||||
pub const NANOS_PER_SEC: u32 = 1_000_000_000;
|
||||
|
||||
pub fn duration_from_seconds(secs: f64) -> Duration {
|
||||
// Get number of seconds and check that it fits in a u64.
|
||||
let whole_secs = secs.trunc();
|
||||
assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64);
|
||||
|
||||
// Get number of nanoseconds. This should always fit in a u32, but check anyway.
|
||||
let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc();
|
||||
assert!(nanos >= 0.0 && nanos <= u32::MAX as f64);
|
||||
|
||||
Duration::new(whole_secs as u64, nanos as u32)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue