-// Hack up our own formatting for the duration to make it easier for scripts
-// to parse (always use the same number of decimal places and the same unit).
-pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
- const NANOS_PER_SEC: f64 = 1_000_000_000.0;
- let secs = dur.as_secs() as f64 + dur.subsec_nanos() as f64 / NANOS_PER_SEC;
+use crate::session::Session;
+use rustc_data_structures::profiling::VerboseTimingGuard;
- format!("{:.3}", secs)
+impl Session {
+ pub fn timer<'a>(&'a self, what: &'a str) -> VerboseTimingGuard<'a> {
+ self.prof.sparse_pass(what)
+ }
+ pub fn time<R>(&self, what: &str, f: impl FnOnce() -> R) -> R {
+ self.prof.sparse_pass(what).run(f)
+ }
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]