diff options
author | Aleksey Kladov <[email protected]> | 2019-06-26 09:11:28 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-26 09:11:28 +0100 |
commit | d621533f15871ce233e3a1dcc0fb10a631090678 (patch) | |
tree | 53bfceb17b0d730490e8f489c0c0611433de46e5 /crates/ra_prof/src | |
parent | 0129790a8f84a0858abcb1448e1052caa01fc41c (diff) |
add cpuprofile to ra_prof
Now, one can use `let _p = ra_prof::cpu_profiler()` to capture profile
of a block of code.
This is not an out of the box experience, as that relies on gperfools
See the docs on https://github.com/AtheMathmo/cpuprofiler for more!
Diffstat (limited to 'crates/ra_prof/src')
-rw-r--r-- | crates/ra_prof/src/lib.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index de67b4031..1e8d780ab 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs | |||
@@ -255,6 +255,39 @@ impl Drop for Scope { | |||
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | /// A wrapper around https://github.com/AtheMathmo/cpuprofiler | ||
259 | /// | ||
260 | /// It can be used to capture sampling profiles of sections of code. | ||
261 | /// It is not exactly out-of-the-box, as it relies on gperftools. | ||
262 | /// See the docs for the crate for more! | ||
263 | #[derive(Debug)] | ||
264 | pub struct CpuProfiler { | ||
265 | _private: (), | ||
266 | } | ||
267 | |||
268 | pub fn cpu_profiler() -> CpuProfiler { | ||
269 | #[cfg(feature = "cpuprofiler")] | ||
270 | { | ||
271 | cpuprofiler::PROFILER.lock().unwrap().start("./out.profile").unwrap(); | ||
272 | } | ||
273 | |||
274 | #[cfg(not(feature = "cpuprofiler"))] | ||
275 | { | ||
276 | eprintln!("cpuprofiler feature is disabled") | ||
277 | } | ||
278 | |||
279 | CpuProfiler { _private: () } | ||
280 | } | ||
281 | |||
282 | impl Drop for CpuProfiler { | ||
283 | fn drop(&mut self) { | ||
284 | #[cfg(feature = "cpuprofiler")] | ||
285 | { | ||
286 | cpuprofiler::PROFILER.lock().unwrap().stop().unwrap(); | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
258 | #[cfg(test)] | 291 | #[cfg(test)] |
259 | mod tests { | 292 | mod tests { |
260 | use super::*; | 293 | use super::*; |