@ -3,14 +3,14 @@ use std::{fs, io, path::Path};
use thiserror ::Error ;
use crate ::{
generated ::bpf_prog_type ::BPF_PROG_TYPE_TRACEPOINT ,
generated ::{ bpf_link_type , bpf_prog_type ::BPF_PROG_TYPE_TRACEPOINT } ,
programs ::{
define_link_wrapper , load_program ,
perf_attach ::{ perf_attach , PerfLinkIdInner , PerfLinkInner } ,
utils ::find_tracefs_path ,
ProgramData, ProgramError ,
FdLink, LinkError , ProgramData, ProgramError ,
} ,
sys ::perf_event_open_trace_point ,
sys ::{ bpf_link_get_info_by_fd , perf_event_open_trace_point } ,
} ;
/// The type returned when attaching a [`TracePoint`] fails.
@ -116,6 +116,35 @@ define_link_wrapper!(
PerfLinkIdInner
) ;
impl TryFrom < TracePointLink > for FdLink {
type Error = LinkError ;
fn try_from ( value : TracePointLink ) -> Result < Self , Self ::Error > {
if let PerfLinkInner ::FdLink ( fd ) = value . into_inner ( ) {
Ok ( fd )
} else {
Err ( LinkError ::InvalidLink )
}
}
}
impl TryFrom < FdLink > for TracePointLink {
type Error = LinkError ;
fn try_from ( fd_link : FdLink ) -> Result < Self , Self ::Error > {
let info =
bpf_link_get_info_by_fd ( fd_link . fd ) . map_err ( | io_error | LinkError ::SyscallError {
call : "BPF_OBJ_GET_INFO_BY_FD" ,
code : 0 ,
io_error ,
} ) ? ;
if info . type_ = = ( bpf_link_type ::BPF_LINK_TYPE_TRACING as u32 ) {
return Ok ( TracePointLink ::new ( PerfLinkInner ::FdLink ( fd_link ) ) ) ;
}
Err ( LinkError ::InvalidLink )
}
}
pub ( crate ) fn read_sys_fs_trace_point_id (
tracefs : & Path ,
category : & str ,