forked from bpftrace/bpftrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunqlen.bt
More file actions
55 lines (51 loc) · 1.66 KB
/
runqlen.bt
File metadata and controls
55 lines (51 loc) · 1.66 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bpftrace
// runqlen.bt CPU scheduler run queue length as a histogram.
// For Linux, uses bpftrace, eBPF.
//
// Example of usage:
//
// # ./runqlen.bt
// Attaching 2 probes...
// Sampling run queue length at 99 Hertz... Hit Ctrl-C to end.
// ^C
//
// @runqlen:
// [0, 1) 1967 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
// [1, 2) 0 | |
// [2, 3) 0 | |
// [3, 4) 306 |@@@@@@@@ |
//
// This output shows that the run queue length was usually zero, except for some
// samples where it was 3. This was caused by binding 4 CPU bound threads to a
// single CPUs.
//
// This is a bpftrace version of the bcc tool of the same name.
// The bcc version provides options to customize the output.
//
// Copyright 2018 Netflix, Inc.
//
// 07-Oct-2018 Brendan Gregg Created this.
#ifndef BPFTRACE_HAVE_BTF
#include <linux/sched.h>
// Without BTF, we'll need to declare some of this struct manually,
// since it isn't available to be #included. This will need maintenance to match
// your kernel version. It is from kernel/sched/sched.h:
struct cfs_rq {
struct load_weight load;
unsigned int nr_queued;
unsigned int h_nr_queued;
};
#endif
BEGIN
{
printf("Sampling run queue length at 99 Hertz... Hit Ctrl-C to end.\n");
}
profile:hz:99
{
$task = (struct task_struct *)curtask;
$my_q = (struct cfs_rq *)$task.se.cfs_rq;
$len = (uint64)$my_q.nr_queued;
$len = ($len > 0) ? ($len - 1) : 0;
// subtract currently running task
@runqlen = lhist($len, 0, 100, 1);
}