perf_event/events/
software.rs

1use c_enum::c_enum;
2use perf_event_open_sys::bindings;
3
4use crate::events::Event;
5
6c_enum! {
7    /// Software counters, implemented by the kernel.
8    ///
9    /// Each variant of this enum corresponds to a particular `PERF_COUNT_SW_`...
10    /// value supported by the [`perf_event_open`][man] system call.
11    ///
12    /// [man]: https://www.mankier.com/2/perf_event_open
13    #[repr(transparent)]
14    #[derive(Clone, Copy, Eq, PartialEq, Hash)]
15    pub enum Software : u64 {
16        /// High-resolution per-CPU timer.
17        CPU_CLOCK = bindings::PERF_COUNT_SW_CPU_CLOCK as _,
18
19        /// Per-task clock count.
20        TASK_CLOCK = bindings::PERF_COUNT_SW_TASK_CLOCK as _,
21
22        /// Page faults.
23        PAGE_FAULTS = bindings::PERF_COUNT_SW_PAGE_FAULTS as _,
24
25        /// Context switches.
26        CONTEXT_SWITCHES = bindings::PERF_COUNT_SW_CONTEXT_SWITCHES as _,
27
28        /// Process migration to another CPU.
29        CPU_MIGRATIONS = bindings::PERF_COUNT_SW_CPU_MIGRATIONS as _,
30
31        /// Minor page faults: resolved without needing I/O.
32        PAGE_FAULTS_MIN = bindings::PERF_COUNT_SW_PAGE_FAULTS_MIN as _,
33
34        /// Major page faults: I/O was required to resolve these.
35        PAGE_FAULTS_MAJ = bindings::PERF_COUNT_SW_PAGE_FAULTS_MAJ as _,
36
37        /// Alignment faults that required kernel intervention.
38        ///
39        /// This is only generated on some CPUs, and never on x86_64 or
40        /// ARM.
41        ALIGNMENT_FAULTS = bindings::PERF_COUNT_SW_ALIGNMENT_FAULTS as _,
42
43        /// Instruction emulation faults.
44        EMULATION_FAULTS = bindings::PERF_COUNT_SW_EMULATION_FAULTS as _,
45
46        /// Placeholder, for collecting informational sample records.
47        DUMMY = bindings::PERF_COUNT_SW_DUMMY as _,
48
49        /// Special event type for streaming data from a eBPF program.
50        ///
51        /// See the documentation of the `bpf_perf_event_output` method in the
52        /// [`bpf-helpers(7)`] manpage for details on how to use this event type.
53        ///
54        /// [`bpf-helpers(7)`]: https://man7.org/linux/man-pages/man7/bpf-helpers.7.html
55        BPF_OUTPUT = bindings::PERF_COUNT_SW_BPF_OUTPUT as _,
56
57        /// Context switches to a task in a different cgroup.
58        CGROUP_SWITCHES = bindings::PERF_COUNT_SW_CGROUP_SWITCHES as _,
59    }
60}
61
62impl Event for Software {
63    fn update_attrs(self, attr: &mut bindings::perf_event_attr) {
64        attr.type_ = bindings::PERF_TYPE_SOFTWARE;
65        attr.config = self.into();
66    }
67}