Disables counting. If counting is already disabled, this is a no-op. # Errors Returns [`SamplerError`] if the kernel rejects the request. Both calls are attempted even if the first fails.
(&mut self)
| 145 | /// Returns [`SamplerError`] if the kernel rejects the request. Both calls |
| 146 | /// are attempted even if the first fails. |
| 147 | pub fn stop(&mut self) -> Result<(), SamplerError> { |
| 148 | if !self.running { |
| 149 | return Ok(()); |
| 150 | } |
| 151 | |
| 152 | let kpc_vt = self.sampler.kperf.vtable(); |
| 153 | |
| 154 | // Reverse order of start: thread counting first, then counting. |
| 155 | // SAFETY: passing 0 to disable counting is always safe. |
| 156 | let ret_thread_counting = unsafe { (kpc_vt.kpc_set_thread_counting)(0) }; |
| 157 | // SAFETY: same as above. |
| 158 | let ret_counting = unsafe { (kpc_vt.kpc_set_counting)(0) }; |
| 159 | |
| 160 | self.running = false; |
| 161 | |
| 162 | try_kpc( |
| 163 | ret_thread_counting, |
| 164 | SamplerError::UnableToStopThreadCounting, |
| 165 | )?; |
| 166 | try_kpc(ret_counting, SamplerError::UnableToStopCounting)?; |
| 167 | |
| 168 | Ok(()) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | impl<const N: usize> Drop for ThreadSampler<'_, N> { |