Skip to content

Commit

Permalink
Always check if the unwind information has already been loaded in BPF…
Browse files Browse the repository at this point in the history
… maps

This was only done in one of the code paths
  • Loading branch information
javierhonduco committed Jan 7, 2025
1 parent 985c193 commit 5926f46
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ impl NativeUnwindState {
last_eviction: Instant::now(),
}
}

/// Checks whether the given `executable_id` is loaded in the BPF maps.
fn is_known(&self, executable_id: ExecutableId) -> bool {
self.known_executables.contains_key(&executable_id)
}
}

pub struct Profiler {
Expand Down Expand Up @@ -1169,7 +1174,6 @@ impl Profiler {
continue;
}
let object_file_info = object_file_info.unwrap();
let obj_path = object_file_info.path.clone();

// TODO: rework this logic as it's quite kludgy at the moment and this is broken with
// some loaders. Particularly, Rust statically linked with musl does not work. We must
Expand All @@ -1184,32 +1188,6 @@ impl Profiler {
}
std::mem::drop(object_file);

match self
.native_unwind_state
.known_executables
.get(&mapping.executable_id)
{
Some(_) => {
// Add mapping.
bpf_mappings.push(mapping_t {
executable_id: mapping.executable_id,
load_address,
begin: mapping.start_addr,
end: mapping.end_addr,
type_: if mapping.kind == ExecutableMappingType::Vdso {
MAPPING_TYPE_VDSO
} else {
MAPPING_TYPE_FILE
},
});
debug!("unwind info CACHED for executable {:?}", obj_path);
continue;
}
None => {
debug!("unwind info not found for executable {:?}", obj_path);
}
}

// Add mapping.
bpf_mappings.push(mapping_t {
load_address,
Expand Down Expand Up @@ -1245,6 +1223,16 @@ impl Profiler {
}

fn add_unwind_information_for_executable(&mut self, executable_id: ExecutableId) {
if self.native_unwind_state.is_known(executable_id) {
debug!("unwind info CACHED for executable id: {:x}", executable_id);
return;
} else {
debug!(
"unwind info not found for executable id: {:x}",
executable_id
);
}

let object_files = self.object_files.read();
let executable_info = object_files.get(&executable_id).unwrap();
let executable_path_open = executable_info.open_file_path();
Expand Down

0 comments on commit 5926f46

Please sign in to comment.