From f274cfb21dadbf7b7786c81e3e34798d449a2005 Mon Sep 17 00:00:00 2001 From: Quentin JEROME Date: Tue, 3 Oct 2023 17:36:30 +0200 Subject: [PATCH] prioritize tracepoint + utility functions Signed-off-by: Quentin JEROME --- kunai/src/compat.rs | 46 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/kunai/src/compat.rs b/kunai/src/compat.rs index 47bfc3f..8a5e53d 100644 --- a/kunai/src/compat.rs +++ b/kunai/src/compat.rs @@ -223,6 +223,13 @@ impl<'a> Program<'a> { let program = self.prog(); match program { + programs::Program::TracePoint(_) => { + let (cat, name) = Self::tp_cat_name(&self.name); + if cat == "syscalls" && name.starts_with("sys_exit") { + return self.prio + 1; + } + return self.prio; + } programs::Program::KProbe(program) => match program.kind() { programs::ProbeKind::URetProbe => self.prio + 1, programs::ProbeKind::KRetProbe => self.prio + 1, @@ -235,6 +242,22 @@ impl<'a> Program<'a> { } } + #[inline(always)] + // gets tracepoint category and name out of program name + fn tp_cat_name(name: &str) -> (String, String) { + let v: Vec = name.split('.').map(|s| String::from(s)).collect(); + let cat = v.get(v.len() - 2).expect("category is missing"); + let name = v.last().expect("name is missing"); + (cat.into(), name.into()) + } + + #[inline(always)] + // gets tracepoint category and name out of program name + fn fn_name(name: &str) -> String { + let v: Vec = name.split('.').map(|s| String::from(s)).collect(); + v.last().expect("we must have at least one element").into() + } + pub fn min_kernel(&mut self, min: KernelVersion) -> &mut Self { self.compat.min = Some(min); self @@ -284,35 +307,22 @@ impl<'a> Program<'a> { let program = self.prog_mut(); match program { - programs::Program::BtfTracePoint(program) => { - program.load(&name, btf)?; - program.attach()?; - } programs::Program::TracePoint(program) => { - let v: Vec<&str> = name.split('.').collect(); program.load()?; - let cat = v.get(v.len() - 2).expect("category is missing"); - let name = v.last().expect("name is missing"); - program.attach(cat, name)?; + let (cat, name) = Self::tp_cat_name(&name); + program.attach(&cat, &name)?; } programs::Program::KProbe(program) => { - let v: Vec<&str> = name.split('.').collect(); - let name = v.last().expect("we must have at least one element"); program.load()?; - program.attach(name, 0)?; + program.attach(&Self::fn_name(&name), 0)?; } - programs::Program::FEntry(program) => { - let v: Vec<&str> = name.split('.').collect(); - let name = v.last().expect("we must have at least one element"); - program.load(name, btf)?; + program.load(&Self::fn_name(&name), btf)?; program.attach()?; } programs::Program::FExit(program) => { - let v: Vec<&str> = name.split('.').collect(); - let name = v.last().expect("we must have at least one element"); - program.load(name, btf)?; + program.load(&Self::fn_name(&name), btf)?; program.attach()?; }