Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move common native unwinder logic deletion to its own function #124

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 40 additions & 46 deletions src/profiler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use libbpf_rs::OpenObject;
use std::collections::hash_map::Entry;
use std::collections::hash_map::OccupiedEntry;
use std::collections::HashMap;
use std::fs;
use std::mem::size_of;
Expand Down Expand Up @@ -532,31 +533,13 @@ impl Profiler {
.known_executables
.entry(mapping.executable_id)
{
Self::delete_bpf_pages(
&self.native_unwinder,
mapping.start_addr,
mapping.end_addr,
mapping.executable_id,
);
Self::delete_bpf_mappings(
&self.native_unwinder,
Self::delete_bpf_native_unwind_all(
pid,
mapping.start_addr,
mapping.end_addr,
);
let res = Self::delete_bpf_unwind_info_map(
&mut self.native_unwinder,
entry.get().bucket_id,
mapping.executable_id,
mapping,
entry,
&mut self.native_unwind_state.unwind_info_bucket_usage,
);
if res.is_err() {
info!("deleting the BPF unwind info array failed with {:?}", res);
}

// The object file (`object_files`) is not removed here as we still need it for
// normalization before sending the profiles.
entry.remove_entry();
}
}
}
Expand All @@ -582,35 +565,13 @@ impl Profiler {
.known_executables
.entry(mapping.executable_id)
{
// Delete unwind info.
Self::delete_bpf_pages(
&self.native_unwinder,
mapping.start_addr,
mapping.end_addr,
mapping.executable_id,
);
Self::delete_bpf_mappings(
&self.native_unwinder,
Self::delete_bpf_native_unwind_all(
pid,
mapping.start_addr,
mapping.end_addr,
);
let res = Self::delete_bpf_unwind_info_map(
&mut self.native_unwinder,
entry.get().bucket_id,
mapping.executable_id,
mapping,
entry,
&mut self.native_unwind_state.unwind_info_bucket_usage,
);
if res.is_err() {
info!(
"deleting the BPF unwind info array failed with {:?}",
res
);
}

// The object file (`object_files`) is not removed here as we still need it for
// normalization before sending the profiles.
entry.remove_entry();
}
}
}
Expand Down Expand Up @@ -967,6 +928,39 @@ impl Profiler {
res
}

/// Called when a process exits or a mapping gets unmapped. Removing the
/// process entry is the responsibility of the caller.
fn delete_bpf_native_unwind_all(
pid: Pid,
native_unwinder: &mut ProfilerSkel,
mapping: &ExecutableMapping,
entry: OccupiedEntry<ExecutableId, KnownExecutableInfo>,
unwind_info_bucket_usage: &mut [usize],
) {
Self::delete_bpf_mappings(native_unwinder, pid, mapping.start_addr, mapping.end_addr);

Self::delete_bpf_pages(
native_unwinder,
mapping.start_addr,
mapping.end_addr,
mapping.executable_id,
);

let res = Self::delete_bpf_unwind_info_map(
native_unwinder,
entry.get().bucket_id,
mapping.executable_id,
unwind_info_bucket_usage,
);
if res.is_err() {
info!("deleting the BPF unwind info array failed with {:?}", res);
}

// The object file (`object_files`) is not removed here as we still need it for
// normalization before sending the profiles.
entry.remove_entry();
}

fn is_bucket_full(unwind_info_bucket_usage: &[usize], bucket_id: usize) -> bool {
unwind_info_bucket_usage[bucket_id] >= MAX_OUTER_UNWIND_MAP_ENTRIES as usize
}
Expand Down