cpu_instructions_reader/ffi/mod.rs
1//! Base bindings to c code
2//!
3//! Unless you are really sure you have to use them, just use [`crate::InstructionNumberReader`] for normal purpose
4
5use libc::{c_int, c_longlong as c_ll, pid_t, size_t};
6
7extern "C" {
8 /// Mock constructor
9 ///
10 /// This C function internally calls malloc to allocate a memory to construct InstructionNumberReaderRaw, and returns a pointer to the heap
11 ///
12 /// If there is an error in the creation process, the memory will be free, and the pointer will be set to NULL to return, special attention should be paid
13 pub fn createInstructionNumberReader(cpus: *const c_int, num_cpus: size_t, pid: pid_t) -> *mut InstructionNumberReaderRaw;
14
15 /// Mock destructor
16 ///
17 /// This C function internally calls free to release the memory and sets the pointer to NULL
18 pub fn destroyInstructionNumberReader(reader: *mut InstructionNumberReaderRaw);
19
20 /// This C function calls ioctl to start recording instruction number, see [perf_event_read](https://www.man7.org/linux/man-pages/man2/perf_event_open.2.html)
21 pub fn enableInstructionNumberReader(reader: *mut InstructionNumberReaderRaw);
22
23 /// This C function calls ioctl to stop recording instruction number, see [perf_event_read](https://www.man7.org/linux/man-pages/man2/perf_event_open.2.html)
24 pub fn disableInstructionNumberReader(reader: *mut InstructionNumberReaderRaw);
25
26 /// This C function reads instruction number information by reading the file identifier, see [perf_event_read](https://www.man7.org/linux/man-pages/man2/perf_event_open.2.html)
27 ///
28 /// The returned array pointer is also allocated by malloc, consider calling [`libc::free`] to release to ensure memory safety, and remember to prevent dangling pointers
29 ///
30 /// NOTE: The length of the array is the number of CPUs used during construction. Consider using the `size` member of [`self::InstructionNumberReaderRaw`] to determine the length of the array
31 pub fn readInstructionNumberReader(reader: *mut InstructionNumberReaderRaw, cpu: c_int) -> c_ll;
32}
33
34/// The Raw Reader Structure, corresponding to the same structure in C
35#[repr(C)]
36pub struct InstructionNumberReaderRaw {
37 pub size: size_t,
38 cpus: *mut c_int,
39}