forked from bpftrace/bpftrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpuwalk.bt
More file actions
97 lines (95 loc) · 5.23 KB
/
cpuwalk.bt
File metadata and controls
97 lines (95 loc) · 5.23 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bpftrace
// cpuwalk Sample which CPUs are executing processes.
// For Linux, uses bpftrace and eBPF.
//
// Example of usage:
//
// # ./cpuwalk.bt
// Attaching 2 probes...
// Sampling CPU at 99hz... Hit Ctrl-C to end.
// ^C
//
// @cpu:
// [0, 1) 130 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [1, 2) 137 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [2, 3) 99 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [3, 4) 99 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [4, 5) 82 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [5, 6) 34 |@@@@@@@@@@@@ |
// [6, 7) 67 |@@@@@@@@@@@@@@@@@@@@@@@@ |
// [7, 8) 41 |@@@@@@@@@@@@@@@ |
// [8, 9) 97 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [9, 10) 140 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
// [10, 11) 105 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [11, 12) 77 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [12, 13) 39 |@@@@@@@@@@@@@@ |
// [13, 14) 58 |@@@@@@@@@@@@@@@@@@@@@ |
// [14, 15) 64 |@@@@@@@@@@@@@@@@@@@@@@@ |
// [15, 16) 57 |@@@@@@@@@@@@@@@@@@@@@ |
// [16, 17) 99 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [17, 18) 56 |@@@@@@@@@@@@@@@@@@@@ |
// [18, 19) 44 |@@@@@@@@@@@@@@@@ |
// [19, 20) 80 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [20, 21) 64 |@@@@@@@@@@@@@@@@@@@@@@@ |
// [21, 22) 59 |@@@@@@@@@@@@@@@@@@@@@ |
// [22, 23) 88 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [23, 24) 84 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [24, 25) 29 |@@@@@@@@@@ |
// [25, 26) 48 |@@@@@@@@@@@@@@@@@ |
// [26, 27) 62 |@@@@@@@@@@@@@@@@@@@@@@@ |
// [27, 28) 66 |@@@@@@@@@@@@@@@@@@@@@@@@ |
// [28, 29) 57 |@@@@@@@@@@@@@@@@@@@@@ |
// [29, 30) 59 |@@@@@@@@@@@@@@@@@@@@@ |
// [30, 31) 56 |@@@@@@@@@@@@@@@@@@@@ |
// [31, 32) 23 |@@@@@@@@ |
// [32, 33) 90 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
// [33, 34) 62 |@@@@@@@@@@@@@@@@@@@@@@@ |
// [34, 35) 39 |@@@@@@@@@@@@@@ |
// [35, 36) 68 |@@@@@@@@@@@@@@@@@@@@@@@@@ |
//
// This shows that all 36 CPUs were active, with some busier than others.
//
//
// Compare that output to the following workload from an application:
//
// # ./cpuwalk.bt
// Attaching 2 probes...
// Sampling CPU at 99hz... Hit Ctrl-C to end.
// ^C
//
// @cpu:
// [6, 7) 243 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
// [7, 8) 0 | |
// [8, 9) 0 | |
// [9, 10) 0 | |
// [10, 11) 0 | |
// [11, 12) 0 | |
// [12, 13) 0 | |
// [13, 14) 0 | |
// [14, 15) 0 | |
// [15, 16) 0 | |
// [16, 17) 0 | |
// [17, 18) 0 | |
// [18, 19) 0 | |
// [19, 20) 0 | |
// [20, 21) 1 | |
//
// In this case, only a single CPU (6) is really active doing work. Only a single
// sample was taken of another CPU (20) running a process. If the workload was
// supposed to be making use of multiple CPUs, it isn't, and that can be
// investigated (application's configuration, number of threads, CPU binding, etc).
//
// This is a bpftrace version of the DTraceToolkit tool of the same name.
//
// Copyright 2018 Netflix, Inc.
//
// 08-Sep-2018 Brendan Gregg Created this.
BEGIN
{
printf("Sampling CPU at 99hz... Hit Ctrl-C to end.\n");
}
profile:hz:99
/pid/
{
@cpu = lhist(cpu, 0, 1000, 1);
}