Skip to content

Commit b9dcc60

Browse files
committed
new tool wakesnoop
wakesnoop attaches to scheduler tracepoints sched_waking and sched_wakeup, and measures delay of wakeup. Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
1 parent 6b88099 commit b9dcc60

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

TOOLS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Show entries about TCP&UDP in nf_conntrack.
1515
Trace scheduling of system processes between NUMA nodes.
1616
- [sigsnoop](https://github.com/bpftrace/user-tools/tree/master/sigsnoop):
1717
Trace standard and real-time signals.
18+
- [wakesnoop](wakesnoop): Task wakeup latency tracing.

wakesnoop/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# wakesnoop
2+
3+
wakesnoop attaches to scheduler tracepoints sched_waking and sched_wakeup, and
4+
measures delay of wakeup. Measurements exceeding threshold, munching cpu mask
5+
and pid are printed. If no optional arguments are provided, the tool prints all
6+
measurements.
7+
8+
USAGE: wakesnoop.bt \[wakeup delay threshold, us\] \[cpu mask\] \[pid\]
9+
10+
## Output
11+
12+
```
13+
# ./sched/wakesnoop.bt 100
14+
Attaching 4 probes...
15+
Tracing scheduler delay and in microseconds. Ctrl-C to end.
16+
TIME DELAY(us) CPU PID COMM
17+
21:49:23.425949 123 7 6124 pulseaudio
18+
21:49:23.534792 116 8 32155 VizCompositorTh
19+
21:49:24.213697 145 5 6124 pulseaudio
20+
21:49:24.315695 113 5 6124 pulseaudio
21+
21:49:24.603702 107 5 6124 pulseaudio
22+
21:49:24.652704 107 5 444683 kworker/u25:3
23+
```

wakesnoop/wakesnoop.bt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bpftrace
2+
3+
// SPDX-License-Identifier: GPL-2.0-or-later
4+
5+
/*
6+
* wakesnoop.bt Scheduler latency tracing tool.
7+
*
8+
* USAGE:
9+
* ./wakesnoop.bt [wakeup delay threshold, us] [cpu mask] [pid]
10+
*
11+
* Copyright 2024 Red Hat, Inc., Costa Shulyupin
12+
*
13+
*/
14+
15+
BEGIN
16+
{
17+
printf("Tracing scheduler delay and in microseconds. Ctrl-C to end.\n");
18+
printf("%-15s %9s %3s %7s %s\n", "TIME", "DELAY(us)", "CPU", "PID", "COMM");
19+
}
20+
21+
22+
tracepoint:sched:sched_waking,
23+
/!$3 || args.pid == $3/
24+
{
25+
@waking[args.pid] = nsecs;
26+
}
27+
28+
tracepoint:sched:sched_wakeup
29+
/(!$3 || args.pid == $3) && @waking[args.pid] /
30+
{
31+
$delay = (nsecs - @waking[args.pid]) / 1000;
32+
@sched_wakeup_delay_max = max($delay);
33+
if ($delay > $1 && (!$2 || 1 << args.target_cpu & $2)) {
34+
printf("%s %9u %3u %7d %s\n",
35+
strftime("%H:%M:%S.%f", @waking[args.pid]), $delay, args.target_cpu,
36+
args.pid, args.comm);
37+
}
38+
delete(@waking[args.pid]);
39+
}
40+
41+
END
42+
{
43+
clear(@waking);
44+
}

0 commit comments

Comments
 (0)