1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! CUDA profiler control helpers.
use singe_cuda_sys::profiler;
use crate::{error::Result, try_ffi};
#[derive(Debug)]
pub struct Profiler {
active: bool,
}
impl Profiler {
/// Starts profiler collection and returns a guard that stops it on drop.
pub fn create() -> Result<Self> {
start()?;
Ok(Self { active: true })
}
pub const fn is_active(&self) -> bool {
self.active
}
/// Stops profiler collection before the guard is dropped.
pub fn stop(mut self) -> Result<()> {
if self.active {
stop()?;
self.active = false;
}
Ok(())
}
}
impl Drop for Profiler {
fn drop(&mut self) {
if self.active {
let _ = stop();
self.active = false;
}
}
}
pub fn start() -> Result<()> {
unsafe {
try_ffi!(profiler::cuProfilerStart())?;
}
Ok(())
}
pub fn stop() -> Result<()> {
unsafe {
try_ffi!(profiler::cuProfilerStop())?;
}
Ok(())
}