diff options
Diffstat (limited to 'src/librustc_session/utils.rs')
| -rw-r--r-- | src/librustc_session/utils.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/librustc_session/utils.rs b/src/librustc_session/utils.rs index 298727d07e4..7806f5e8753 100644 --- a/src/librustc_session/utils.rs +++ b/src/librustc_session/utils.rs @@ -1,10 +1,13 @@ -// 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)] |
