Skip to content

Commit

Permalink
chore(eBPF) fixed return KProbe time difference
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Weisshuhn <[email protected]>
  • Loading branch information
der-whity committed Nov 19, 2024
1 parent 434f4bb commit a2e426b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions rust/backend/ebpf/src/vfs_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
const TIME_LIMIT_NS: u64 = 100_000_000;

use aya_ebpf::{
macros::{kprobe, map},
macros::{kprobe, map, kretprobe},
maps::{HashMap, RingBuf},
programs::ProbeContext,
programs::{ProbeContext, RetProbeContext},
EbpfContext,
helpers::gen::bpf_ktime_get_ns,
};
use aya_log_ebpf::info;
use backend_common::{generate_id, VfsWriteCall};


Expand All @@ -31,7 +32,6 @@ struct VfsWriteIntern {
bytes_written: usize,
}


#[kprobe]
pub fn vfs_write(ctx: ProbeContext) -> Result<(), u32> {
let id = generate_id(ctx.pid(), ctx.tgid());
Expand All @@ -49,8 +49,8 @@ pub fn vfs_write(ctx: ProbeContext) -> Result<(), u32> {
}


#[kprobe]
pub fn vfs_write_ret(ctx: ProbeContext) -> Result<(), u32> {
#[kretprobe]
pub fn vfs_write_ret(ctx: RetProbeContext) -> Result<(), u32> {
let probe_end = unsafe { bpf_ktime_get_ns() };

let pid = ctx.pid();
Expand All @@ -61,12 +61,9 @@ pub fn vfs_write_ret(ctx: ProbeContext) -> Result<(), u32> {
Some(entry) => {entry}
};

if data.begin_time_stamp - probe_end > TIME_LIMIT_NS {


if probe_end - data.begin_time_stamp > TIME_LIMIT_NS {
let data = VfsWriteCall::new(pid, tgid, data.begin_time_stamp, data.fd, data.bytes_written);


let mut entry = match VFS_WRITE_MAP.reserve::<VfsWriteCall>(0) {
Some(entry) => entry,
None => return Err(0),
Expand Down

0 comments on commit a2e426b

Please sign in to comment.