Struct aya::maps::stack_trace::StackTraceMap
source · [−]pub struct StackTraceMap<T> { /* private fields */ }
Expand description
A hash map of kernel or user space stack traces.
Stack trace maps can be used to store stack traces captured by eBPF programs, which can be
useful for profiling, to associate a trace to an event, etc. You can capture traces calling
stack_id = bpf_get_stackid(ctx, map, flags)
from eBPF, and then you can retrieve the traces
from their stack ids.
Minimum kernel version
The minimum kernel version required to use this feature is 4.6.
Examples
use aya::maps::StackTraceMap;
use aya::util::kernel_symbols;
use std::convert::TryFrom;
let mut stack_traces = StackTraceMap::try_from(bpf.map("STACK_TRACES")?)?;
// load kernel symbols from /proc/kallsyms
let ksyms = kernel_symbols()?;
// NOTE: you typically send stack_ids from eBPF to user space using other maps
let stack_id = 1234;
let mut stack_trace = stack_traces.get(&stack_id, 0)?;
// here we resolve symbol names using kernel symbols. If this was a user space stack (for
// example captured from a uprobe), you'd have to load the symbols using some other mechanism
// (eg loading the target binary debuginfo)
for frame in stack_trace.resolve(&ksyms).frames() {
println!(
"{:#x} {}",
frame.ip,
frame
.symbol_name
.as_ref()
.unwrap_or(&"[unknown symbol name]".to_owned())
);
}
Implementations
sourceimpl<T: Deref<Target = Map>> StackTraceMap<T>
impl<T: Deref<Target = Map>> StackTraceMap<T>
sourcepub fn get(&self, stack_id: &u32, flags: u64) -> Result<StackTrace, MapError>
pub fn get(&self, stack_id: &u32, flags: u64) -> Result<StackTrace, MapError>
Returns the stack trace with the given stack_id.
Errors
Returns MapError::KeyNotFound
if there is no stack trace with the
given stack_id
, or MapError::SyscallError
if bpf_map_lookup_elem
fails.
sourcepub fn iter(&self) -> MapIter<'_, u32, StackTrace, Self>ⓘNotable traits for MapIter<'_, K, V, I>impl<K: Pod, V, I: IterableMap<K, V>> Iterator for MapIter<'_, K, V, I> type Item = Result<(K, V), MapError>;
pub fn iter(&self) -> MapIter<'_, u32, StackTrace, Self>ⓘNotable traits for MapIter<'_, K, V, I>impl<K: Pod, V, I: IterableMap<K, V>> Iterator for MapIter<'_, K, V, I> type Item = Result<(K, V), MapError>;
An iterator visiting all (stack_id
, stack_trace
) pairs in arbitrary order. The
iterator item type is Result<(u32, StackTrace), MapError>
.
Trait Implementations
sourceimpl<T: Debug> Debug for StackTraceMap<T>
impl<T: Debug> Debug for StackTraceMap<T>
sourceimpl<'a, T: Deref<Target = Map>> IntoIterator for &'a StackTraceMap<T>
impl<'a, T: Deref<Target = Map>> IntoIterator for &'a StackTraceMap<T>
sourceimpl<T: Deref<Target = Map>> IterableMap<u32, StackTrace> for StackTraceMap<T>
impl<T: Deref<Target = Map>> IterableMap<u32, StackTrace> for StackTraceMap<T>
sourceimpl TryFrom<MapRef> for StackTraceMap<MapRef>
impl TryFrom<MapRef> for StackTraceMap<MapRef>
Auto Trait Implementations
impl<T> RefUnwindSafe for StackTraceMap<T> where
T: RefUnwindSafe,
impl<T> Send for StackTraceMap<T> where
T: Send,
impl<T> Sync for StackTraceMap<T> where
T: Sync,
impl<T> Unpin for StackTraceMap<T> where
T: Unpin,
impl<T> UnwindSafe for StackTraceMap<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more