perf_event/events/
hardware.rs

1use c_enum::c_enum;
2use perf_event_open_sys::bindings;
3
4use crate::events::Event;
5
6c_enum! {
7    /// Hardware counters.
8    ///
9    /// These are counters implemented by the processor itself. Such counters vary
10    /// from one architecture to the next, and even different models within a
11    /// particular architecture will often change the way they expose this data.
12    /// This is a selection of portable names for values that can be obtained on a
13    /// wide variety of systems.
14    ///
15    /// Each variant of this enum corresponds to a particular `PERF_COUNT_HW_`...
16    /// value supported by the [`perf_event_open`][man] system call.
17    ///
18    /// [man]: https://www.mankier.com/2/perf_event_open
19    #[repr(transparent)]
20    #[derive(Clone, Copy, Eq, PartialEq, Hash)]
21    pub enum Hardware : u64 {
22        /// Total cycles.
23        CPU_CYCLES = bindings::PERF_COUNT_HW_CPU_CYCLES as _,
24
25        /// Retired instructions.
26        INSTRUCTIONS = bindings::PERF_COUNT_HW_INSTRUCTIONS as _,
27
28        /// Cache accesses.
29        CACHE_REFERENCES = bindings::PERF_COUNT_HW_CACHE_REFERENCES as _,
30
31        /// Cache misses.
32        CACHE_MISSES = bindings::PERF_COUNT_HW_CACHE_MISSES as _,
33
34        /// Retired branch instructions.
35        BRANCH_INSTRUCTIONS = bindings::PERF_COUNT_HW_BRANCH_INSTRUCTIONS as _,
36
37        /// Mispredicted branch instructions.
38        BRANCH_MISSES = bindings::PERF_COUNT_HW_BRANCH_MISSES as _,
39
40        /// Bus cycles.
41        BUS_CYCLES = bindings::PERF_COUNT_HW_BUS_CYCLES as _,
42
43        /// Stalled cycles during issue.
44        STALLED_CYCLES_FRONTEND = bindings::PERF_COUNT_HW_STALLED_CYCLES_FRONTEND as _,
45
46        /// Stalled cycles during retirement.
47        STALLED_CYCLES_BACKEND = bindings::PERF_COUNT_HW_STALLED_CYCLES_BACKEND as _,
48
49        /// Total cycles, independent of frequency scaling.
50        REF_CPU_CYCLES = bindings::PERF_COUNT_HW_REF_CPU_CYCLES as _,
51    }
52}
53
54impl Event for Hardware {
55    fn update_attrs(self, attr: &mut bindings::perf_event_attr) {
56        attr.type_ = bindings::PERF_TYPE_HARDWARE;
57        attr.config = self.into();
58    }
59}