leodos_libcfs/cfe/es/perf.rs
1//! Safe wrapper for CFE Performance Logging.
2
3use crate::ffi;
4
5/// A performance marker that logs entry and exit points for performance measurement.
6///
7/// Automatically starts logging on creation and stops logging when dropped.
8pub struct PerfMarker {
9 id: u32,
10}
11
12impl PerfMarker {
13 /// Creates a new performance marker with the given ID and logs an "entry" event.
14 ///
15 /// # Arguments
16 /// * `id`: A numeric identifier for the performance event.
17 ///
18 /// # C-API Mapping
19 /// This calls `CFE_ES_PerfLogAdd(id, 0)`.
20 pub fn new(id: u32) -> Self {
21 unsafe {
22 ffi::CFE_ES_PerfLogAdd(id, 0);
23 }
24 Self { id }
25 }
26}
27
28impl Drop for PerfMarker {
29 /// Logs an "exit" event when the marker goes out of scope.
30 ///
31 /// # C-API Mapping
32 /// This calls `CFE_ES_PerfLogAdd(self.id, 1)`.
33 fn drop(&mut self) {
34 unsafe {
35 ffi::CFE_ES_PerfLogAdd(self.id, 1);
36 }
37 }
38}