pub struct PerfEvent { /* private fields */ }
Expand description

A program that can be attached at a perf event.

Minimum kernel version

The minimum kernel version required to use this feature is 4.9.

Examples

use std::convert::TryInto;
use aya::util::online_cpus;
use aya::programs::perf_event::{
    perf_sw_ids::PERF_COUNT_SW_CPU_CLOCK, PerfEvent, PerfEventScope, PerfTypeId, SamplePolicy,
};

let prog: &mut PerfEvent = bpf.program_mut("observe_cpu_clock").unwrap().try_into()?;
prog.load()?;

for cpu in online_cpus()? {
    prog.attach(
        PerfTypeId::Software,
        PERF_COUNT_SW_CPU_CLOCK as u64,
        PerfEventScope::AllProcessesOneCpu { cpu },
        SamplePolicy::Period(1000000),
    )?;
}

Implementations

Loads the program inside the kernel.

See also Program::load.

Attaches to the given perf event.

The possible values and encoding of the config argument depends on the perf_type. See perf_sw_ids, perf_hw_id, perf_hw_cache_id, perf_hw_cache_op_id and perf_hw_cache_op_result_id.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the RawFd of the program if it has been loaded, or None

Returns the RawFd of the program if it has been loaded, or None

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.