baracuda_runtime/
profiler.rs1use baracuda_cuda_sys::runtime::runtime;
5
6use crate::error::{check, Result};
7
8pub fn start() -> Result<()> {
10 let r = runtime()?;
11 let cu = r.cuda_profiler_start()?;
12 check(unsafe { cu() })
13}
14
15pub fn stop() -> Result<()> {
17 let r = runtime()?;
18 let cu = r.cuda_profiler_stop()?;
19 check(unsafe { cu() })
20}
21
22pub fn with_profiling<F, R>(f: F) -> Result<R>
25where
26 F: FnOnce() -> R,
27{
28 start()?;
29 struct Guard;
30 impl Drop for Guard {
31 fn drop(&mut self) {
32 let _ = stop();
33 }
34 }
35 let _g = Guard;
36 Ok(f())
37}