diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-25 10:59:46 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-25 10:59:46 +0000 |
commit | fb81726ee59a8df5d86ec2a78f959a0e166b8199 (patch) | |
tree | 4bf167645d4b7f098140612086424f6a0de69719 /crates/ra_prof/src | |
parent | c6dbf406a9bbf1d8df438753c9e1a7c97d0f00e1 (diff) | |
parent | 6577a7622d5053f35c16eed47516265c98e5212e (diff) |
Merge #2903
2903: Add print_time helper r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_prof/src')
-rw-r--r-- | crates/ra_prof/src/lib.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index da541005a..c7973ddf4 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs | |||
@@ -106,6 +106,21 @@ pub fn profile(desc: &str) -> Profiler { | |||
106 | }) | 106 | }) |
107 | } | 107 | } |
108 | 108 | ||
109 | pub fn print_time(desc: &str) -> impl Drop + '_ { | ||
110 | struct Guard<'a> { | ||
111 | desc: &'a str, | ||
112 | start: Instant, | ||
113 | } | ||
114 | |||
115 | impl Drop for Guard<'_> { | ||
116 | fn drop(&mut self) { | ||
117 | eprintln!("{}: {:?}", self.desc, self.start.elapsed()) | ||
118 | } | ||
119 | } | ||
120 | |||
121 | Guard { desc, start: Instant::now() } | ||
122 | } | ||
123 | |||
109 | pub struct Profiler { | 124 | pub struct Profiler { |
110 | desc: Option<String>, | 125 | desc: Option<String>, |
111 | } | 126 | } |