Skip to content

Commit

Permalink
handle exit only for main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Jul 10, 2024
1 parent 947c10d commit 0053758
Show file tree
Hide file tree
Showing 6 changed files with 1,109 additions and 1,095 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: test

on:
push:
pull_request:
branches:
- "**"
- "!dependabot/**"
pull_request:
branches: [master]
workflow_call:

jobs:
Expand Down
1 change: 1 addition & 0 deletions e2e/examples/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ fn main() {
state.inc(sleep_duration);
});
});
sleep(sleep_duration);
}
2 changes: 2 additions & 0 deletions e2e/proptest-regressions/main.txt

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions e2e/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ impl Locker {

let rst = OffcpuDataFrame(dfctx.sql(&query).await.unwrap().collect().await.unwrap());

// find task with tgid == pid, offcpu >= 2 * sleep_after_lock and futex_wait in stacks
let parent = rst.iter().find(|item| {
item.tgid == item.pid
&& item.offcpu >= 2 * self.sleep_after_lock
&& item.stacks().any(|stack| stack.contains("futex_wait"))
});
// find task with tgid == pid and futex_wait in stacks
let parent = rst
.iter()
.find(|item| item.tgid == item.pid && item.stacks().any(|stack| stack.contains("futex_wait")));
assert!(
parent.is_some(),
"parent events always should wait for 2 sleep durations for child threads"
Expand All @@ -165,14 +163,14 @@ impl Locker {
})
.count();
assert_eq!(nanosleeps, 2, "two threads should wait in nanosleep for sleep duration");
// find 3 tasks with do_exit stack and 0 offcpu
// find 2 tasks with do_exit stack and 0 offcpu
let exits = rst
.iter()
.filter(|item| {
item.stacks().any(|stack| stack.contains("do_exit")) && item.offcpu == Duration::from_nanos(0)
})
.count();
assert_eq!(exits, 3, "three threads should exit");
assert!(exits >= 2, "should capture childs atleast 2 exits, found {}", exits);
}
}

Expand Down
8 changes: 8 additions & 0 deletions past/src/bpf/past.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ SEC("tp_btf/sched_process_exit")
int handle__sched_process_exit(u64 *ctx)
{
struct task_struct *p = (void *)ctx[0];
if (p->tgid != p->pid)
{
return 0;
}
u64 tgid = p->tgid;
if (apply_tgid_filter(tgid) > 0)
{
Expand All @@ -281,6 +285,10 @@ SEC("tp_btf/sched_process_exec")
int handle__sched_process_exec(u64 *ctx)
{
struct task_struct *p = (void *)ctx[0];
if (p->tgid != p->pid)
{
return 0;
}
if (apply_filters(p) > 0)
{
return 0;
Expand Down
Loading

0 comments on commit 0053758

Please sign in to comment.