Don't duplicate perf_attach code and formatting

pull/108/head
Dan Everton 3 years ago
parent d0321bd1ee
commit 84fa2197ec
No known key found for this signature in database
GPG Key ID: 2AF33A2B189A11B3

@ -2,8 +2,9 @@ use libc::close;
use std::os::unix::io::RawFd;
use crate::{
sys::perf_event_ioctl, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF,
programs::ProbeKind, programs::probe::detach_debug_fs
programs::{probe::detach_debug_fs, ProbeKind},
sys::perf_event_ioctl,
PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF,
};
use super::{Link, LinkRef, ProgramData, ProgramError};
@ -62,20 +63,13 @@ pub(crate) fn perf_attach(data: &mut ProgramData, fd: RawFd) -> Result<LinkRef,
}))
}
pub(crate) fn perf_attach_debugfs(data: &mut ProgramData, fd: RawFd, probe_kind: ProbeKind, event_alias: String) -> Result<LinkRef, ProgramError> {
let prog_fd = data.fd_or_err()?;
perf_event_ioctl(fd, PERF_EVENT_IOC_SET_BPF, prog_fd).map_err(|(_, io_error)| {
ProgramError::SyscallError {
call: "PERF_EVENT_IOC_SET_BPF".to_owned(),
io_error,
}
})?;
perf_event_ioctl(fd, PERF_EVENT_IOC_ENABLE, 0).map_err(|(_, io_error)| {
ProgramError::SyscallError {
call: "PERF_EVENT_IOC_ENABLE".to_owned(),
io_error,
}
})?;
pub(crate) fn perf_attach_debugfs(
data: &mut ProgramData,
fd: RawFd,
probe_kind: ProbeKind,
event_alias: String,
) -> Result<LinkRef, ProgramError> {
perf_attach(data, fd)?;
Ok(data.link(PerfLink {
perf_fd: Some(fd),

@ -7,8 +7,9 @@ use std::{
use crate::{
programs::{
kprobe::KProbeError, perf_attach, perf_attach_debugfs, trace_point::read_sys_fs_trace_point_id,
uprobe::UProbeError, LinkRef, ProgramData, ProgramError,
kprobe::KProbeError, perf_attach, perf_attach_debugfs,
trace_point::read_sys_fs_trace_point_id, uprobe::UProbeError, LinkRef, ProgramData,
ProgramError,
},
sys::{kernel_version, perf_event_open_probe, perf_event_open_trace_point},
};
@ -32,16 +33,15 @@ pub(crate) fn attach(
offset: u64,
pid: Option<pid_t>,
) -> Result<LinkRef, ProgramError> {
// https://github.com/torvalds/linux/commit/e12f03d7031a977356e3d7b75a68c2185ff8d155
// Use debugfs to create probe
// Use debugfs to create probe
let k_ver = kernel_version().unwrap();
if k_ver < (4, 17, 0) {
let (fd, event_alias) = create_as_trace_point(kind, fn_name, offset, pid)?;
return perf_attach_debugfs(program_data, fd, kind, event_alias);
};
let fd = create_as_probe(kind, fn_name, offset, pid)?;
perf_attach(program_data, fd)

Loading…
Cancel
Save