aya: perf_event: add inherit argument to attach()

reviewable/pr878/r1
Alessandro Decina 10 months ago
parent 3fedc2a706
commit 0f6a734392

@ -115,6 +115,7 @@ pub enum PerfEventScope {
/// PERF_COUNT_SW_CPU_CLOCK as u64,
/// PerfEventScope::AllProcessesOneCpu { cpu },
/// SamplePolicy::Period(1000000),
/// true,
/// )?;
/// }
/// # Ok::<(), Error>(())
@ -137,6 +138,10 @@ impl PerfEvent {
/// `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`.
///
/// The `scope` argument determines which processes are sampled. If `inherit`
/// is true, any new processes spawned by those processes will also
/// automatically get sampled.
///
/// The returned value can be used to detach, see [PerfEvent::detach].
pub fn attach(
&mut self,
@ -144,6 +149,7 @@ impl PerfEvent {
config: u64,
scope: PerfEventScope,
sample_policy: SamplePolicy,
inherit: bool,
) -> Result<PerfEventLinkId, ProgramError> {
let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd();
@ -166,6 +172,7 @@ impl PerfEvent {
sample_period,
sample_frequency,
false,
inherit,
0,
)
.map_err(|(_code, io_error)| SyscallError {

@ -24,6 +24,7 @@ pub(crate) fn perf_event_open(
sample_period: u64,
sample_frequency: Option<u64>,
wakeup: bool,
inherit: bool,
flags: u32,
) -> SysResult<OwnedFd> {
let mut attr = unsafe { mem::zeroed::<perf_event_attr>() };
@ -32,7 +33,7 @@ pub(crate) fn perf_event_open(
attr.size = mem::size_of::<perf_event_attr>() as u32;
attr.type_ = perf_type;
attr.sample_type = PERF_SAMPLE_RAW as u64;
// attr.inherits = if pid > 0 { 1 } else { 0 };
attr.set_inherit(if inherit { 1 } else { 0 });
attr.__bindgen_anon_2.wakeup_events = u32::from(wakeup);
if let Some(frequency) = sample_frequency {
@ -54,6 +55,7 @@ pub(crate) fn perf_event_open_bpf(cpu: c_int) -> SysResult<OwnedFd> {
1,
None,
true,
false,
PERF_FLAG_FD_CLOEXEC,
)
}

@ -4304,7 +4304,7 @@ impl<T> core::convert::From<T> for aya::programs::perf_event::SamplePolicy
pub fn aya::programs::perf_event::SamplePolicy::from(t: T) -> T
pub struct aya::programs::perf_event::PerfEvent
impl aya::programs::perf_event::PerfEvent
pub fn aya::programs::perf_event::PerfEvent::attach(&mut self, perf_type: aya::programs::perf_event::PerfTypeId, config: u64, scope: aya::programs::perf_event::PerfEventScope, sample_policy: aya::programs::perf_event::SamplePolicy) -> core::result::Result<aya::programs::perf_event::PerfEventLinkId, aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::attach(&mut self, perf_type: aya::programs::perf_event::PerfTypeId, config: u64, scope: aya::programs::perf_event::PerfEventScope, sample_policy: aya::programs::perf_event::SamplePolicy, inherit: bool) -> core::result::Result<aya::programs::perf_event::PerfEventLinkId, aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::detach(&mut self, link_id: aya::programs::perf_event::PerfEventLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::take_link(&mut self, link_id: aya::programs::perf_event::PerfEventLinkId) -> core::result::Result<aya::programs::perf_event::PerfEventLink, aya::programs::ProgramError>
@ -6708,7 +6708,7 @@ impl<T> core::convert::From<T> for aya::programs::lsm::Lsm
pub fn aya::programs::lsm::Lsm::from(t: T) -> T
pub struct aya::programs::PerfEvent
impl aya::programs::perf_event::PerfEvent
pub fn aya::programs::perf_event::PerfEvent::attach(&mut self, perf_type: aya::programs::perf_event::PerfTypeId, config: u64, scope: aya::programs::perf_event::PerfEventScope, sample_policy: aya::programs::perf_event::SamplePolicy) -> core::result::Result<aya::programs::perf_event::PerfEventLinkId, aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::attach(&mut self, perf_type: aya::programs::perf_event::PerfTypeId, config: u64, scope: aya::programs::perf_event::PerfEventScope, sample_policy: aya::programs::perf_event::SamplePolicy, inherit: bool) -> core::result::Result<aya::programs::perf_event::PerfEventLinkId, aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::detach(&mut self, link_id: aya::programs::perf_event::PerfEventLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::perf_event::PerfEvent::take_link(&mut self, link_id: aya::programs::perf_event::PerfEventLinkId) -> core::result::Result<aya::programs::perf_event::PerfEventLink, aya::programs::ProgramError>

Loading…
Cancel
Save