]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_session/utils.rs
Auto merge of #66899 - msizanoen1:riscv-std, r=alexcrichton
[rust.git] / src / librustc_session / utils.rs
index ad593398a52bae2638f4b6f7566256edc95e3f74..7806f5e8753f22b9fcea1275ecabcf33e7571ca1 100644 (file)
@@ -1,11 +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)]