forked from brendangregg/bpf-perf-tools-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offcputime.bt
executable file
·42 lines (37 loc) · 975 Bytes
/
offcputime.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/local/bin/bpftrace
/*
* offcputime - Summarize off-CPU time by stack trace (bpftrace version).
*
* See BPF Performance Tools, Chapter 6, for an explanation of this tool.
*
* Copyright (c) 2019 Brendan Gregg.
* Licensed under the Apache License, Version 2.0 (the "License").
* This was originally created for the BPF Performance Tools book
* published by Addison Wesley. ISBN-13: 9780136554820
* When copying or porting, include this comment.
*
* 16-Feb-2019 Brendan Gregg Created this.
*/
#include <linux/sched.h>
BEGIN
{
printf("Tracing nanosecond time in off-CPU stacks. Ctrl-C to end.\n");
}
kprobe:finish_task_switch
{
// record previous thread sleep time
$prev = (struct task_struct *)arg0;
if ($1 == 0 || $prev->tgid == $1) {
@start[$prev->pid] = nsecs;
}
// get the current thread start time
$last = @start[tid];
if ($last != 0) {
@[kstack, ustack, comm] = sum(nsecs - $last);
delete(@start[tid]);
}
}
END
{
clear(@start);
}