Skip to content

Commit

Permalink
exit optional, close cleans up stored stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 15, 2024
1 parent a873d2a commit aa68978
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
20 changes: 10 additions & 10 deletions stacks/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use libbpf_rs::{
skel::{OpenSkel, SkelBuilder},
Link,
};
use tracing::warn;
use tracing::info;

use crate::{
perf_event::{attach_perf_event, perf_event_per_cpu},
Expand Down Expand Up @@ -629,20 +629,20 @@ pub(crate) fn link<'a>(
.progs_mut()
.stacks_tracing_exit()
.attach_usdt(-1, u, "stacks_tracing", "exit")
.context("usdt exit")?;
let _usdt_close = skel
.progs_mut()
.stacks_tracing_close()
.attach_usdt(-1, u, "stacks_tracing", "close")
.context("usdt close");
match _usdt_close {
.context("usdt exit");
match _usdt_exit {
Ok(link) => links.push(link),
Err(err) => {
warn!("failed to attach usdt close to binary {:?}: {}", u, err);
info!("usdt exit is not attached to binary {:?}: {}", u, err);
}
}
let _usdt_close = skel
.progs_mut()
.stacks_tracing_close()
.attach_usdt(-1, u, "stacks_tracing", "close")
.context("usdt close")?;
links.push(_usdt_enter);
links.push(_usdt_exit);
links.push(_usdt_close);
}

Ok((skel, links))
Expand Down
6 changes: 4 additions & 2 deletions stacks/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,22 @@ impl<Fr: Frames, Sym: Symbolizer> State<Fr, Sym> {
});
}
Received::TraceClose(event) => {
// record it only once for any pid where this span_id has entered before
// record close event only once for any pid where this span_id has entered before
let pids = self
.tgid_span_id_pid_to_enter
.range((event.tgid, event.span_id, 0)..(event.tgid, event.span_id, u32::MAX))
.map(|(k, _)| k.2)
.collect::<Vec<_>>();
let process_info = self.tgid_process_info.get(&pids[0]);
let process_info = self.tgid_process_info.get(&event.tgid);
for (i, pid) in pids.into_iter().enumerate() {
// delete all observed
let span = match self.tgid_span_id_pid_to_enter.remove(&(event.tgid, event.span_id, pid)) {
Some(span) => span,
None => {
anyhow::bail!("missing span for pid {} span_id {}", pid, event.span_id);
}
};
// record only first
if i > 0 {
continue;
}
Expand Down

0 comments on commit aa68978

Please sign in to comment.