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

@ -7,8 +7,9 @@ use std::{
use crate::{ use crate::{
programs::{ programs::{
kprobe::KProbeError, perf_attach, perf_attach_debugfs, trace_point::read_sys_fs_trace_point_id, kprobe::KProbeError, perf_attach, perf_attach_debugfs,
uprobe::UProbeError, LinkRef, ProgramData, ProgramError, 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}, sys::{kernel_version, perf_event_open_probe, perf_event_open_trace_point},
}; };
@ -32,7 +33,6 @@ pub(crate) fn attach(
offset: u64, offset: u64,
pid: Option<pid_t>, pid: Option<pid_t>,
) -> Result<LinkRef, ProgramError> { ) -> Result<LinkRef, ProgramError> {
// https://github.com/torvalds/linux/commit/e12f03d7031a977356e3d7b75a68c2185ff8d155 // https://github.com/torvalds/linux/commit/e12f03d7031a977356e3d7b75a68c2185ff8d155
// Use debugfs to create probe // Use debugfs to create probe
let k_ver = kernel_version().unwrap(); let k_ver = kernel_version().unwrap();

Loading…
Cancel
Save