Skip to content

Commit c528d1e

Browse files
committed
rex/tracepoint: implement PerfEventStreamer trait
Signed-off-by: MinhPhan8803 <[email protected]>
1 parent bc62fe0 commit c528d1e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

rex/src/tracepoint/tp_impl.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
use crate::base_helper::termination_check;
12
use crate::bindings::uapi::linux::bpf::{
23
bpf_map_type, BPF_PROG_TYPE_TRACEPOINT,
34
};
5+
use crate::ffi;
6+
use crate::map::RexPerfEventArray;
47
use crate::prog_type::rex_prog;
58
use crate::task_struct::TaskStruct;
9+
use crate::utils::{to_result, NoRef, PerfEventMaskedCPU, PerfEventStreamer};
610
use crate::Result;
711

812
use super::{
@@ -65,3 +69,26 @@ impl<C: TracepointContext + 'static> rex_prog for tracepoint<C> {
6569
((self.prog)(self, newctx)).unwrap_or_else(|e| e) as u32
6670
}
6771
}
72+
73+
impl<C: TracepointContext + 'static> PerfEventStreamer for tracepoint<C> {
74+
type Context = C;
75+
fn output_event<T: Copy + NoRef>(
76+
&self,
77+
ctx: &Self::Context,
78+
map: &'static RexPerfEventArray<T>,
79+
data: &T,
80+
cpu: PerfEventMaskedCPU,
81+
) -> Result {
82+
let map_kptr = unsafe { core::ptr::read_volatile(&map.kptr) };
83+
let ctx_ptr = ctx as *const C as *const ();
84+
termination_check!(unsafe {
85+
to_result!(ffi::bpf_perf_event_output_tp(
86+
ctx_ptr,
87+
map_kptr,
88+
cpu.masked_cpu,
89+
data as *const T as *const (),
90+
core::mem::size_of::<T>() as u64
91+
))
92+
})
93+
}
94+
}

0 commit comments

Comments
 (0)